diff --git a/src/lib/components/heading.svelte b/src/lib/components/heading.svelte index 9ef0315f6..a8ce04948 100644 --- a/src/lib/components/heading.svelte +++ b/src/lib/components/heading.svelte @@ -21,3 +21,10 @@ {id}> + + diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index dd698c912..3923ce250 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -32,6 +32,7 @@ import { organization, type Organization, type OrganizationError } from './organ import { canSeeBilling } from './roles'; import { sdk } from './sdk'; import { user } from './user'; +import BudgetLimitAlert from '$routes/(console)/organization-[organization]/budgetLimitAlert.svelte'; export type Tier = 'tier-0' | 'tier-1' | 'tier-2' | 'auto-1' | 'cont-1' | 'ent-1'; @@ -64,6 +65,11 @@ export const plansInfo = derived(page, ($page) => $page.data.plansInfo as PlansM export const daysLeftInTrial = writable(0); export const readOnly = writable(false); +export const showBudgetAlert = derived( + page, + ($page) => ($page.data.organization?.billingLimits.budgetLimit ?? 0) >= 100 +); + export function getRoleLabel(role: string) { return roles.find((r) => r.value === role)?.label ?? role; } @@ -264,12 +270,26 @@ export function calculateTrialDay(org: Organization) { } export async function checkForUsageLimit(org: Organization) { - if (org?.billingPlan !== BillingPlan.FREE) { + if (!org?.billingLimits) { readOnly.set(false); return; } - if (!org?.billingLimits) { - readOnly.set(false); + if (org?.billingPlan !== BillingPlan.FREE) { + const { budgetLimit } = org?.billingLimits ?? {}; + + if (!budgetLimit || budgetLimit < 100) { + readOnly.set(false); + return; + } + + headerAlert.add({ + id: 'budgetLimit', + component: BudgetLimitAlert, + show: true, + importance: 10 + }); + + readOnly.set(true); return; } const { bandwidth, documents, executions, storage, users } = org?.billingLimits ?? {}; diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index dcfd0a562..3f02fe50a 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -45,6 +45,7 @@ export type BillingLimits = { executions: number; storage: number; users: number; + budgetLimit: number; }; export const newOrgModal = writable(false); diff --git a/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte b/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte index df6a7e84a..479886016 100644 --- a/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte +++ b/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte @@ -26,7 +26,7 @@ budget, $organization.budgetAlerts ); - invalidate(Dependencies.ORGANIZATION); + await invalidate(Dependencies.ORGANIZATION); addNotification({ type: 'success', isHtml: true, @@ -51,7 +51,7 @@
- Budget cap + Budget cap

Restrict your resource usage by setting a budget cap. Cap usage is reset at the diff --git a/src/routes/(console)/organization-[organization]/budgetLimitAlert.svelte b/src/routes/(console)/organization-[organization]/budgetLimitAlert.svelte new file mode 100644 index 000000000..2d1e25a46 --- /dev/null +++ b/src/routes/(console)/organization-[organization]/budgetLimitAlert.svelte @@ -0,0 +1,28 @@ + + +{#if $showBudgetAlert && $organization?.$id && $organization?.billingPlan !== BillingPlan.FREE && $readOnly && !hideBillingHeaderRoutes.includes($page.url.pathname)} + + + This organization has reached its budget limit and is now blocked. To continue using + Appwrite services, update the budget limit. + + + + + + +{/if}