diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 46134dde33..db5e28f6b4 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -100,7 +100,7 @@ export function tierToPlan(tier: Tier) { case BillingPlan.ENTERPRISE: return tierEnterprise; default: - return tierFree; + return tierCustom; } } diff --git a/src/routes/(console)/account/organizations/+page.svelte b/src/routes/(console)/account/organizations/+page.svelte index a08500bb7d..2d16680439 100644 --- a/src/routes/(console)/account/organizations/+page.svelte +++ b/src/routes/(console)/account/organizations/+page.svelte @@ -13,10 +13,10 @@ import { sdk } from '$lib/stores/sdk'; import type { PageData } from './$types'; import { isCloud } from '$lib/system'; - import { Badge } from '@appwrite.io/pink-svelte'; + import { Badge, Skeleton } from '@appwrite.io/pink-svelte'; import type { Models } from '@appwrite.io/console'; import type { Organization } from '$lib/stores/organization'; - import { daysLeftInTrial, plansInfo, tierToPlan } from '$lib/stores/billing'; + import { daysLeftInTrial, plansInfo, tierToPlan, type Tier } from '$lib/stores/billing'; import { toLocaleDate } from '$lib/helpers/date'; import { BillingPlan } from '$lib/constants'; import { goto } from '$app/navigation'; @@ -36,6 +36,27 @@ return memberships.memberships.map((team) => team.userName || team.userEmail); } + async function getPlanName(billingPlan: string | undefined): Promise { + if (!billingPlan) return 'Unknown'; + + // For known plans, use tierToPlan + const tierData = tierToPlan(billingPlan as Tier); + + // If it's not a custom plan or we got a non-custom result, return the name + if (tierData.name !== 'Custom') { + return tierData.name; + } + + // For custom plans, fetch from API + try { + const plan = await sdk.forConsole.billing.getPlan(billingPlan); + return plan.name; + } catch (error) { + // Fallback to 'Custom' if fetch fails + return 'Custom'; + } + } + function isOrganizationOnTrial(organization: Organization): boolean { if (!organization?.billingTrialStartDate) return false; if ($daysLeftInTrial <= 0) return false; @@ -92,6 +113,9 @@ {#each data.organizations.teams as organization} {@const avatarList = getMemberships(organization.$id)} {@const payingOrg = isPayingOrganization(organization)} + {@const planName = isCloudOrg(organization) + ? getPlanName(organization.billingPlan) + : null} @@ -104,16 +128,19 @@ {#if isCloudOrg(organization)} {#if isNonPayingOrganization(organization)} - - - - - You are limited to 1 free organization per account - - + {#if planName} + {#await planName} + + {:then name} + + + + + You are limited to 1 free organization per account + + + {/await} + {/if} {/if} {#if isOrganizationOnTrial(organization)} @@ -132,16 +159,20 @@ {/if} {#if payingOrg} - + {#await planName} + + {:then name} + + {/await} {/if} {/if} {#await avatarList} - + {:then avatars} {/await}