Skip to content

Commit 0e921a6

Browse files
committed
update: better params for short-circuiting.
1 parent a8ea415 commit 0e921a6

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

src/lib/stores/billing.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,21 @@ export function checkForProjectLimitation(plan: string, id: PlanServices) {
300300
}
301301
}
302302

303-
export function isServiceLimited(serviceId: PlanServices, plan: string, total: number) {
303+
export function isServiceLimited(
304+
serviceId: PlanServices,
305+
organization: Models.Organization,
306+
total: number
307+
) {
308+
// total validity
304309
if (!total) return false;
305-
if (!plan) return false;
310+
311+
// org and plan validity!
312+
if (!organization) return false;
313+
if (!('billingPlanId' in organization)) return false;
314+
306315
const limit = getServiceLimit(serviceId) || Infinity;
307316
const isLimited = limit !== 0 && limit < Infinity;
308-
const hasUsageFees = checkForUsageFees(plan, serviceId);
317+
const hasUsageFees = checkForUsageFees(organization.billingPlanId, serviceId);
309318
return isLimited && total >= limit && !hasUsageFees;
310319
}
311320

src/routes/(console)/project-[region]-[project]/databases/+page.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
2626
let showCreate = $state(false);
2727
28-
const isLimited = $derived(
29-
isServiceLimited('databases', $organization?.billingPlanId, data.databases.total)
30-
);
28+
const isLimited = $derived(isServiceLimited('databases', $organization, data.databases.total));
3129
3230
async function handleCreate(event: CustomEvent<Models.Database>) {
3331
showCreate = false;

src/routes/(console)/project-[region]-[project]/functions/+page.svelte

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@
6868
keys: ['c'],
6969
disabled:
7070
$wizard.show ||
71-
isServiceLimited(
72-
'functions',
73-
$organization?.billingPlanId,
74-
data.functions?.total
75-
) ||
71+
isServiceLimited('functions', $organization, data.functions?.total) ||
7672
!$canWriteFunctions,
7773
icon: IconPlus,
7874
group: 'functions'

src/routes/(console)/project-[region]-[project]/functions/templates/+page.svelte

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@
7979
.some((param) => param.toLowerCase() === useCase.toLowerCase());
8080
};
8181
82-
$: buttonDisabled = isServiceLimited(
83-
'functions',
84-
$organization?.billingPlanId,
85-
$functionsList?.total ?? 0
86-
);
82+
$: buttonDisabled = isServiceLimited('functions', $organization, $functionsList?.total ?? 0);
8783
</script>
8884

8985
<Container>

src/routes/(console)/project-[region]-[project]/functions/templates/template-[template]/+page.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
import { IconExternalLink } from '@appwrite.io/pink-icons-svelte';
2727
2828
$: buttonDisabled =
29-
isCloud &&
30-
isServiceLimited('functions', $organization?.billingPlanId, $functionsList?.total);
29+
isCloud && isServiceLimited('functions', $organization, $functionsList?.total);
3130
</script>
3231

3332
<Container>

src/routes/(console)/project-[region]-[project]/sites/+page.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
},
4141
keys: ['c'],
4242
disabled:
43-
isServiceLimited('sites', $organization?.billingPlanId, data.siteList?.total) ||
44-
!$canWriteSites,
43+
isServiceLimited('sites', $organization, data.siteList?.total) || !$canWriteSites,
4544
icon: IconPlus,
4645
group: 'sites'
4746
}

0 commit comments

Comments
 (0)