diff --git a/src/lib/helpers/pricingRedirect.ts b/src/lib/helpers/pricingRedirect.ts new file mode 100644 index 000000000..5de04212f --- /dev/null +++ b/src/lib/helpers/pricingRedirect.ts @@ -0,0 +1,13 @@ +import { goto } from '$app/navigation'; +import { base } from '$app/paths'; + +export function checkPricingRefAndRedirect(searchParams: URLSearchParams, shouldRegister = false) { + if (searchParams.has('type')) { + const paramType = searchParams.get('type'); + if (paramType === 'createPro') { + shouldRegister + ? goto(`${base}/register?type=createPro`) + : goto(`${base}/create-organization?type=createPro`); + } + } +} diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index c463a5d4a..63cc1f210 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -79,7 +79,11 @@ billingPlan = plan as BillingPlan; } } - if (anyOrgFree) { + if ( + anyOrgFree || + ($page.url.searchParams.has('type') && + $page.url.searchParams.get('type') === 'createPro') + ) { billingPlan = BillingPlan.PRO; } }); diff --git a/src/routes/(console)/onboarding/+page.svelte b/src/routes/(console)/onboarding/+page.svelte index 3f112011c..b4a9b4aba 100644 --- a/src/routes/(console)/onboarding/+page.svelte +++ b/src/routes/(console)/onboarding/+page.svelte @@ -17,6 +17,7 @@ import { tierToPlan, type Tier, plansInfo } from '$lib/stores/billing'; import { formatCurrency } from '$lib/helpers/numbers'; import { base } from '$app/paths'; + import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect'; let name: string; let id: string; @@ -42,12 +43,7 @@ onMount(() => { if (isCloud) { - if ($page.url.searchParams.has('type')) { - const paramType = $page.url.searchParams.get('type'); - if (paramType === 'createPro') { - goto(`${base}/create-organization`); - } - } + checkPricingRefAndRedirect($page.url.searchParams); } }); diff --git a/src/routes/(console)/organization-[organization]/+page.svelte b/src/routes/(console)/organization-[organization]/+page.svelte index d16339072..76607b429 100644 --- a/src/routes/(console)/organization-[organization]/+page.svelte +++ b/src/routes/(console)/organization-[organization]/+page.svelte @@ -32,6 +32,7 @@ import { onMount } from 'svelte'; import { organization } from '$lib/stores/organization'; import { canWriteProjects } from '$lib/stores/roles'; + import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect'; export let data; @@ -123,12 +124,7 @@ onMount(async () => { if (isCloud) { regions = await sdk.forConsole.billing.listRegions(); - if ($page.url.searchParams.has('type')) { - const paramType = $page.url.searchParams.get('type'); - if (paramType === 'createPro') { - goto(`${base}/create-organization`); - } - } + checkPricingRefAndRedirect($page.url.searchParams); } }); diff --git a/src/routes/(public)/(guest)/register/+page.svelte b/src/routes/(public)/(guest)/register/+page.svelte index f8fab2e6f..96fe43ae0 100644 --- a/src/routes/(public)/(guest)/register/+page.svelte +++ b/src/routes/(public)/(guest)/register/+page.svelte @@ -20,6 +20,7 @@ import { isCloud } from '$lib/system'; import { page } from '$app/stores'; import { redirectTo } from '$routes/store'; + import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect'; export let data; @@ -52,6 +53,8 @@ $page.url.searchParams.delete('redirect'); if (redirect) { await goto(`${redirect}${$page.url.search}`); + } else if (isCloud) { + checkPricingRefAndRedirect($page.url.searchParams); } else { await goto(`${base}/${$page.url.search ?? ''}`); } diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 77fd3e8b1..134ef1e22 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -9,6 +9,8 @@ import { redirectTo } from './store'; import { base } from '$app/paths'; import type { Account } from '$lib/stores/user'; import type { AppwriteException } from '@appwrite.io/console'; +import { isCloud } from '$lib/system'; +import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect'; export const ssr = false; @@ -46,6 +48,10 @@ export const load: LayoutLoad = async ({ depends, url, route }) => { } if (!isPublicRoute) { + if (isCloud) { + checkPricingRefAndRedirect(url.searchParams, true); + } + redirect(303, withParams(`${base}/login`, url.searchParams)); } };