diff --git a/package.json b/package.json index c00f69e17..b804dae27 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "@ai-sdk/svelte": "^1.1.24", - "@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@5b9d902", + "@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@d7e354b", "@appwrite.io/pink-icons": "0.25.0", "@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@865e2fc", "@appwrite.io/pink-legacy": "^1.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 07d17765a..8aee84871 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: ^1.1.24 version: 1.1.24(svelte@5.25.3)(zod@3.24.3) '@appwrite.io/console': - specifier: https://pkg.vc/-/@appwrite/@appwrite.io/console@5b9d902 - version: https://pkg.vc/-/@appwrite/@appwrite.io/console@5b9d902 + specifier: https://pkg.vc/-/@appwrite/@appwrite.io/console@d7e354b + version: https://pkg.vc/-/@appwrite/@appwrite.io/console@d7e354b '@appwrite.io/pink-icons': specifier: 0.25.0 version: 0.25.0 @@ -272,8 +272,8 @@ packages: '@analytics/type-utils@0.6.2': resolution: {integrity: sha512-TD+xbmsBLyYy/IxFimW/YL/9L2IEnM7/EoV9Aeh56U64Ify8o27HJcKjo38XY9Tcn0uOq1AX3thkKgvtWvwFQg==} - '@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@5b9d902': - resolution: {tarball: https://pkg.vc/-/@appwrite/@appwrite.io/console@5b9d902} + '@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@d7e354b': + resolution: {tarball: https://pkg.vc/-/@appwrite/@appwrite.io/console@d7e354b} version: 1.10.0 '@appwrite.io/pink-icons-svelte@2.0.0-RC.1': @@ -3823,7 +3823,7 @@ snapshots: '@analytics/type-utils@0.6.2': {} - '@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@5b9d902': {} + '@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@d7e354b': {} '@appwrite.io/pink-icons-svelte@2.0.0-RC.1(svelte@5.25.3)': dependencies: diff --git a/src/lib/components/billing/estimatedTotalBox.svelte b/src/lib/components/billing/estimatedTotalBox.svelte index 80285b4cb..ba4d01acb 100644 --- a/src/lib/components/billing/estimatedTotalBox.svelte +++ b/src/lib/components/billing/estimatedTotalBox.svelte @@ -4,7 +4,7 @@ import { Card, Divider, Layout, Typography } from '@appwrite.io/pink-svelte'; import { CreditsApplied } from '.'; import { sdk } from '$lib/stores/sdk'; - import { AppwriteException, BillingPlan, type Models } from '@appwrite.io/console'; + import { AppwriteException, type Models } from '@appwrite.io/console'; import DiscountsApplied from './discountsApplied.svelte'; export let billingPlan: Models.BillingPlan; @@ -23,12 +23,9 @@ collaborators: string[], couponId: string | undefined ) { - /* TODO: @itznotabug - temporary fix */ - const billingPlanTyped = billingPlan as BillingPlan; - try { estimation = await sdk.forConsole.organizations.estimationCreateOrganization({ - billingPlan: billingPlanTyped, + billingPlan, invites: collaborators ?? [], couponId: couponId === '' ? null : couponId }); @@ -59,7 +56,7 @@ try { estimation = await sdk.forConsole.organizations.estimationUpdatePlan({ organizationId, - billingPlan: billingPlan as BillingPlan, + billingPlan: billingPlan, invites: collaborators ?? [], couponId: couponId && couponId.length > 0 ? couponId : null }); diff --git a/src/lib/components/progressbar/ProgressBar.svelte b/src/lib/components/progressbar/ProgressBar.svelte index a4cebc8ee..4591e706e 100644 --- a/src/lib/components/progressbar/ProgressBar.svelte +++ b/src/lib/components/progressbar/ProgressBar.svelte @@ -22,7 +22,7 @@
{#each $$props.data as item} - +
; - -export class Billing { - client: Client; - - constructor(client: Client) { - this.client = client; - } - - async createOrganization( - organizationId: string, - name: string, - billingPlan: string, - paymentMethodId: string, - billingAddressId: string = undefined, - couponId: string = null, - invites: Array = [], - budget: number = undefined, - taxId: string = null - ): Promise { - const path = `/organizations`; - const params = { - organizationId, - name, - billingPlan, - paymentMethodId, - billingAddressId, - couponId, - invites, - budget, - taxId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'POST', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async updatePlan( - organizationId: string, - billingPlan: string, - paymentMethodId: string, - billingAddressId: string = undefined, - couponId: string = null, - invites: Array = [], - budget: number = undefined, - taxId: string = null - ): Promise { - const path = `/organizations/${organizationId}/plan`; - const params = { - organizationId, - billingPlan, - paymentMethodId, - billingAddressId, - couponId, - invites, - budget, - taxId - }; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async cancelDowngrade( - organizationId: string - ): Promise { - const path = `/organizations/${organizationId}/plan/cancel`; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json' - }); - } -} diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 90bad262d..95eb8fbfb 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -11,7 +11,6 @@ import PaymentAuthRequired from '$lib/components/billing/alerts/paymentAuthRequi import PaymentMandate from '$lib/components/billing/alerts/paymentMandate.svelte'; import { NEW_DEV_PRO_UPGRADE_COUPON } from '$lib/constants'; import { cachedStore } from '$lib/helpers/cache'; -import { type Size, sizeToBytes } from '$lib/helpers/sizeConvertion'; import type { BillingPlansMap } from '$lib/sdk/billing'; import { isCloud } from '$lib/system'; import { activeHeaderAlert, orgMissingPaymentMethod } from '$routes/(console)/store'; @@ -25,7 +24,7 @@ import { import { derived, get, writable } from 'svelte/store'; import { headerAlert } from './headerAlert'; import { addNotification, notifications } from './notifications'; -import { currentPlan, type OrganizationError } from './organization'; +import { currentPlan } from './organization'; import { canSeeBilling } from './roles'; import { sdk } from './sdk'; import { user } from './user'; @@ -667,31 +666,10 @@ export const upgradeURL = derived(page, ($page) => { }); }); -export const billingURL = derived(page, ($page) => { - return resolve('/(console)/organization-[organization]/billing', { - organization: $page.data?.organization?.$id - }); -}); - export const hideBillingHeaderRoutes = [resolve('/account'), resolve('/create-organization')]; -export function calculateExcess(addon: Models.AggregationTeam, plan: Models.BillingPlan) { - return { - bandwidth: calculateResourceSurplus(addon.usageBandwidth, plan.bandwidth), - storage: calculateResourceSurplus(addon.usageStorage, plan.storage, 'GB'), - executions: calculateResourceSurplus(addon.usageExecutions, plan.executions, 'GB'), - members: addon.additionalMembers - }; -} - -export function calculateResourceSurplus(total: number, limit: number, limitUnit: Size = null) { - if (total === undefined || limit === undefined) return 0; - const realLimit = (limitUnit ? sizeToBytes(limit, limitUnit) : limit) || Infinity; - return total > realLimit ? total - realLimit : 0; -} - -export function isOrganization( - org: Models.Organization | OrganizationError -): org is Models.Organization { - return (org as Models.Organization).$id !== undefined; +export function isPaymentAuthenticationRequired( + org: Models.Organization | Models.PaymentAuthentication +): org is Models.PaymentAuthentication { + return 'clientSecret' in org; } diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index f0e15a0ac..8503d8f63 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -4,15 +4,6 @@ import { isCloud } from '$lib/system'; import { derived, writable } from 'svelte/store'; import { type Models, Platform, Query } from '@appwrite.io/console'; -export type OrganizationError = { - status: number; - message: string; - teamId: string; - invoiceId: string; - clientSecret: string; - type: string; -}; - export const newOrgModal = writable(false); export const newMemberModal = writable(false); export const organizationList = derived( diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 05f9f54db..38cf83b7f 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -25,7 +25,6 @@ import { Realtime, Organizations } from '@appwrite.io/console'; -import { Billing } from '../sdk/billing'; import { Backups } from '../sdk/backups'; import { Sources } from '$lib/sdk/sources'; import { @@ -91,7 +90,6 @@ function createConsoleSdk(client: Client) { migrations: new Migrations(client), console: new Console(client), assistant: new Assistant(client), - billing: new Billing(client), sources: new Sources(client), sites: new Sites(client), domains: new Domains(client), diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index e96002202..b1cbfedbf 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -9,7 +9,7 @@ import { toLocaleDate } from '$lib/helpers/date'; import { Wizard } from '$lib/layout'; import { addNotification } from '$lib/stores/notifications'; - import { type OrganizationError, organizationList } from '$lib/stores/organization'; + import { organizationList } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; import { confirmPayment } from '$lib/stores/stripe.js'; import { BillingPlanGroup, ID, type Models } from '@appwrite.io/console'; @@ -18,7 +18,7 @@ import { billingIdToPlan, getBasePlanFromGroup, - isOrganization, + isPaymentAuthenticationRequired, plansInfo } from '$lib/stores/billing'; import { Fieldset, Icon, Layout, Tooltip } from '@appwrite.io/pink-svelte'; @@ -133,32 +133,30 @@ if (couponForm && !couponForm.checkValidity()) return; isSubmitting.set(true); try { - let org: Models.Organization | OrganizationError; + let org: Models.Organization | Models.PaymentAuthentication; // Create new org if (selectedOrgId === newOrgId) { - org = await sdk.forConsole.billing.createOrganization( - newOrgId, + org = await sdk.forConsole.organizations.create({ + organizationId: newOrgId, name, - billingPlan.$id, + billingPlan: billingPlan.$id, paymentMethodId, - undefined, - couponData.code ? couponData.code : null, - collaborators, - billingBudget, - taxId - ); + invites: collaborators, + couponId: couponData.code ? couponData.code : null, + taxId, + budget: billingBudget + }); } // Upgrade existing org else if (selectedOrg?.billingPlan !== billingPlan.$id && isUpgrade()) { - org = await sdk.forConsole.billing.updatePlan( - selectedOrg.$id, - billingPlan.$id, + org = await sdk.forConsole.organizations.updatePlan({ + organizationId: selectedOrg.$id, + billingPlan: billingPlan.$id, paymentMethodId, - undefined, - couponData.code ? couponData.code : null, - collaborators - ); + invites: collaborators, + couponId: couponData.code ? couponData.code : null + }); } // Existing pro org, apply credits else { @@ -169,11 +167,11 @@ }); } - if (!isOrganization(org) && org.status === 402) { + if (isPaymentAuthenticationRequired(org)) { let clientSecret = org.clientSecret; let params = new URLSearchParams(); params.append('type', 'payment_confirmed'); - params.append('org', org.teamId); + params.append('org', org.organizationId); for (const [key, value] of page.url.searchParams.entries()) { if (key !== 'type' && key !== 'id') { params.append(key, value); @@ -188,12 +186,12 @@ ); org = await sdk.forConsole.organizations.validatePayment({ - organizationId: org.teamId, + organizationId: org.organizationId, invites: collaborators }); } - if (isOrganization(org)) { + if (!isPaymentAuthenticationRequired(org)) { trackEvent(Submit.CreditRedeem, { coupon: couponData.code, campaign: couponData?.campaign diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index d1751e048..f2ca6c32c 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -8,12 +8,15 @@ import { Dependencies } from '$lib/constants'; import { Button, Form, InputTags, InputText } from '$lib/elements/forms'; import { Wizard } from '$lib/layout'; - import { billingIdToPlan, getBasePlanFromGroup, isOrganization } from '$lib/stores/billing'; + import { + billingIdToPlan, + getBasePlanFromGroup, + isPaymentAuthenticationRequired + } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; - import type { OrganizationError } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; import { confirmPayment } from '$lib/stores/stripe'; - import { BillingPlan, BillingPlanGroup, ID, type Models } from '@appwrite.io/console'; + import { BillingPlanGroup, ID, type Models } from '@appwrite.io/console'; import { IconPlus } from '@appwrite.io/pink-icons-svelte'; import { Divider, Fieldset, Icon, Layout, Link, Typography } from '@appwrite.io/pink-svelte'; import { writable } from 'svelte/store'; @@ -24,8 +27,8 @@ const { data }: PageProps = $props(); let showExitModal = $state(false); + let selectedPlan = $state(data.plan); let previousPage: string = $state(resolve('/(console)')); - let selectedPlan: Models.BillingPlan = $state(data.plan); let selectedCoupon: Partial | null = $state(data.coupon); let isSubmitting = $state(writable(false)); @@ -64,8 +67,8 @@ } if (page.url.searchParams.has('plan')) { - const plan = page.url.searchParams.get('plan') as BillingPlan; - if (plan && Object.values(BillingPlan).includes(plan)) { + const plan = page.url.searchParams.get('plan'); + if (plan) { billingPlan = plan; } } @@ -94,7 +97,7 @@ invites }); - if (isOrganization(org)) { + if (!isPaymentAuthenticationRequired(org)) { await preloadData(`${base}/console/organization-${org.$id}`); await goto(`${base}/console/organization-${org.$id}`); addNotification({ @@ -113,33 +116,31 @@ async function create() { try { - let org: Models.Organization | OrganizationError; + let org: Models.Organization | Models.PaymentAuthentication; if (selectedPlan.group === BillingPlanGroup.Starter) { - org = await sdk.forConsole.billing.createOrganization( - ID.unique(), - name, - getBasePlanFromGroup(BillingPlanGroup.Starter).$id, - null - ); + org = await sdk.forConsole.organizations.create({ + organizationId: ID.unique(), + name: name, + billingPlan: getBasePlanFromGroup(BillingPlanGroup.Starter).$id + }); } else { - org = await sdk.forConsole.billing.createOrganization( - ID.unique(), + org = await sdk.forConsole.organizations.create({ + organizationId: ID.unique(), name, - selectedPlan.$id, + billingPlan: selectedPlan.$id, paymentMethodId, - undefined, - selectedCoupon?.code, - collaborators, - billingBudget, + couponId: selectedCoupon?.code, + invites: collaborators, + budget: billingBudget, taxId - ); + }); - if (!isOrganization(org) && org.status === 402) { + if (isPaymentAuthenticationRequired(org)) { let clientSecret = org.clientSecret; let params = new URLSearchParams(); params.append('type', 'payment_confirmed'); - params.append('id', org.teamId); + params.append('id', org.organizationId); for (const [key, value] of page.url.searchParams.entries()) { if (key !== 'type' && key !== 'id') { params.append(key, value); @@ -152,7 +153,7 @@ paymentMethodId, `${base}/create-organization?${params}` ); - await validate(org.teamId, collaborators); + await validate(org.organizationId, collaborators); } } @@ -162,7 +163,7 @@ members_invited: collaborators?.length }); - if (isOrganization(org)) { + if (!isPaymentAuthenticationRequired(org)) { await invalidate(Dependencies.ACCOUNT); await preloadData(`${base}/organization-${org.$id}`); await goto(`${base}/organization-${org.$id}`); diff --git a/src/routes/(console)/create-organization/+page.ts b/src/routes/(console)/create-organization/+page.ts index 1aea815e7..8e33b6294 100644 --- a/src/routes/(console)/create-organization/+page.ts +++ b/src/routes/(console)/create-organization/+page.ts @@ -1,6 +1,6 @@ import { sdk } from '$lib/stores/sdk'; import type { PageLoad } from './$types'; -import { BillingPlan, BillingPlanGroup, type Models, Platform } from '@appwrite.io/console'; +import { BillingPlanGroup, type Models, Platform } from '@appwrite.io/console'; import { Dependencies } from '$lib/constants'; import { billingIdToPlan, getNextTierBillingPlan } from '$lib/stores/billing'; @@ -44,7 +44,8 @@ async function getPlanFromUrl(url: URL): Promise { } // fallback - return await sdk.forConsole.console.getPlan({ planId: BillingPlan.Tier0 }); + // @todo: avoid hardcoded maybe + return await sdk.forConsole.console.getPlan({ planId: 'tier-0' }); } function getPlanFromCache(plan: string): Models.BillingPlan | null { diff --git a/src/routes/(console)/onboarding/create-organization/+page.svelte b/src/routes/(console)/onboarding/create-organization/+page.svelte index d1a596e3a..62cbcd5dd 100644 --- a/src/routes/(console)/onboarding/create-organization/+page.svelte +++ b/src/routes/(console)/onboarding/create-organization/+page.svelte @@ -22,12 +22,11 @@ try { if (isCloud) { const starter = getBasePlanFromGroup(BillingPlanGroup.Starter); - organization = await sdk.forConsole.billing.createOrganization( - ID.unique(), - organizationName, - starter.$id, - null - ); + organization = await sdk.forConsole.organizations.create({ + organizationId: ID.unique(), + name: organizationName, + billingPlan: starter.$id + }); trackEvent(Submit.OrganizationCreate, { plan: starter?.name, diff --git a/src/routes/(console)/onboarding/create-project/+page.ts b/src/routes/(console)/onboarding/create-project/+page.ts index 15a1b6fdf..4dfa4b9b2 100644 --- a/src/routes/(console)/onboarding/create-project/+page.ts +++ b/src/routes/(console)/onboarding/create-project/+page.ts @@ -2,7 +2,7 @@ import type { PageLoad } from './$types'; import { isCloud } from '$lib/system'; import { sdk } from '$lib/stores/sdk'; import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; -import { getBasePlanFromGroup, isOrganization } from '$lib/stores/billing'; +import { getBasePlanFromGroup, isPaymentAuthenticationRequired } from '$lib/stores/billing'; import { BillingPlanGroup, ID, type Models, Query } from '@appwrite.io/console'; import { redirect } from '@sveltejs/kit'; import { base } from '$app/paths'; @@ -25,19 +25,18 @@ export const load: PageLoad = async ({ parent }) => { try { if (isCloud) { const starterPlan = getBasePlanFromGroup(BillingPlanGroup.Starter); - const org = await sdk.forConsole.billing.createOrganization( - ID.unique(), - 'Personal projects', - starterPlan.$id, - null - ); + const org = await sdk.forConsole.organizations.create({ + organizationId: ID.unique(), + name: 'Personal projects', + billingPlan: starterPlan.$id + }); trackEvent(Submit.OrganizationCreate, { plan: starterPlan?.name, budget_cap_enabled: false, members_invited: 0 }); - if (isOrganization(org)) { + if (!isPaymentAuthenticationRequired(org)) { return { accountPrefs, organization: org diff --git a/src/routes/(console)/organization-[organization]/billing/cancelDowngradeModal.svelte b/src/routes/(console)/organization-[organization]/billing/cancelDowngradeModal.svelte index 448fc8961..84b985434 100644 --- a/src/routes/(console)/organization-[organization]/billing/cancelDowngradeModal.svelte +++ b/src/routes/(console)/organization-[organization]/billing/cancelDowngradeModal.svelte @@ -15,7 +15,10 @@ async function cancelDowngrade() { try { - await sdk.forConsole.billing.cancelDowngrade($organization.$id); + await sdk.forConsole.organizations.cancelDowngrade({ + organizationId: $organization.$id + }); + await invalidate(Dependencies.ORGANIZATION); showCancel = false; addNotification({ diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index d71ce0086..e3ebb2f9c 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -9,7 +9,11 @@ import { Button, Form, InputSelect, InputTags, InputTextarea } from '$lib/elements/forms'; import { formatCurrency } from '$lib/helpers/numbers.js'; import { Wizard } from '$lib/layout'; - import { billingIdToPlan, getBasePlanFromGroup, isOrganization } from '$lib/stores/billing'; + import { + billingIdToPlan, + getBasePlanFromGroup, + isPaymentAuthenticationRequired + } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; import { currentPlan, organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; @@ -161,11 +165,11 @@ async function downgrade() { try { // 1) update the plan first - await sdk.forConsole.billing.updatePlan( - data.organization.$id, - selectedPlan.$id, + await sdk.forConsole.organizations.updatePlan({ + organizationId: data.organization.$id, + billingPlan: selectedPlan.$id, paymentMethodId - ); + }); // 2) If the target plan has a project limit, apply selected projects now const targetProjectsLimit = selectedPlan?.projects ?? 0; @@ -211,7 +215,7 @@ invites }); - if (isOrganization(org)) { + if (!isPaymentAuthenticationRequired(org)) { await invalidate(Dependencies.ACCOUNT); await invalidate(Dependencies.ORGANIZATION); @@ -244,18 +248,17 @@ !data?.members?.memberships?.find((m) => m.userEmail === collaborator) ); } - const org = await sdk.forConsole.billing.updatePlan( - data.organization.$id, - selectedPlan.$id, + const org = await sdk.forConsole.organizations.updatePlan({ + organizationId: data.organization.$id, + billingPlan: selectedPlan.$id, paymentMethodId, - undefined, - selectedCoupon?.code, - newCollaborators, - billingBudget, - taxId ? taxId : null - ); + couponId: selectedCoupon?.code, + invites: newCollaborators, + budget: billingBudget, + taxId: taxId ? taxId : null + }); - if (!isOrganization(org) && org.status == 402) { + if (isPaymentAuthenticationRequired(org)) { let clientSecret = org.clientSecret; let params = new URLSearchParams(); for (const [key, value] of page.url.searchParams.entries()) { @@ -264,7 +267,7 @@ } } params.append('type', 'payment_confirmed'); - params.append('id', org.teamId); + params.append('id', org.organizationId); params.append('invites', collaborators.join(',')); params.append('plan', selectedPlan.$id); await confirmPayment( @@ -273,10 +276,10 @@ paymentMethodId, base + '/change-plan?' + params.toString() ); - await validate(org.teamId, collaborators); + await validate(org.organizationId, collaborators); } - if (isOrganization(org)) { + if (!isPaymentAuthenticationRequired(org)) { /** * Reload on upgrade (e.g. Free → Paid) */ diff --git a/src/routes/(console)/project-[region]-[project]/overview/onboard.svelte b/src/routes/(console)/project-[region]-[project]/overview/onboard.svelte index 78757226d..8650aa498 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/onboard.svelte +++ b/src/routes/(console)/project-[region]-[project]/overview/onboard.svelte @@ -28,7 +28,7 @@ import PlatformFlutterImgSourceDark from './assets/platform-flutter-dark.svg'; import PlatformSdkImgSource from './assets/platform-sdk.jpg'; import PlatformSdkImgSourceDark from './assets/platform-sdk-dark.png'; - import { base } from '$app/paths'; + import { resolve } from '$app/paths'; import { isSmallViewport } from '$lib/stores/viewport'; import type { Models } from '@appwrite.io/console'; import { getPlatformInfo } from '$lib/helpers/platform'; @@ -36,40 +36,45 @@ import { goto } from '$app/navigation'; import { page } from '$app/state'; - export let pingCount = 0; - export let platforms: Models.Platform[] = []; + let { + pingCount = 0, + platforms = [] + }: { + pingCount: number; + platforms: Array; + } = $props(); + + const platformMap = $derived.by(() => { + const map = new Map(); + platforms.forEach((platform) => { + const platformInfo = getPlatformInfo(platform.type); + map.set(platformInfo.name, platform); + }); + + return map; + }); + + const projectRoute = $derived.by(() => { + return resolve('/(console)/project-[region]-[project]', { + region: page.params.region, + project: page.params.project + }); + }); function createKey() { - trackEvent(Click.KeyCreateClick, { - source: 'onboarding' - }); - goto( - `${base}/project-${page.params.region}-${page.params.project}/overview/api-keys/create`, - { - replaceState: true - } - ); + trackEvent(Click.KeyCreateClick, { source: 'onboarding' }); + + goto(`${projectRoute}/overview/api-keys/create`, { replaceState: true }); } function openPlatformWizard(type: number, platform?: Models.Platform) { if (platform) { - continuePlatform(type, platform.name, platform.key, platform.type); + continuePlatform(type, platform.name, platform.type); } else { trackEvent(Click.PlatformCreateClick, { source: 'onboarding' }); addPlatform(type); } } - - let platformMap = new Map(); - - $: { - let updatedMap = new Map(); - platforms.forEach((platform) => { - const platformInfo = getPlatformInfo(platform.type); - updatedMap.set(platformInfo.name, platform); - }); - platformMap = updatedMap; - }
@@ -410,9 +415,7 @@ { trackEvent(Click.OnboardingSetupDatabaseClick); - goto( - `${base}/project-${page.params.region}-${page.params.project}/databases` - ); + goto(`${projectRoute}/databases`); }} padding="s" > { trackEvent( Click.OnboardingAuthEmailPasswordClick @@ -517,7 +520,7 @@ { trackEvent( Click.OnboardingAuthOauth2Click @@ -525,7 +528,7 @@ }}>OAuth 2 { trackEvent( Click.OnboardingAuthAllMethodsClick diff --git a/src/routes/(console)/project-[region]-[project]/overview/platforms/+page.svelte b/src/routes/(console)/project-[region]-[project]/overview/platforms/+page.svelte index c86b1b50d..22d0bce77 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/platforms/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/overview/platforms/+page.svelte @@ -27,25 +27,20 @@ }); } - export async function continuePlatform( - platform: Platform, - name: string, - key: string, - type: PlatformType - ) { + export async function continuePlatform(platform: Platform, name: string, type: PlatformType) { createPlatform.set({ name: name, - key: key, type: type }); + trackEvent(Click.PlatformCreateClick, { platform: platforms[platform], state: 'continue' }); + wizard.start(platforms[platform], null, 1, { isConnectPlatform: true, - platform: type, - key: key + platform: type }); } diff --git a/src/routes/(console)/project-[region]-[project]/overview/platforms/wizard/store.ts b/src/routes/(console)/project-[region]-[project]/overview/platforms/wizard/store.ts index e15dcfbf2..24f28def6 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/platforms/wizard/store.ts +++ b/src/routes/(console)/project-[region]-[project]/overview/platforms/wizard/store.ts @@ -6,7 +6,6 @@ function createPlatformStore() { $id: null, name: null, hostname: null, - key: null, store: null, type: null }); @@ -20,7 +19,6 @@ function createPlatformStore() { $id: null, name: null, hostname: null, - key: null, store: null, type: null }); diff --git a/src/routes/(console)/supportWizard.svelte b/src/routes/(console)/supportWizard.svelte index eabf8a26b..7fe3fc710 100644 --- a/src/routes/(console)/supportWizard.svelte +++ b/src/routes/(console)/supportWizard.svelte @@ -1,6 +1,15 @@