add: backup banner alert.

This commit is contained in:
ItzNotABug
2024-09-06 12:06:36 +05:30
parent 30bedb07b3
commit 9a35a2a2b9
4 changed files with 67 additions and 0 deletions
@@ -0,0 +1,28 @@
<script lang="ts">
import { page } from '$app/stores';
import { BillingPlan } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import { organization } from '$lib/stores/organization';
import { HeaderAlert } from '$lib/layout';
import { isCloud } from '$lib/system.js';
import { upgradeURL } from '$lib/stores/billing';
const isFreePlan = $organization?.billingPlan === BillingPlan.FREE;
const subtitle = isFreePlan
? 'Upgrade your plan to ensure your data stays safe with advanced backup policies'
: 'Protect your data by quickly adding a backup policy';
const ctaText = isFreePlan ? 'Upgrade plan' : 'Add backup';
const ctaURL = isFreePlan ? $upgradeURL : `${$page.url.pathname}/backups`;
</script>
{#if isCloud && $organization?.$id && $page.url.pathname.match(/\/databases\/database-[^/]+$/)}
<HeaderAlert type="warning" title="Your database is not backed up">
<svelte:fragment>{subtitle}</svelte:fragment>
<svelte:fragment slot="buttons">
<Button href={ctaURL} secondary fullWidthMobile>
<span class="text">{ctaText}</span>
</Button>
</svelte:fragment>
</HeaderAlert>
{/if}
+31
View File
@@ -0,0 +1,31 @@
import { derived } from 'svelte/store';
import { page } from '$app/stores';
import { type Models, Query } from '@appwrite.io/console';
import { sdk } from '$lib/stores/sdk';
import { headerAlert } from '$lib/stores/headerAlert';
import BackupDatabase from '$lib/components/billing/alerts/backupDatabase.svelte';
export const database = derived(page, ($page) => $page.data?.database as Models.Database);
export async function checkForDatabaseBackupPolicies(database: Models.Database) {
let total = 0;
try {
const policies = await sdk.forConsole.backups.listPolicies([
Query.limit(1),
Query.equal('resourceId', database.$id)
]);
total = policies.total;
} catch (e) {
// ignore, backups not allowed on free plan error.
}
if (!total) {
headerAlert.add({
id: 'databasesBackup',
component: BackupDatabase,
show: true,
importance: 7
});
}
}
+1
View File
@@ -71,6 +71,7 @@ export const sdk = {
client: clientConsole,
account: new Account(clientConsole),
avatars: new Avatars(clientConsole),
backups: new Backups(clientConsole),
functions: new Functions(clientConsole),
health: new Health(clientConsole),
locale: new Locale(clientConsole),
+7
View File
@@ -9,6 +9,7 @@
import { app } from '$lib/stores/app';
import { log } from '$lib/stores/logs';
import { newOrgModal, organization } from '$lib/stores/organization';
import { database, checkForDatabaseBackupPolicies } from '$lib/stores/database';
import { wizard } from '$lib/stores/wizard';
import { afterUpdate, onMount } from 'svelte';
import { loading } from '$routes/store';
@@ -265,6 +266,12 @@
}
}
database.subscribe(async (database) => {
if (!database) return;
// the component checks `isCloud` internally.
await checkForDatabaseBackupPolicies(database);
});
organization.subscribe(async (org) => {
if (!org) return;
if (isCloud) {