diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index 210be56b6..11eff6bf0 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -3,9 +3,11 @@ import { formatCurrency } from '$lib/helpers/numbers'; import type { Coupon, Estimation } from '$lib/sdk/billing'; import { sdk } from '$lib/stores/sdk'; + import { AppwriteException } from '@appwrite.io/console'; import Alert from '../alert.svelte'; import Card from '../card.svelte'; import DiscountsApplied from './discountsApplied.svelte'; + import { addNotification } from '$lib/stores/notifications'; export let organizationId: string | undefined = undefined; export let billingPlan: string; @@ -22,15 +24,30 @@ async function getEstimate(billingPlan: string, collaborators: string[], couponId: string) { try { - error = ''; estimation = await sdk.forConsole.billing.estimationCreateOrganization( billingPlan, couponId === '' ? null : couponId, collaborators ?? [] ); - error = estimation.error ?? ''; } catch (e) { - error = e.message; + if (e instanceof AppwriteException) { + if ( + e.type === 'coupon_not_found' || + e.type === 'coupon_already_used' || + e.type === 'billing_credits_unsupported' + ) { + couponData = { + code: null, + status: null, + credits: null + }; + } + } + addNotification({ + type: 'error', + isHtml: false, + message: e.message + }); } } @@ -41,16 +58,18 @@ couponId: string | undefined ) { try { - error = ''; estimation = await sdk.forConsole.billing.estimationUpdatePlan( organizationId, billingPlan, couponId && couponId.length > 0 ? couponId : null, collaborators ?? [] ); - error = estimation.error ?? ''; } catch (e) { - error = e.message; + addNotification({ + type: 'error', + isHtml: false, + message: e.message + }); } } @@ -70,10 +89,10 @@ {#if estimation} {#each estimation.items ?? [] as item} {#if item.value > 0} - -

{item.label}

-

{formatCurrency(item.value)}

-
+ +

{item.label}

+

{formatCurrency(item.value)}

+
{/if} {/each} {#each estimation.discounts ?? [] as item} diff --git a/src/lib/layout/wizardExitModal.svelte b/src/lib/layout/wizardExitModal.svelte index 13f677e99..2b71f4a59 100644 --- a/src/lib/layout/wizardExitModal.svelte +++ b/src/lib/layout/wizardExitModal.svelte @@ -14,7 +14,7 @@ diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 0edd44b72..d3de145b8 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -3,13 +3,7 @@ import { base } from '$app/paths'; import { page } from '$app/stores'; import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; - import { - PlanComparisonBox, - SelectPaymentMethod, - - SelectPlan - - } from '$lib/components/billing'; + import { PlanComparisonBox, SelectPaymentMethod, SelectPlan } from '$lib/components/billing'; import EstimatedTotal from '$lib/components/billing/estimatedTotal.svelte'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; import Default from '$lib/components/roles/default.svelte'; @@ -227,23 +221,27 @@ id="members" /> - + {#if !couponData?.code} + + {/if} {/if} {#if billingPlan !== BillingPlan.FREE} + {couponData} /> {:else} {/if}