From eeeb762fec3870422b6dd68c113dee74b7488b0b Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 14 Dec 2023 13:30:57 +0100 Subject: [PATCH] fix: post release modal --- src/lib/stores/billing.ts | 3 +- .../(billing-modal)/postReleaseModal.svelte | 109 +++++++++++------- src/routes/console/+layout.svelte | 3 +- 3 files changed, 74 insertions(+), 41 deletions(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 371ca8edd..44e492ffd 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -291,7 +291,8 @@ export async function checkForFreeOrgOverflow(orgs: Models.TeamList>) { + if (!orgs?.teams?.length) return; const modalTime = localStorage.getItem('postReleaseProModal'); const now = Date.now(); // show the modal if it was never shown diff --git a/src/routes/console/(billing-modal)/postReleaseModal.svelte b/src/routes/console/(billing-modal)/postReleaseModal.svelte index 4eefaf293..ee51e7b17 100644 --- a/src/routes/console/(billing-modal)/postReleaseModal.svelte +++ b/src/routes/console/(billing-modal)/postReleaseModal.svelte @@ -3,17 +3,45 @@ import SideLight from './side-light.png'; import SideDark from './side-dark.png'; import { app } from '$lib/stores/app'; - import { Button } from '$lib/elements/forms'; + import { Button, FormList } from '$lib/elements/forms'; import { trackEvent } from '$lib/actions/analytics'; import { wizard } from '$lib/stores/wizard'; import ChangeOrganizationTierCloud from '../changeOrganizationTierCloud.svelte'; import { user } from '$lib/stores/user'; + import { onMount } from 'svelte'; + import { sdk } from '$lib/stores/sdk'; + import { goto } from '$app/navigation'; + import { base } from '$app/paths'; + import type { Organization } from '$lib/stores/organization'; + import InputSelect from '$lib/elements/forms/inputSelect.svelte'; export let show = false; + let orgs: { teams: Organization[]; total: number }; + let selectedOrg: string; - $: isNewUser = new Date($user.$createdAt) > new Date(2023, 11, 12); - //user creation date after the 12th of December 2023 + onMount(async () => { + orgs = (await sdk.forConsole.teams.list()) as { teams: Organization[]; total: number }; + }); + + async function handleUpgrade() { + if (selectedOrg) { + await goto(`${base}/console/organization/${selectedOrg}/billing`); + } else { + const freeOrg = orgs.teams.find((o) => o.billingPlan === 'tier-0'); + await goto(`${base}/console/organization/${freeOrg.$id}/billing`); + } + show = false; + wizard.start(ChangeOrganizationTierCloud); + trackEvent('click_organization_upgrade', { + source: event + }); + } + + $: isNewUser = new Date($user.$createdAt) > new Date(2023, 11, 18); + //user creation date after the 18th of December 2023 $: event = isNewUser ? 'billing_new_user_modal' : 'billing_release_modal'; + $: freeOrgs = orgs?.teams.filter((o) => o.billingPlan === 'tier-0'); + $: options = freeOrgs.map((o) => ({ label: o.name, value: o.$id })); @@ -38,7 +66,7 @@

Upgrade now and use the code {isNewUser ? 'WELCOME15' : 'THANKYOU30'} + >{isNewUser ? 'PRO15' : 'THANKYOU30'} to claim ${isNewUser ? '15' : '30'} in credits for a Pro plan. Credits will expire on 31 January 2024.

@@ -58,41 +86,44 @@ }}>Learn more on our pricing page.

-
    -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
- diff --git a/src/routes/console/+layout.svelte b/src/routes/console/+layout.svelte index e4bd24327..7331f35b2 100644 --- a/src/routes/console/+layout.svelte +++ b/src/routes/console/+layout.svelte @@ -248,12 +248,13 @@ if (isCloud) { if (!$page.url.pathname.includes('/console/onboarding')) { - checkForPostReleaseProModal(); } try { const orgs = await sdk.forConsole.teams.list([ Query.equal('billingPlan', 'tier-0') ]); + + checkForPostReleaseProModal(orgs); checkForFreeOrgOverflow(orgs); } catch (error) { console.log(error);