fix: budget alerts

This commit is contained in:
Arman
2023-07-26 17:58:10 +02:00
parent cb19a50515
commit ed7a4e0868
3 changed files with 7 additions and 8 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import type { Models } from '@appwrite.io/console';
export type Organization = Models.Team<Record<string, unknown>> & {
billingBudget: number;
billingPlan: string;
budgetAlert: number[];
budgetAlerts: number[];
paymentMethodId: string;
backupPaymentMethodId: string;
billingCurrentInvoiceDate: string;
@@ -33,14 +33,14 @@
];
onMount(() => {
alerts = $organization?.budgetAlert ?? [];
alerts = $organization?.budgetAlerts ?? [];
});
function addAlert() {
if (alerts.some((alert) => alert === selectedAlert)) {
return;
}
if (alerts.length < 2) {
if (alerts.length <= 2) {
alerts = [...alerts, selectedAlert ? selectedAlert : parseInt(search)];
search = '';
selectedAlert = null;
@@ -54,6 +54,7 @@
$organization.billingBudget,
alerts
);
invalidate(Dependencies.ORGANIZATION);
addNotification({
@@ -72,9 +73,7 @@
}
}
$: isButtonDisabled = symmetricDifference(alerts, $organization.budgetAlert).length === 0;
$: console.log($organization.budgetAlert, alerts);
$: isButtonDisabled = symmetricDifference(alerts, $organization.budgetAlerts).length === 0;
</script>
<Form onSubmit={updateBudget}>
@@ -111,7 +110,7 @@
<TableCellHead width={30} />
</TableHeader>
<TableBody>
{#each alerts as alert}
{#each alerts.sort() as alert}
<TableRow>
<TableCellText title="Percentage">
{alert}%
@@ -24,7 +24,7 @@
await sdk.forConsole.billing.updateBudget(
$organization.$id,
budget,
$organization.budgetAlert
$organization.budgetAlerts
);
invalidate(Dependencies.ORGANIZATION);
addNotification({