Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start building PRO flow #1601

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/lib/helpers/pricingRedirect.ts
Original file line number Diff line number Diff line change
@@ -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`);
}
Comment on lines +7 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we know if we are going to open scale as well, like createScale in the params? I am not yet aware of the Scale GA. If not, lgtm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently on the website that button is still disabled, and also in the console it's not a visible option. So I thought: we'll cross that bridge when we get there. It is the reason I moved everything into 1 function, so we can easily adjust it when we do need to make that change!

}
}
6 changes: 5 additions & 1 deletion src/routes/(console)/create-organization/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down
8 changes: 2 additions & 6 deletions src/routes/(console)/onboarding/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
});

Expand Down
8 changes: 2 additions & 6 deletions src/routes/(console)/organization-[organization]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
});

Expand Down
3 changes: 3 additions & 0 deletions src/routes/(public)/(guest)/register/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ?? ''}`);
}
Expand Down
6 changes: 6 additions & 0 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
};
Expand Down
Loading