|
13 | 13 | import { sdk } from '$lib/stores/sdk'; |
14 | 14 | import type { PageData } from './$types'; |
15 | 15 | import { isCloud } from '$lib/system'; |
16 | | - import { Badge } from '@appwrite.io/pink-svelte'; |
| 16 | + import { Badge, Skeleton } from '@appwrite.io/pink-svelte'; |
17 | 17 | import type { Models } from '@appwrite.io/console'; |
18 | 18 | import type { Organization } from '$lib/stores/organization'; |
19 | | - import { daysLeftInTrial, plansInfo, tierToPlan } from '$lib/stores/billing'; |
| 19 | + import { daysLeftInTrial, plansInfo, tierToPlan, type Tier } from '$lib/stores/billing'; |
20 | 20 | import { toLocaleDate } from '$lib/helpers/date'; |
21 | 21 | import { BillingPlan } from '$lib/constants'; |
22 | 22 | import { goto } from '$app/navigation'; |
|
36 | 36 | return memberships.memberships.map((team) => team.userName || team.userEmail); |
37 | 37 | } |
38 | 38 |
|
| 39 | + async function getPlanName(billingPlan: string | undefined): Promise<string> { |
| 40 | + if (!billingPlan) return 'Unknown'; |
| 41 | +
|
| 42 | + // For known plans, use tierToPlan |
| 43 | + const tierData = tierToPlan(billingPlan as Tier); |
| 44 | +
|
| 45 | + // If it's not a custom plan or we got a non-custom result, return the name |
| 46 | + if (tierData.name !== 'Custom') { |
| 47 | + return tierData.name; |
| 48 | + } |
| 49 | +
|
| 50 | + // For custom plans, fetch from API |
| 51 | + try { |
| 52 | + const plan = await sdk.forConsole.billing.getPlan(billingPlan); |
| 53 | + return plan.name; |
| 54 | + } catch (error) { |
| 55 | + // Fallback to 'Custom' if fetch fails |
| 56 | + return 'Custom'; |
| 57 | + } |
| 58 | + } |
| 59 | +
|
39 | 60 | function isOrganizationOnTrial(organization: Organization): boolean { |
40 | 61 | if (!organization?.billingTrialStartDate) return false; |
41 | 62 | if ($daysLeftInTrial <= 0) return false; |
|
92 | 113 | {#each data.organizations.teams as organization} |
93 | 114 | {@const avatarList = getMemberships(organization.$id)} |
94 | 115 | {@const payingOrg = isPayingOrganization(organization)} |
| 116 | + {@const planName = isCloudOrg(organization) |
| 117 | + ? getPlanName(organization.billingPlan) |
| 118 | + : null} |
95 | 119 |
|
96 | 120 | <GridItem1 href={`${base}/organization-${organization.$id}`}> |
97 | 121 | <svelte:fragment slot="eyebrow"> |
|
104 | 128 | <svelte:fragment slot="status"> |
105 | 129 | {#if isCloudOrg(organization)} |
106 | 130 | {#if isNonPayingOrganization(organization)} |
107 | | - <Tooltip> |
108 | | - <Badge |
109 | | - size="xs" |
110 | | - variant="secondary" |
111 | | - content={tierToPlan(organization?.billingPlan)?.name} /> |
112 | | - |
113 | | - <span slot="tooltip"> |
114 | | - You are limited to 1 free organization per account |
115 | | - </span> |
116 | | - </Tooltip> |
| 131 | + {#if planName} |
| 132 | + {#await planName} |
| 133 | + <Skeleton width={30} height={20} variant="line" /> |
| 134 | + {:then name} |
| 135 | + <Tooltip> |
| 136 | + <Badge size="xs" variant="secondary" content={name} /> |
| 137 | + |
| 138 | + <span slot="tooltip"> |
| 139 | + You are limited to 1 free organization per account |
| 140 | + </span> |
| 141 | + </Tooltip> |
| 142 | + {/await} |
| 143 | + {/if} |
117 | 144 | {/if} |
118 | 145 |
|
119 | 146 | {#if isOrganizationOnTrial(organization)} |
|
132 | 159 | {/if} |
133 | 160 |
|
134 | 161 | {#if payingOrg} |
135 | | - <Badge |
136 | | - size="xs" |
137 | | - type="success" |
138 | | - variant="secondary" |
139 | | - content={tierToPlan(payingOrg?.billingPlan)?.name} /> |
| 162 | + {#await planName} |
| 163 | + <Skeleton width={30} height={20} variant="line" /> |
| 164 | + {:then name} |
| 165 | + <Badge |
| 166 | + size="xs" |
| 167 | + type="success" |
| 168 | + variant="secondary" |
| 169 | + content={name} /> |
| 170 | + {/await} |
140 | 171 | {/if} |
141 | 172 | {/if} |
142 | 173 | </svelte:fragment> |
143 | 174 | {#await avatarList} |
144 | | - <span class="avatar is-color-empty"></span> |
| 175 | + <Skeleton width={40} height={40} variant="circle" /> |
145 | 176 | {:then avatars} |
146 | 177 | <AvatarGroup {avatars} /> |
147 | 178 | {/await} |
|
0 commit comments