mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
feat: more work on the creation flow
This commit is contained in:
1 parent
4ac90c367a
commit
74bbcad52d
7 files changed
+142
-15
No files matched your search
@@ -1,2 +1,3 @@
|
||||
export { default as PaymentBoxes } from './paymentBoxes.svelte';
|
||||
export { default as CouponInput } from './couponInput.svelte';
|
||||
export { default as SelectPaymentMethod } from './selectPaymentMethod.svelte';
|
||||
@@ -0,0 +1,68 @@
|
||||
<script lang="ts">
|
||||
import { Button, InputSelectSearch } from '$lib/elements/forms';
|
||||
import type { PaymentList, PaymentMethodData } from '$lib/sdk/billing';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { hasStripePublicKey, isCloud } from '$lib/system';
|
||||
import PaymentModal from '$routes/console/account/payments/paymentModal.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { Card, CreditCardBrandImage } from '..';
|
||||
|
||||
export let methods: PaymentList;
|
||||
export let value: string;
|
||||
|
||||
let showPaymentModal = false;
|
||||
|
||||
async function cardSaved(event: CustomEvent<PaymentMethodData>) {
|
||||
value = event.detail.$id;
|
||||
methods = await sdk.forConsole.billing.listPaymentMethods();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (methods?.total && methods.paymentMethods.some((method) => !!method?.last4)) {
|
||||
value = methods.paymentMethods[0].$id;
|
||||
}
|
||||
});
|
||||
|
||||
$: filteredMethods = methods?.paymentMethods?.filter((method) => !!method?.last4);
|
||||
</script>
|
||||
|
||||
{#if filteredMethods?.length}
|
||||
<InputSelectSearch
|
||||
id="method"
|
||||
label="Payment method"
|
||||
bind:value
|
||||
options={filteredMethods.map((method) => {
|
||||
return {
|
||||
value: method.$id,
|
||||
label: `ending in ${method.last4}`,
|
||||
data: [method.brand]
|
||||
};
|
||||
})}
|
||||
interactiveOutput
|
||||
let:option={o}>
|
||||
<span class="u-flex u-gap-16 u-flex-vertical">
|
||||
<span class="u-flex u-gap-16">
|
||||
<span class="u-flex u-cross-center u-gap-8" style="padding-inline:0.25rem">
|
||||
<span> <span class="u-capitalize">{o.data}</span> {o.label}</span>
|
||||
<CreditCardBrandImage brand={o.data?.toString()} />
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</InputSelectSearch>
|
||||
{:else}
|
||||
<Card isDashed style="--p-card-padding: 1rem; --p-card-bg-color: transparent" isTile>
|
||||
<div class="u-flex u-main-space-between u-cross-center">
|
||||
<p>
|
||||
<span class="icon-exclamation-circle"></span>
|
||||
<span class="text">No saved payment methods</span>
|
||||
</p>
|
||||
<Button secondary on:click={() => (showPaymentModal = true)}>
|
||||
<span class="icon-plus"></span> <span class="text">Add</span>
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
{/if}
|
||||
|
||||
{#if showPaymentModal && isCloud && hasStripePublicKey}
|
||||
<PaymentModal bind:show={showPaymentModal} on:submit={cardSaved} />
|
||||
{/if}
|
||||
@@ -5,6 +5,8 @@
|
||||
isTile?: boolean;
|
||||
isDashed?: boolean;
|
||||
danger?: boolean;
|
||||
style?: string;
|
||||
class?: string;
|
||||
};
|
||||
|
||||
type ButtonProps = {
|
||||
@@ -26,6 +28,7 @@
|
||||
export let href: string = null;
|
||||
let classes = '';
|
||||
export { classes as class };
|
||||
export let style: string = '';
|
||||
|
||||
function getElement() {
|
||||
switch (true) {
|
||||
@@ -46,6 +49,7 @@
|
||||
class:is-border-dashed={isDashed}
|
||||
class:is-danger={danger}
|
||||
class:is-allowed-focus={href}
|
||||
{style}
|
||||
on:click
|
||||
on:keyup={clickOnEnter}
|
||||
role={href || isButton ? 'button' : 'generic'}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
type Option = $$Generic<{
|
||||
value: string | boolean | number;
|
||||
label: string;
|
||||
data?: string[];
|
||||
data?: unknown[];
|
||||
}>;
|
||||
type OptionArray = Option[];
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
export let readonly = false;
|
||||
export let required = false;
|
||||
export let tooltip: string = null;
|
||||
export let validityRegex: RegExp = null;
|
||||
export let validityMessage: string = null;
|
||||
|
||||
let value = '';
|
||||
let element: HTMLInputElement;
|
||||
@@ -32,8 +34,13 @@
|
||||
if (value === '' && ['Enter', 'Tab'].includes(e.key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (['Enter', 'Tab', ' '].includes(e.key)) {
|
||||
e.preventDefault();
|
||||
if (validityRegex && !validityRegex.test(value)) {
|
||||
error = validityMessage ? validityMessage : 'Invalid value';
|
||||
return;
|
||||
}
|
||||
addValue();
|
||||
}
|
||||
if (['Backspace', 'Delete'].includes(e.key)) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { tooltip as tooltipAction } from '$lib/actions/tooltip';
|
||||
|
||||
interface $$Props extends Partial<HTMLLabelElement> {
|
||||
required?: boolean;
|
||||
hideRequired?: boolean;
|
||||
@@ -31,12 +33,12 @@
|
||||
{/if}
|
||||
|
||||
{#if tooltip}
|
||||
<button type="button" on:click|preventDefault class="tooltip" aria-label="input tooltip">
|
||||
<button
|
||||
type="button"
|
||||
on:click|preventDefault
|
||||
class="tooltip"
|
||||
aria-label="input tooltip"
|
||||
use:tooltipAction={{ content: tooltip }}>
|
||||
<span class="icon-info" aria-hidden="true" style="font-size: var(--icon-size-small)" />
|
||||
<span class="tooltip-popup" role="tooltip">
|
||||
<p class="text">
|
||||
{tooltip}
|
||||
</p>
|
||||
</span>
|
||||
</button>
|
||||
{/if}
|
||||
@@ -1,8 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { LabelCard } from '$lib/components';
|
||||
import { SelectPaymentMethod } from '$lib/components/billing';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { Button, Form, FormList, InputText, Label } from '$lib/elements/forms';
|
||||
import { Button, Form, FormList, InputTags, InputText, Label } from '$lib/elements/forms';
|
||||
import { formatCurrency } from '$lib/helpers/numbers';
|
||||
import {
|
||||
WizardSecondaryContainer,
|
||||
@@ -10,33 +11,64 @@
|
||||
WizardSecondaryFooter,
|
||||
WizardSecondaryHeader
|
||||
} from '$lib/layout';
|
||||
import type { PaymentList } from '$lib/sdk/billing';
|
||||
import { plansInfo, tierFree, tierPro } from '$lib/stores/billing';
|
||||
import { organizationList, type Organization } from '$lib/stores/organization';
|
||||
import { createOrganization } from './store';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$/i;
|
||||
$: anyOrgFree = $organizationList.teams?.find(
|
||||
(org) => (org as Organization)?.billingPlan === BillingPlan.STARTER
|
||||
);
|
||||
|
||||
let methods: PaymentList;
|
||||
let billingPlan: BillingPlan = BillingPlan.STARTER;
|
||||
let paymentMethodId: string;
|
||||
|
||||
onMount(async () => {
|
||||
if (anyOrgFree) {
|
||||
billingPlan = BillingPlan.PRO;
|
||||
}
|
||||
});
|
||||
|
||||
async function loadPaymentMethods() {
|
||||
methods = await sdk.forConsole.billing.listPaymentMethods();
|
||||
// initialPaymentMethodId =
|
||||
// methods.paymentMethods.find((method) => !!method?.last4)?.$id ?? null;
|
||||
// $createOrganization.paymentMethodId = initialPaymentMethodId;
|
||||
}
|
||||
|
||||
$: freePlan = $plansInfo.get(BillingPlan.STARTER);
|
||||
$: proPlan = $plansInfo.get(BillingPlan.PRO);
|
||||
$: if (billingPlan === BillingPlan.PRO) {
|
||||
loadPaymentMethods();
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Create organization - Appwrite</title>
|
||||
</svelte:head>
|
||||
|
||||
<WizardSecondaryContainer>
|
||||
<WizardSecondaryHeader href={`${base}/console`}>Create organization</WizardSecondaryHeader>
|
||||
<WizardSecondaryContent>
|
||||
<Form onSubmit={() => console.log('test')}>
|
||||
<FormList>
|
||||
<InputText label="Name" placeholder="Enter name" id="name" />
|
||||
<InputText label="Name" placeholder="Enter name" id="name" required />
|
||||
</FormList>
|
||||
<Label class="u-margin-block-start-16">Select plan</Label>
|
||||
<p class="text">
|
||||
For more details on our plans, visit our
|
||||
<Button href="https://appwrite.io/pricing" external link>pricing page</Button>.
|
||||
</p>
|
||||
<ul
|
||||
class="u-flex u-gap-16 u-margin-block-start-8"
|
||||
style="--p-grid-item-size:16em; --p-grid-item-size-small-screens:16rem; --grid-gap: 1rem;">
|
||||
<li class="u-flex-basis-50-percent">
|
||||
<LabelCard
|
||||
name="plan"
|
||||
bind:group={$createOrganization.billingPlan}
|
||||
bind:group={billingPlan}
|
||||
value="tier-0"
|
||||
disabled={!!anyOrgFree}
|
||||
tooltipShow={!!anyOrgFree}
|
||||
@@ -58,10 +90,7 @@
|
||||
</li>
|
||||
|
||||
<li class="u-flex-basis-50-percent">
|
||||
<LabelCard
|
||||
name="plan"
|
||||
bind:group={$createOrganization.billingPlan}
|
||||
value="tier-1">
|
||||
<LabelCard name="plan" bind:group={billingPlan} value="tier-1">
|
||||
<svelte:fragment slot="custom">
|
||||
<div class="u-flex u-flex-vertical u-gap-4 u-width-full-line">
|
||||
<h4 class="body-text-2 u-bold">
|
||||
@@ -78,6 +107,22 @@
|
||||
</LabelCard>
|
||||
</li>
|
||||
</ul>
|
||||
{#if billingPlan === BillingPlan.PRO}
|
||||
<FormList class="u-margin-block-start-16">
|
||||
<InputTags
|
||||
label="Invite members by email"
|
||||
tooltip="Invited members will have access to all services and payment data within your organization"
|
||||
placeholder="Enter email address(es)"
|
||||
validityRegex={emailRegex}
|
||||
validityMessage="Invalid email address"
|
||||
id="members" />
|
||||
<SelectPaymentMethod bind:methods bind:value={paymentMethodId}
|
||||
></SelectPaymentMethod>
|
||||
</FormList>
|
||||
<Button text noMargin class="u-margin-block-start-16">
|
||||
<span class="icon-plus"></span> <span class="text">Add credits</span>
|
||||
</Button>
|
||||
{/if}
|
||||
</Form>
|
||||
<svelte:fragment slot="aside">
|
||||
<div class="card">
|
||||
|
||||
Reference in new issue
Block a user