diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 646fdc175..3c93d32ae 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -1,5 +1,5 @@ import type { Client, Models } from '@appwrite.io/console'; -import type { CreateOrgAuth, Organization, OrganizationList } from '../stores/organization'; +import type { OrganizationError, Organization, OrganizationList } from '../stores/organization'; import type { PaymentMethod } from '@stripe/stripe-js'; import type { Tier } from '$lib/stores/billing'; @@ -332,7 +332,7 @@ export class Billing { invites: Array = [], budget: number = undefined, taxId: string = null - ): Promise { + ): Promise { const path = `/organizations`; const params = { organizationId, diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index d41cc3f54..ca7269ca3 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -3,7 +3,7 @@ import { derived, writable } from 'svelte/store'; import type { Models } from '@appwrite.io/console'; import type { Tier } from './billing'; -export type CreateOrgAuth = { +export type OrganizationError = { status: number; message: string; teamId: string; diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 5f0472229..8986f1a12 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -6,6 +6,7 @@ import { redirect } from '@sveltejs/kit'; import { Dependencies } from '$lib/constants'; import type { LayoutLoad } from './$types'; import { redirectTo } from './store'; +import { isCloud } from '$lib/system'; export const ssr = false; @@ -22,7 +23,7 @@ export const load: LayoutLoad = async ({ depends, url }) => { return { account, - organizations: await sdk.forConsole.billing.listOrganization() + organizations: isCloud ? await sdk.forConsole.billing.listOrganization() : await sdk.forConsole.teams.list() }; } catch (error) { const acceptedRoutes = [ diff --git a/src/routes/console/account/organizations/+page.ts b/src/routes/console/account/organizations/+page.ts index 3f21115b8..803497c6a 100644 --- a/src/routes/console/account/organizations/+page.ts +++ b/src/routes/console/account/organizations/+page.ts @@ -3,19 +3,24 @@ import { sdk } from '$lib/stores/sdk'; import { getLimit, getPage, pageToOffset } from '$lib/helpers/load'; import { CARD_LIMIT } from '$lib/constants'; import type { PageLoad } from './$types'; +import { isCloud } from '$lib/system'; export const load: PageLoad = async ({ url, route }) => { const page = getPage(url); const limit = getLimit(url, route, CARD_LIMIT); const offset = pageToOffset(page, limit); + const queries = [ + Query.offset(offset), + Query.limit(limit), + Query.orderDesc('') + ]; + + const organizations = isCloud ? await sdk.forConsole.billing.listOrganization(queries) : sdk.forConsole.teams.list(queries); + return { offset, limit, - organizations: await sdk.forConsole.billing.listOrganization([ - Query.offset(offset), - Query.limit(limit), - Query.orderDesc('') - ]) + organizations }; }; diff --git a/src/routes/console/create-organization/+page.svelte b/src/routes/console/create-organization/+page.svelte index 67d1341f1..323d48c61 100644 --- a/src/routes/console/create-organization/+page.svelte +++ b/src/routes/console/create-organization/+page.svelte @@ -24,7 +24,7 @@ import { addNotification } from '$lib/stores/notifications'; import { organizationList, - type CreateOrgAuth, + type OrganizationError, type Organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; @@ -88,10 +88,10 @@ if (anyOrgFree) { billingPlan = BillingPlan.PRO; } - if($page.url.searchParams.has('type')) { + if ($page.url.searchParams.has('type')) { const type = $page.url.searchParams.get('type'); - if(type === 'confirmed') { - const organizationId= $page.url.searchParams.get('id'); + if (type === 'confirmed') { + const organizationId = $page.url.searchParams.get('id'); const invites = $page.url.searchParams.getAll('invites'); await validate(organizationId, invites); } @@ -103,7 +103,7 @@ paymentMethodId = methods.paymentMethods.find((method) => !!method?.last4)?.$id ?? null; } - function isOrganization(org: Organization | CreateOrgAuth): org is Organization { + function isOrganization(org: Organization | OrganizationError): org is Organization { return (org as Organization).$id !== undefined; } @@ -125,12 +125,11 @@ }); trackError(e, Submit.OrganizationCreate); } - } async function create() { try { - let org: Organization | CreateOrgAuth; + let org: Organization | OrganizationError; if (billingPlan === BillingPlan.FREE) { org = await sdk.forConsole.billing.createOrganization( @@ -162,39 +161,14 @@ const invite = collaborators[index]; params.append('invites', invite); } - await confirmPayment('', clientSecret, paymentMethodId, '/console/create-organization?'+params.toString()); + await confirmPayment( + '', + clientSecret, + paymentMethodId, + '/console/create-organization?' + params.toString() + ); await validate(org.teamId, collaborators); } - - //Add budget - // if (billingBudget && isOrganization(org)) { - // await sdk.forConsole.billing.updateBudget(org.$id, billingBudget, [75]); - // } - - // //Add coupon - // if (couponData?.code) { - // await sdk.forConsole.billing.addCredit(org.$id, couponData.code); - // trackEvent(Submit.CreditRedeem); - // } - - // //Add collaborators - // if (collaborators?.length) { - // collaborators.forEach(async (collaborator) => { - // await sdk.forConsole.teams.createMembership( - // org.$id, - // ['owner'], - // collaborator, - // undefined, - // undefined, - // `${$page.url.origin}/console/organization-${org.$id}` - // ); - // }); - // } - - // Add tax ID - // if (taxId) { - // await sdk.forConsole.billing.updateTaxId(org.$id, taxId); - // } } trackEvent(Submit.OrganizationCreate, { @@ -203,7 +177,7 @@ members_invited: collaborators?.length }); - if(isOrganization(org)) { + if (isOrganization(org)) { await invalidate(Dependencies.ACCOUNT); await preloadData(`${base}/console/organization-${org.$id}`); await goto(`${base}/console/organization-${org.$id}`);