Skip to content

Commit 3c2c49b

Browse files
authored
Merge pull request #2043 from appwrite/fix-education-plan-crash
2 parents b1a5d77 + 19f23c0 commit 3c2c49b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/lib/stores/billing.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ export async function checkForUsageLimit(org: Organization) {
357357
const members = org.total;
358358
const plan = get(currentPlan);
359359
const membersOverflow =
360-
members > plan.addons.seats.limit ? members - (plan.addons.seats.limit || members) : 0;
360+
// nested null checks needed: GitHub Education plan have empty addons.
361+
members > plan.addons.seats?.limit ? members - (plan.addons.seats?.limit || members) : 0;
361362

362363
if (resources.some((r) => r.value >= 100) || membersOverflow > 0) {
363364
readOnly.set(true);

src/routes/(console)/project-[region]-[project]/+layout.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@ export const load: LayoutLoad = async ({ params, depends, parent }) => {
2222
(org) => org.$id === project.teamId
2323
);
2424

25-
const [org, regionalConsoleVariables, rolesResult] = await Promise.all([
25+
const includedInBasePlans = plansInfo.has(organization.billingPlan);
26+
27+
const [org, regionalConsoleVariables, rolesResult, organizationPlan] = await Promise.all([
2628
!organization
2729
? (sdk.forConsole.teams.get(project.teamId) as Promise<Organization>)
2830
: organization,
2931
sdk.forConsoleIn(project.region).console.variables(),
3032
isCloud ? sdk.forConsole.billing.getRoles(project.teamId) : null,
33+
34+
// fetch if not available in `plansInfo`
35+
includedInBasePlans
36+
? plansInfo.get(organization.billingPlan)
37+
: sdk.forConsole.billing.getOrganizationPlan(organization.$id),
38+
3139
loadAvailableRegions(project.teamId)
3240
]);
3341

@@ -49,13 +57,18 @@ export const load: LayoutLoad = async ({ params, depends, parent }) => {
4957
loadFailedInvoices(project.teamId);
5058
}
5159

60+
if (!includedInBasePlans) {
61+
// save the custom plan to `plansInfo` cache.
62+
plansInfo.set(organization.billingPlan, organizationPlan);
63+
}
64+
5265
return {
5366
project,
5467
organization,
5568
regionalConsoleVariables,
5669
roles,
5770
scopes,
58-
currentPlan: plansInfo.get(organization.billingPlan)
71+
currentPlan: organizationPlan
5972
};
6073
};
6174

0 commit comments

Comments
 (0)