mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Merge pull request #1922 from appwrite/fix-onboarding-redirection
fix: onboarding redirection
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
}
|
||||
|
||||
// safe side!
|
||||
loadAvailableRegions(data.organization.$id);
|
||||
loadAvailableRegions(data.organization?.$id);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { isCloud } from '$lib/system';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
|
||||
import { isOrganization, tierToPlan } from '$lib/stores/billing';
|
||||
import { ID, Query } from '@appwrite.io/console';
|
||||
import { ID, Query, type Models } from '@appwrite.io/console';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { base } from '$app/paths';
|
||||
@@ -12,61 +12,62 @@ import { base } from '$app/paths';
|
||||
export const load: PageLoad = async ({ parent }) => {
|
||||
const { organizations } = await parent();
|
||||
|
||||
try {
|
||||
if (!organizations?.total) {
|
||||
try {
|
||||
if (isCloud) {
|
||||
const org = await sdk.forConsole.billing.createOrganization(
|
||||
ID.unique(),
|
||||
'Personal projects',
|
||||
BillingPlan.FREE,
|
||||
null,
|
||||
null
|
||||
);
|
||||
trackEvent(Submit.OrganizationCreate, {
|
||||
plan: tierToPlan(BillingPlan.FREE)?.name,
|
||||
budget_cap_enabled: false,
|
||||
members_invited: 0
|
||||
});
|
||||
if (!organizations?.total) {
|
||||
try {
|
||||
if (isCloud) {
|
||||
const org = await sdk.forConsole.billing.createOrganization(
|
||||
ID.unique(),
|
||||
'Personal projects',
|
||||
BillingPlan.FREE,
|
||||
null,
|
||||
null
|
||||
);
|
||||
trackEvent(Submit.OrganizationCreate, {
|
||||
plan: tierToPlan(BillingPlan.FREE)?.name,
|
||||
budget_cap_enabled: false,
|
||||
members_invited: 0
|
||||
});
|
||||
|
||||
if (isOrganization(org)) {
|
||||
return {
|
||||
organization: org
|
||||
};
|
||||
} else {
|
||||
const e = new Error(org.message, {
|
||||
cause: org
|
||||
});
|
||||
trackError(e, Submit.OrganizationCreate);
|
||||
}
|
||||
} else {
|
||||
if (isOrganization(org)) {
|
||||
return {
|
||||
organization: await sdk.forConsole.teams.create(
|
||||
ID.unique(),
|
||||
'Personal projects'
|
||||
)
|
||||
organization: org
|
||||
};
|
||||
} else {
|
||||
const e = new Error(org.message, {
|
||||
cause: org
|
||||
});
|
||||
trackError(e, Submit.OrganizationCreate);
|
||||
}
|
||||
} catch (e) {
|
||||
trackError(e, Submit.OrganizationCreate);
|
||||
} else {
|
||||
return {
|
||||
organization: await sdk.forConsole.teams.create(
|
||||
ID.unique(),
|
||||
'Personal projects'
|
||||
)
|
||||
};
|
||||
}
|
||||
} else if (organizations?.total === 1) {
|
||||
const org = organizations.teams[0];
|
||||
const projects = await sdk.forConsole.projects.list([
|
||||
} catch (e) {
|
||||
trackError(e, Submit.OrganizationCreate);
|
||||
}
|
||||
} else if (organizations?.total === 1) {
|
||||
const org = organizations.teams[0];
|
||||
let projects: Models.ProjectList = null;
|
||||
try {
|
||||
projects = await sdk.forConsole.projects.list([
|
||||
Query.equal('teamId', org.$id),
|
||||
Query.limit(1)
|
||||
]);
|
||||
if (!projects.total) {
|
||||
return {
|
||||
organization: org
|
||||
};
|
||||
} else {
|
||||
redirect(303, `${base}/console/organization-${org.$id}`);
|
||||
}
|
||||
} else {
|
||||
redirect(303, `${base}/console/organization-${organizations.teams[0].$id}`);
|
||||
} catch (e) {
|
||||
redirect(303, `${base}/organization-${org.$id}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (!projects?.total) {
|
||||
return {
|
||||
organization: org
|
||||
};
|
||||
} else {
|
||||
redirect(303, `${base}/organization-${org.$id}`);
|
||||
}
|
||||
} else {
|
||||
redirect(303, `${base}/organization-${organizations.teams[0].$id}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ let lastLoadedOrganization = null;
|
||||
* Prevents unnecessary API calls if the regions are already loaded for the same organization.
|
||||
*/
|
||||
export async function loadAvailableRegions(orgId: string): Promise<void> {
|
||||
if (!isCloud) return;
|
||||
if (!isCloud || !orgId) return;
|
||||
|
||||
try {
|
||||
const storedRegions = get(regions);
|
||||
|
||||
Reference in New Issue
Block a user