refactor: project payment to org payment

This commit is contained in:
Arman committed 2023-06-16 16:37:25 +02:00
1 parent 50c376e558
commit b526675a07
10 files changed
+325 -131

No files matched your search

+11 -6
View File
@@ -21,6 +21,9 @@
import { Submit, trackEvent } from '$lib/actions/analytics';
import { sdk } from '$lib/stores/sdk';
import { goto } from '$app/navigation';
import { isCloud } from '$lib/system';
import { wizard } from '$lib/stores/wizard';
import CreateOrganizationCloud from '$routes/console/createOrganizationCloud.svelte';
let showDropdown = false;
let droplistElement: HTMLDivElement;
@@ -48,6 +51,13 @@
}
}
function createOrg() {
showDropdown = false;
if (isCloud) {
wizard.start(CreateOrganizationCloud);
} else newOrgModal.set(true);
}
$: if (showDropdown) {
trackEvent('click_menu_dropdown');
}
@@ -128,12 +138,7 @@
{/if}
<section class="drop-section">
<ul class="drop-list">
<DropListItem
icon="plus"
on:click={() => {
showDropdown = false;
newOrgModal.set(true);
}}>
<DropListItem icon="plus" on:click={createOrg}>
New organization
</DropListItem>
<DropListLink
@@ -0,0 +1,66 @@
<script lang="ts">
import { Wizard } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { createEventDispatcher, onDestroy } from 'svelte';
import { addNotification } from '$lib/stores/notifications';
import Step1 from './wizard/step1.svelte';
import Step2 from './wizard/step2.svelte';
import { createOrganization } from './wizard/store';
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
import { goto, invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { ID } from '@appwrite.io/console';
import { Tier } from '$lib/system';
const dispatch = createEventDispatcher();
async function onFinish() {
await invalidate(Dependencies.FUNCTIONS);
}
async function create() {
try {
const org = await sdk.forConsole.teams.create(
$createOrganization.id ?? ID.unique(),
$createOrganization.name
);
await invalidate(Dependencies.ACCOUNT);
dispatch('created');
await goto(`/console/organization-${org.$id}`);
addNotification({
type: 'success',
message: `${$createOrganization.name} has been created`
});
trackEvent(Submit.OrganizationCreate, {
customId: !!$createOrganization.id
});
} catch (e) {
addNotification({
type: 'error',
message: e.mesage
});
trackError(e, Submit.OrganizationCreate);
}
}
onDestroy(() => {
$createOrganization = {
id: null,
name: null,
tier: Tier['PREMIUM'],
region: 'eu-central-1'
};
});
const stepsComponents: WizardStepsType = new Map();
stepsComponents.set(1, {
label: 'Project details',
component: Step1
});
stepsComponents.set(2, {
label: 'Select region',
component: Step2
});
</script>
<Wizard title="Create a Project" steps={stepsComponents} on:finish={create} on:exit={onFinish} />
@@ -4,14 +4,18 @@
import { GridItem1, Heading, Empty, CardContainer, PaginationWithLimit } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { Container } from '$lib/layout';
import Create from './createProject.svelte';
import Create from './createProjectCloud.svelte';
import CreateProject from './createProject.svelte';
import CreateOrganization from '../createOrganization.svelte';
import type { PageData } from './$types';
import { wizard } from '$lib/stores/wizard';
import { isCloud } from '$lib/system';
import { page } from '$app/stores';
export let data: PageData;
let addOrganization = false;
let showCreate = false;
const getPlatformInfo = (platform: string) => {
let name: string, icon: string;
@@ -43,15 +47,16 @@
);
}
function openWizard() {
wizard.start(Create);
function createProject() {
if (isCloud) wizard.start(Create);
else showCreate = true;
}
</script>
<Container>
<div class="u-flex u-gap-12 common-section u-main-space-between">
<Heading tag="h2" size="5">Projects</Heading>
<Button on:click={openWizard} event="create_project">
<Button on:click={createProject} event="create_project">
<span class="icon-plus" aria-hidden="true" /> <span class="text">Create project</span>
</Button>
</div>
@@ -61,7 +66,7 @@
total={data.projects.total}
offset={data.offset}
event="project"
on:click={openWizard}>
on:click={createProject}>
{#each data.projects.projects as project}
<GridItem1 href={`${base}/console/project-${project.$id}`}>
<svelte:fragment slot="eyebrow">
@@ -93,7 +98,7 @@
</svelte:fragment>
</CardContainer>
{:else}
<Empty single on:click={openWizard}>
<Empty single on:click={createProject}>
<p>Create a new project</p>
</Empty>
{/if}
@@ -106,3 +111,4 @@
</Container>
<CreateOrganization bind:show={addOrganization} />
<CreateProject bind:show={showCreate} teamId={$page.params.organization} />
@@ -1,71 +1,67 @@
<script lang="ts">
import { Wizard } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { createEventDispatcher, onDestroy } from 'svelte';
import { addNotification } from '$lib/stores/notifications';
import Step1 from './wizard/step1.svelte';
import Step2 from './wizard/step2.svelte';
import { createProject } from './wizard/store';
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
import { goto, invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { page } from '$app/stores';
import { goto } from '$app/navigation';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { Modal, CustomId } from '$lib/components';
import { Pill } from '$lib/elements';
import { InputText, Button, FormList } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { ID } from '@appwrite.io/console';
import { Tier } from '$lib/system';
import { createEventDispatcher } from 'svelte';
export let show = false;
export let teamId: string;
const teamId = $page.params.organization;
const dispatch = createEventDispatcher();
async function onFinish() {
await invalidate(Dependencies.FUNCTIONS);
}
let id: string;
let name: string;
let showCustomId = false;
let error: string;
async function create() {
try {
const project = await sdk.forConsole.projects.create(
$createProject?.id ?? ID.unique(),
$createProject.name,
id ?? ID.unique(),
name,
teamId,
'default'
);
dispatch('created', project);
trackEvent(Submit.ProjectCreate, {
customId: !!$createProject?.id,
customId: !!id,
teamId
});
addNotification({
type: 'success',
message: `${$createProject.name} has been created`
message: `${name} has been created`
});
await goto(`/console/project-${project.$id}`);
} catch (e) {
addNotification({
type: 'error',
message: e.mesage
});
error = e.message;
trackError(e, Submit.ProjectCreate);
}
}
onDestroy(() => {
$createProject = {
id: null,
name: null,
tier: Tier['PREMIUM'],
region: 'eu-central-1'
};
});
const stepsComponents: WizardStepsType = new Map();
stepsComponents.set(1, {
label: 'Project details',
component: Step1
});
stepsComponents.set(2, {
label: 'Select region',
component: Step2
});
</script>
<Wizard title="Create a Project" steps={stepsComponents} on:finish={create} on:exit={onFinish} />
<Modal {error} onSubmit={create} size="big" bind:show>
<svelte:fragment slot="header">Create Project</svelte:fragment>
<FormList>
<InputText id="name" label="Name" bind:value={name} required autofocus={true} />
{#if !showCustomId}
<div>
<Pill button on:click={() => (showCustomId = !showCustomId)}>
<span class="icon-pencil" aria-hidden="true" /><span class="text">
Project ID
</span>
</Pill>
</div>
{:else}
<CustomId bind:show={showCustomId} name="Project" bind:id />
{/if}
</FormList>
<svelte:fragment slot="footer">
<Button secondary on:click={() => (show = false)}>Cancel</Button>
<Button submit>Create</Button>
</svelte:fragment>
</Modal>
@@ -0,0 +1,78 @@
<script lang="ts">
import { Wizard } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { createEventDispatcher, onDestroy } from 'svelte';
import { addNotification } from '$lib/stores/notifications';
import Step1 from './wizard/step1.svelte';
import Step2 from './wizard/step2.svelte';
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
import { goto, invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { page } from '$app/stores';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { ID } from '@appwrite.io/console';
import { Tier } from '$lib/system';
import { createOrganization } from '../wizard/store';
const teamId = $page.params.organization;
const dispatch = createEventDispatcher();
async function onFinish() {
await invalidate(Dependencies.FUNCTIONS);
}
async function create() {
try {
const project = await sdk.forConsole.projects.create(
$createOrganization?.id ?? ID.unique(),
$createOrganization.name,
teamId,
'default'
);
dispatch('created', project);
trackEvent(Submit.ProjectCreate, {
customId: !!$createOrganization?.id,
teamId
});
addNotification({
type: 'success',
message: `${$createOrganization.name} has been created`
});
await goto(`/console/project-${project.$id}`);
} catch (e) {
addNotification({
type: 'error',
message: e.mesage
});
trackError(e, Submit.ProjectCreate);
}
}
onDestroy(() => {
$createOrganization = {
id: null,
name: null,
tier: Tier['PREMIUM']
};
});
const stepsComponents: WizardStepsType = new Map();
stepsComponents.set(1, {
label: 'Organization details',
component: Step1
});
stepsComponents.set(2, {
label: 'Payment details',
component: Step2
});
stepsComponents.set(2, {
label: 'Invite collaborators',
component: Step2
});
stepsComponents.set(2, {
label: 'Review & confirm',
component: Step2
});
</script>
<Wizard title="Create organization" steps={stepsComponents} on:finish={create} on:exit={onFinish} />
@@ -12,9 +12,19 @@
organization,
organizationList
} from '$lib/stores/organization';
import { wizard } from '$lib/stores/wizard';
import { isCloud } from '$lib/system';
import CreateOrganizationCloud from '../createOrganizationCloud.svelte';
let showDropdown = false;
function createOrg() {
showDropdown = false;
if (isCloud) {
wizard.start(CreateOrganizationCloud);
} else newOrgModal.set(true);
}
$: avatars = $members.memberships?.map((m) => m.userName) ?? [];
$: organizationId = $page.params.organization;
$: path = `/console/organization-${organizationId}`;
@@ -75,7 +85,7 @@
<svelte:fragment slot="other">
<section class="drop-section">
<ul class="drop-list">
<DropListItem icon="plus" on:click={() => newOrgModal.set(true)}>
<DropListItem icon="plus" on:click={createOrg}>
New Organization
</DropListItem>
</ul>
@@ -1,14 +1,11 @@
<script lang="ts">
import { Alert, CustomId, LabelCard, List, ListItem } from '$lib/components';
import { CustomId } from '$lib/components';
import { Pill } from '$lib/elements';
import { InputText, FormList, Button } from '$lib/elements/forms';
import { InputText, FormList } from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import PaymentModal from '../billing/paymentModal.svelte';
import { paymentMethods } from '../billing/store';
import { createProject } from './store';
let showCustomId = false;
let showPaymentModal = false;
</script>
<WizardStep>
@@ -32,73 +29,4 @@
<CustomId bind:show={showCustomId} name="Project" bind:id={$createProject.id} />
{/if}
</FormList>
<p class="body-text-1 u-bold common-section">Plan</p>
<p class="text">
For more details on our plans, visit our <a
class="link"
href="http://#"
target="_blank"
rel="noopener noreferrer">pricing page</a
>.
</p>
<ul
class="grid-box u-margin-block-start-16"
style="--p-grid-item-size:16em; --p-grid-item-size-small-screens:16rem; --grid-gap: 1rem;">
<li>
<LabelCard name="plan" bind:group={$createProject.tier} value="premium">
<svelte:fragment slot="title">Pro plan</svelte:fragment>
For projects you want to scale. <b>$25/month</b>
<h6 class="eyebrow-heading-3 u-margin-block-start-16">Includes up to:</h6>
<div class="u-margin-block-start-8">
<List>
<ListItem>2XGB bandwidth</ListItem>
<ListItem>2XGB storage</ListItem>
<ListItem>2Xhrs compute</ListItem>
<ListItem>X days of logs</ListItem>
<ListItem>24/7 personalised support</ListItem>
</List>
</div>
</LabelCard>
</li>
<li>
<LabelCard name="plan" bind:group={$createProject.tier} value="free">
<svelte:fragment slot="title">Free plan</svelte:fragment>
For personal, passion projects. <b>$0/month</b>
<h6 class="eyebrow-heading-3 u-margin-block-start-16">Includes up to:</h6>
<div class="u-margin-block-start-8">
<List>
<ListItem>1XGB bandwidth</ListItem>
<ListItem>1XGB storage</ListItem>
<ListItem>1Xhrs compute</ListItem>
<ListItem>7 days of logs</ListItem>
<ListItem>Email support within business hours</ListItem>
</List>
</div>
</LabelCard>
</li>
</ul>
{#if !$paymentMethods?.length}
<div class="common-section">
<Alert type="warning">
<svelte:fragment slot="title">Add a payment method to continue</svelte:fragment>
You need to add a payment method to your organization to create a paid project.
<svelte:fragment slot="action">
<div class="alert-buttons u-flex">
<Button text on:click={() => (showPaymentModal = true)}>
Add payment method
</Button>
</div>
</svelte:fragment>
</Alert>
</div>
{:else}
{JSON.stringify($paymentMethods)}
{/if}
</WizardStep>
{#if showPaymentModal}
<PaymentModal bind:show={showPaymentModal} />
{/if}
+70
View File
@@ -0,0 +1,70 @@
<script lang="ts">
import { CustomId, LabelCard } from '$lib/components';
import { Pill } from '$lib/elements';
import { InputText, FormList } from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import { createOrganization } from './store';
let showCustomId = false;
</script>
<WizardStep>
<svelte:fragment slot="title">Organization Details</svelte:fragment>
<FormList>
<InputText
label="Name"
id="name"
placeholder="Organization name"
bind:value={$createOrganization.name}
required />
{#if !showCustomId}
<div>
<Pill button on:click={() => (showCustomId = !showCustomId)}>
<span class="icon-pencil" aria-hidden="true" />
<span class="text">Organization ID </span>
</Pill>
</div>
{:else}
<CustomId
bind:show={showCustomId}
name="Organization"
bind:id={$createOrganization.id} />
{/if}
</FormList>
<p class="body-text-1 u-bold common-section">Plan</p>
<p class="text">
For more details on our plans, visit our <a
class="link"
href="http://#"
target="_blank"
rel="noopener noreferrer">pricing page</a
>.
</p>
<ul
class="u-flex u-flex-vertical u-gap-16 u-margin-block-start-16"
style="--p-grid-item-size:16em; --p-grid-item-size-small-screens:16rem; --grid-gap: 1rem;">
<li>
<LabelCard name="plan" bind:group={$createOrganization.tier} value="free">
<svelte:fragment slot="title">Free - $0/month</svelte:fragment>
For personal, passion projects.
</LabelCard>
</li>
<li>
<LabelCard name="plan" bind:group={$createOrganization.tier} value="starter">
<svelte:fragment slot="title"
>Starter - $10/month per organization member</svelte:fragment>
For small organizations that want flexibility.
</LabelCard>
</li>
<li>
<LabelCard name="plan" bind:group={$createOrganization.tier} value="premium">
<svelte:fragment slot="title">
Pro - $20/month per organization member + exta usage
</svelte:fragment>
For organizations that need the ability scale easily.
</LabelCard>
</li>
</ul>
</WizardStep>
+23
View File
@@ -0,0 +1,23 @@
<script lang="ts">
import { RegionCard } from '$lib/components';
import { Pill } from '$lib/elements';
import { WizardStep } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { createOrganization } from './store';
</script>
<WizardStep>
<svelte:fragment slot="title">Select region</svelte:fragment>
<svelte:fragment slot="subtitle">
Choose a deployment region for your project. This region cannot be changed.
</svelte:fragment>
<p class="text u-margin-block-start-16">
Edge Network is enabled on all regions. For more details, check out our <a
class="link"
href="http://#"
target="_blank"
rel="noopener noreferrer">Documentation</a
>.
</p>
</WizardStep>
+12
View File
@@ -0,0 +1,12 @@
import { Tier } from '$lib/system';
import { writable } from 'svelte/store';
export const createOrganization = writable<{
id?: string;
name: string;
tier: Tier;
}>({
id: null,
name: null,
tier: Tier['PREMIUM']
});