Skip to content

Commit 213a54e

Browse files
committed
fix
1 parent 6110c0c commit 213a54e

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

src/lib/stores/billing.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,40 +78,60 @@ export const showBudgetAlert = derived(
7878
);
7979

8080
function getPlansInfoStore(): BillingPlansMap | null {
81-
return get(plansInfo) ?? get(page).data?.plansInfo ?? null;
81+
return get(plansInfo) ?? get(page).data?.plansInfo ?? new Map();
8282
}
8383

84-
function makeBillingPlan(billingPlanOrId: string | Models.BillingPlan): Models.BillingPlan {
84+
function makeBillingPlan(
85+
billingPlanOrId: string | Models.BillingPlan | null | undefined
86+
): Models.BillingPlan | null {
87+
if (!billingPlanOrId) {
88+
return null;
89+
}
90+
8591
return typeof billingPlanOrId === 'string' ? billingIdToPlan(billingPlanOrId) : billingPlanOrId;
8692
}
8793

8894
export function getRoleLabel(role: string) {
8995
return roles.find((r) => r.value === role)?.label ?? role;
9096
}
9197

92-
export function isStarterPlan(billingPlanOrId: string | Models.BillingPlan): boolean {
98+
export function isStarterPlan(
99+
billingPlanOrId: string | Models.BillingPlan | null | undefined
100+
): boolean {
93101
const billingPlan = makeBillingPlan(billingPlanOrId);
94102
return planHasGroup(billingPlan, BillingPlanGroup.Starter);
95103
}
96104

97-
export function canUpgrade(billingPlanOrId: string | Models.BillingPlan): boolean {
105+
export function canUpgrade(
106+
billingPlanOrId: string | Models.BillingPlan | null | undefined
107+
): boolean {
98108
const billingPlan = makeBillingPlan(billingPlanOrId);
109+
if (!billingPlan?.$id) {
110+
return false;
111+
}
112+
99113
const nextTier = getNextTierBillingPlan(billingPlan.$id);
100114

101115
// defaults back to PRO, so adjust the check!
102116
return billingPlan.$id !== nextTier.$id;
103117
}
104118

105-
export function canDowngrade(billingPlanOrId: string | Models.BillingPlan): boolean {
119+
export function canDowngrade(
120+
billingPlanOrId: string | Models.BillingPlan | null | undefined
121+
): boolean {
106122
const billingPlan = makeBillingPlan(billingPlanOrId);
123+
if (!billingPlan?.$id) {
124+
return false;
125+
}
126+
107127
const nextTier = getPreviousTierBillingPlan(billingPlan.$id);
108128

109129
// defaults back to Starter, so adjust the check!
110130
return billingPlan.$id !== nextTier.$id;
111131
}
112132

113133
export function planHasGroup(
114-
billingPlanOrId: string | Models.BillingPlan,
134+
billingPlanOrId: string | Models.BillingPlan | null | undefined,
115135
group: BillingPlanGroup
116136
): boolean {
117137
const billingPlan = makeBillingPlan(billingPlanOrId);
@@ -567,6 +587,9 @@ export function checkForMarkedForDeletion(org: Models.Organization) {
567587

568588
export async function checkForMissingPaymentMethod() {
569589
const starterPlan = getBasePlanFromGroup(BillingPlanGroup.Starter);
590+
if (!starterPlan?.$id) {
591+
return;
592+
}
570593

571594
const orgs = await sdk.forConsole.organizations.list({
572595
queries: [

src/routes/+layout.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export const load: LayoutLoad = async ({ depends, url, route }) => {
3939
if (account) {
4040
// `/v1/teams` (and org list on cloud) returns 401 until the console account is verified;
4141
// do not call that API on this route while still unverified.
42-
if (url.pathname === verifyEmailPath && !account.emailVerification) {
43-
const plansInfo = await getPlatformPlans();
42+
if (url.pathname === verifyEmailPath) {
43+
const plansInfo = await getPlatformPlans().catch(() => null);
4444
plansInfoStore.set(plansInfo);
4545
return {
4646
plansInfo,
@@ -69,7 +69,7 @@ export const load: LayoutLoad = async ({ depends, url, route }) => {
6969
}
7070

7171
// Already on verify-email: do not rethrow; the teams API is blocked until verified.
72-
const plansInfo = await getPlatformPlans();
72+
const plansInfo = await getPlatformPlans().catch(() => null);
7373
plansInfoStore.set(plansInfo);
7474
return {
7575
plansInfo,

0 commit comments

Comments
 (0)