Check and handle if the console is visited from the start building pro button on the site

This commit is contained in:
ernstmul
2025-01-08 10:08:02 +01:00
parent be7aa21121
commit b65eaaa78b
6 changed files with 31 additions and 13 deletions
+13
View File
@@ -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`);
}
}
}
@@ -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;
}
});
+2 -6
View File
@@ -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);
}
});
@@ -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);
}
});
@@ -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 ?? ''}`);
}
+6
View File
@@ -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));
}
};