-
Notifications
You must be signed in to change notification settings - Fork 198
Fix custom plan names displaying as "Custom" on account organizations page #2545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
667c92e
9b4ef58
56052dd
17c1d1f
b445fad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
| import { Badge } 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<string> { | ||
| 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} | ||
|
|
||
| <GridItem1 href={`${base}/organization-${organization.$id}`}> | ||
| <svelte:fragment slot="eyebrow"> | ||
|
|
@@ -104,16 +128,17 @@ | |
| <svelte:fragment slot="status"> | ||
| {#if isCloudOrg(organization)} | ||
| {#if isNonPayingOrganization(organization)} | ||
| <Tooltip> | ||
| <Badge | ||
| size="xs" | ||
| variant="secondary" | ||
| content={tierToPlan(organization?.billingPlan)?.name} /> | ||
|
|
||
| <span slot="tooltip"> | ||
| You are limited to 1 free organization per account | ||
| </span> | ||
| </Tooltip> | ||
| {#if planName} | ||
| {#await planName then name} | ||
|
||
| <Tooltip> | ||
| <Badge size="xs" variant="secondary" content={name} /> | ||
|
|
||
| <span slot="tooltip"> | ||
| You are limited to 1 free organization per account | ||
| </span> | ||
| </Tooltip> | ||
| {/await} | ||
| {/if} | ||
| {/if} | ||
|
|
||
| {#if isOrganizationOnTrial(organization)} | ||
|
|
@@ -132,11 +157,13 @@ | |
| {/if} | ||
|
|
||
| {#if payingOrg} | ||
| <Badge | ||
| size="xs" | ||
| type="success" | ||
| variant="secondary" | ||
| content={tierToPlan(payingOrg?.billingPlan)?.name} /> | ||
| {#await getPlanName(payingOrg.billingPlan) then name} | ||
| <Badge | ||
| size="xs" | ||
| type="success" | ||
| variant="secondary" | ||
| content={name} /> | ||
| {/await} | ||
|
||
| {/if} | ||
| {/if} | ||
| </svelte:fragment> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do a quick cached data lookup first to avoid a network call, there should be a
plansInfoavailable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ItzNotABug
tierToPlanessentially has the same data asplansInfo, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant we can avoid the
getPlanAPI call if theplansInfoalready has the details needed, which in most cases should be available.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, were only calling getPlan when the plan info is unknown.