diff --git a/src/lib/layout/unauthenticated.svelte b/src/lib/layout/unauthenticated.svelte index b06d957d5..ae6d44edb 100644 --- a/src/lib/layout/unauthenticated.svelte +++ b/src/lib/layout/unauthenticated.svelte @@ -6,6 +6,7 @@ import LoginLight from '$lib/images/login/login-light-mode.png'; import type { Coupon } from '$lib/sdk/billing'; import { app } from '$lib/stores/app'; + import { campaigns } from '$lib/stores/campaigns'; import { user } from '$lib/stores/user'; export const imgLight = LoginLight; @@ -14,6 +15,7 @@ export let coupon: Coupon = null; $: variation = coupon?.code ? 'card' : 'default'; + $: campaign = campaigns.get(coupon.campaign);
@@ -60,11 +62,10 @@
- You've received ${coupon.credits} in credits + {campaign.title.replace('VALUE', coupon.credits)}

- Get ${coupon.credits} in credits when you upgrade or create an organization with - a Pro plan. + {campaign.description.replace('VALUE', coupon.credits)}

diff --git a/src/lib/stores/campaigns.ts b/src/lib/stores/campaigns.ts new file mode 100644 index 000000000..019a0441e --- /dev/null +++ b/src/lib/stores/campaigns.ts @@ -0,0 +1,15 @@ +//campaign welcome and startup + +export const campaigns = new Map(); + +campaigns + .set('welcome', { + title: "You've received $VALUE in credits", + description: + 'Get $VALUE in credits when you upgrade or create an organization with a Pro plan.' + }) + .set('startup', { + title: "You've received $VALUE in credits", + description: + 'Get $VALUE in credits when you upgrade or create an organization with a Pro plan.' + }); diff --git a/src/routes/console/apply-credit/+page.svelte b/src/routes/console/apply-credit/+page.svelte index 3c1927d93..e065e4d09 100644 --- a/src/routes/console/apply-credit/+page.svelte +++ b/src/routes/console/apply-credit/+page.svelte @@ -39,13 +39,14 @@ let collaborators: string[]; let taxId: string; let billingBudget: number; + let newOrgId = ID.unique(); let options = [ ...($organizationList?.teams?.map((team) => ({ value: team.$id, label: team.name })) ?? []), { - value: null, + value: newOrgId, label: 'Create new organization' } ]; @@ -54,9 +55,7 @@ onMount(async () => { await loadPaymentMethods(); if (!$organizationList?.total) { - selectedOrgId = null; - } else { - selectedOrgId = $organizationList?.teams[0]?.$id; + selectedOrgId = newOrgId; } }); @@ -75,7 +74,7 @@ // Create new org if (!selectedOrgId) { org = await sdk.forConsole.billing.createOrganization( - ID.unique(), + newOrgId, name, BillingPlan.PRO, paymentMethodId @@ -166,14 +165,14 @@ label="Select organization" {options} required - placeholder="Create new organization" + placeholder="Select organization" id="organization" /> {/if} - {#if selectedOrg?.billingPlan !== BillingPlan.PRO || !selectedOrg?.paymentMethodId} + {#if selectedOrgId && (selectedOrg?.billingPlan !== BillingPlan.PRO || !selectedOrg?.paymentMethodId)}
- {#if !selectedOrgId} + {#if selectedOrgId === newOrgId} {/if} -
- promo +
+
+
+ promo +

+ {data.campaign.title.replace('VALUE', data.couponData.credits)} +

+
{#if selectedOrg?.billingPlan === BillingPlan.PRO}
@@ -207,7 +214,7 @@ >{toLocaleDate(selectedOrg.billingNextInvoiceDate)}.

- {:else if selectedOrg?.$id} + {:else if selectedOrgId} diff --git a/src/routes/console/apply-credit/+page.ts b/src/routes/console/apply-credit/+page.ts index 0c0762b5e..a5e9c5792 100644 --- a/src/routes/console/apply-credit/+page.ts +++ b/src/routes/console/apply-credit/+page.ts @@ -1,5 +1,6 @@ import { base } from '$app/paths'; import type { Coupon } from '$lib/sdk/billing.js'; +import { campaigns } from '$lib/stores/campaigns.js'; import { sdk } from '$lib/stores/sdk.js'; import { redirect } from '@sveltejs/kit'; @@ -13,11 +14,12 @@ export const load = async ({ url }) => { redirect(303, `${base}/console`); } } - if (!couponData?.campaign) { + if (!couponData?.campaign || !campaigns.has(couponData.campaign)) { redirect(303, `${base}/console`); } return { - couponData + couponData, + campaign: campaigns.get(couponData.campaign) }; }; diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index 77b60f325..85d4bc2e0 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -42,8 +42,8 @@ } await invalidate(Dependencies.ACCOUNT); - trackEvent(Submit.AccountCreate, { campaign_name: data?.couponData?.code }); if (data?.couponData?.code) { + trackEvent(Submit.AccountCreate, { campaign_name: data?.couponData?.code }); await goto(`${base}/console/apply-credit?code=${data?.couponData?.code}`); return; } diff --git a/src/routes/login/+page.ts b/src/routes/login/+page.ts index ddf8ff52e..c91140d32 100644 --- a/src/routes/login/+page.ts +++ b/src/routes/login/+page.ts @@ -1,4 +1,5 @@ import { base } from '$app/paths'; +import { campaigns } from '$lib/stores/campaigns'; import { sdk } from '$lib/stores/sdk'; import { redirect } from '@sveltejs/kit'; @@ -7,9 +8,11 @@ export const load = async ({ url }) => { const code = url.searchParams.get('code'); try { const couponData = await sdk.forConsole.billing.getCoupon(code); - return { - couponData - }; + if (couponData?.campaign && campaigns.has(couponData.campaign)) { + return { + couponData + }; + } else redirect(303, `${base}/login`); } catch (e) { redirect(303, `${base}/login`); } diff --git a/src/routes/register/+page.ts b/src/routes/register/+page.ts index ac36b230e..eb4f4ae52 100644 --- a/src/routes/register/+page.ts +++ b/src/routes/register/+page.ts @@ -1,4 +1,5 @@ import { base } from '$app/paths'; +import { campaigns } from '$lib/stores/campaigns.js'; import { sdk } from '$lib/stores/sdk'; import { redirect } from '@sveltejs/kit'; @@ -7,9 +8,11 @@ export const load = async ({ url }) => { const code = url.searchParams.get('code'); try { const couponData = await sdk.forConsole.billing.getCoupon(code); - return { - couponData - }; + if (couponData?.campaign && campaigns.has(couponData.campaign)) { + return { + couponData + }; + } else redirect(303, `${base}/register`); } catch (e) { redirect(303, `${base}/register`); }