From 9bdaa4caaf5b55085ee83b29d0369d45e87e6c4a Mon Sep 17 00:00:00 2001 From: Arman Date: Mon, 9 Oct 2023 19:48:41 +0200 Subject: [PATCH] feat: readOnly, plan limits, fixes --- src/lib/elements/forms/inputChoice.svelte | 1 + src/lib/helpers/numbers.ts | 12 +++ src/lib/layout/containerHeader.svelte | 5 +- src/lib/stores/billing.ts | 1 + src/routes/console/+layout.svelte | 5 ++ src/routes/console/+page.ts | 2 - .../organization-[organization]/+page.svelte | 3 +- .../members/+page.svelte | 4 +- .../overview/platforms/+page.svelte | 5 +- .../settings/migrations/+page.svelte | 9 +- .../storage/bucket-[bucket]/+page.svelte | 6 +- .../bucket-[bucket]/settings/+page.svelte | 90 ++++++++----------- .../settings/updateMaxFileSize.svelte | 6 +- .../cloudOrganization/usageRates.svelte | 38 +++++--- 14 files changed, 108 insertions(+), 79 deletions(-) create mode 100644 src/lib/helpers/numbers.ts diff --git a/src/lib/elements/forms/inputChoice.svelte b/src/lib/elements/forms/inputChoice.svelte index b8d5215be..a76182a9b 100644 --- a/src/lib/elements/forms/inputChoice.svelte +++ b/src/lib/elements/forms/inputChoice.svelte @@ -35,6 +35,7 @@ {required} type="checkbox" class:switch={type === 'switchbox'} + aria-checked={value} bind:this={element} bind:checked={value} on:invalid={handleInvalid} /> diff --git a/src/lib/helpers/numbers.ts b/src/lib/helpers/numbers.ts new file mode 100644 index 000000000..8e0b53097 --- /dev/null +++ b/src/lib/helpers/numbers.ts @@ -0,0 +1,12 @@ +export function abbreviateNumber(num: number, decimals: number = 1): string { + if (isNaN(num)) return String(num); + if (num >= 1000000) { + const result = num / 1000000; + return result.toFixed(result % 1 !== 0 ? decimals : 0) + 'M'; + } else if (num >= 1000) { + const result = num / 1000; + return result.toFixed(result % 1 !== 0 ? decimals : 0) + 'K'; + } else { + return num.toString(); + } +} diff --git a/src/lib/layout/containerHeader.svelte b/src/lib/layout/containerHeader.svelte index b8084a545..4fd58c2f1 100644 --- a/src/lib/layout/containerHeader.svelte +++ b/src/lib/layout/containerHeader.svelte @@ -20,10 +20,11 @@ export let buttonText: string = null; export let buttonMethod: () => void = null; export let buttonEvent: string = buttonText?.toLocaleLowerCase(); + export let buttonDisabled = false; let tooltipContent: HTMLDivElement; - const limit = getServiceLimit(serviceId)?.amount ?? Infinity; + const limit = getServiceLimit(serviceId) || Infinity; $: tier = tierToPlan($organization?.billingPlan as Tier)?.name; @@ -76,7 +77,7 @@ diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 4152ef030..ddf900bdb 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -13,6 +13,7 @@ export const addressList = derived(page, ($page) => $page.data.addressList as Ad export const plansInfo = derived(page, ($page) => $page.data.plansInfo as PlansInfo); export const daysLeftInTrial = writable(0); export const trialEndDate = writable(); +export const readOnly = writable(false); export function tierToPlan(tier: Tier) { switch (tier) { diff --git a/src/routes/console/+layout.svelte b/src/routes/console/+layout.svelte index 02140973f..f8f2b02c0 100644 --- a/src/routes/console/+layout.svelte +++ b/src/routes/console/+layout.svelte @@ -259,6 +259,7 @@ checkForTrialEnding(); paymentExpired(); + checkForUsageLimit(); } }); @@ -286,6 +287,10 @@ } } + function checkForUsageLimit() { + console.log('test'); + } + async function paymentExpired() { if (!$organization?.paymentMethodId) return; const payment = await sdk.forConsole.billing.getPaymentMethod( diff --git a/src/routes/console/+page.ts b/src/routes/console/+page.ts index bf3f287c3..d3738605b 100644 --- a/src/routes/console/+page.ts +++ b/src/routes/console/+page.ts @@ -4,8 +4,6 @@ import type { PageLoad } from './$types'; export const load: PageLoad = async ({ parent }) => { const { organizations } = await parent(); - console.log(organizations); - console.log('test'); if (organizations.total) { const teamId = localStorage.getItem('organization') ?? organizations.teams[0].$id; throw redirect(303, `${base}/console/organization-${teamId}`); diff --git a/src/routes/console/organization-[organization]/+page.svelte b/src/routes/console/organization-[organization]/+page.svelte index 26f23aa1e..53a1ed7b5 100644 --- a/src/routes/console/organization-[organization]/+page.svelte +++ b/src/routes/console/organization-[organization]/+page.svelte @@ -27,6 +27,7 @@ import type { Models } from '@appwrite.io/console'; import { ID } from '@appwrite.io/console'; import { openImportWizard } from '../project-[project]/settings/migrations/(import)'; + import { readOnly } from '$lib/stores/billing'; export let data; @@ -119,7 +120,7 @@ Projects - diff --git a/src/routes/console/organization-[organization]/members/+page.svelte b/src/routes/console/organization-[organization]/members/+page.svelte index 2d8ebeeb3..b70a684f6 100644 --- a/src/routes/console/organization-[organization]/members/+page.svelte +++ b/src/routes/console/organization-[organization]/members/+page.svelte @@ -22,6 +22,7 @@ import type { Models } from '@appwrite.io/console'; import type { PageData } from './$types'; import Delete from '../deleteMember.svelte'; + import { readOnly } from '$lib/stores/billing'; export let data: PageData; @@ -61,7 +62,8 @@ title="Members" total={data.organizationMembers.total} buttonText="Invite" - buttonMethod={() => newMemberModal.set(true)} /> + buttonMethod={() => newMemberModal.set(true)} + buttonDisabled={$readOnly} /> diff --git a/src/routes/console/project-[project]/overview/platforms/+page.svelte b/src/routes/console/project-[project]/overview/platforms/+page.svelte index 8da591f8c..24d6f4304 100644 --- a/src/routes/console/project-[project]/overview/platforms/+page.svelte +++ b/src/routes/console/project-[project]/overview/platforms/+page.svelte @@ -37,7 +37,7 @@ import { app } from '$lib/stores/app'; import type { PageData } from './$types'; import { ContainerHeader } from '$lib/layout'; - import { getServiceLimit } from '$lib/stores/billing'; + import { getServiceLimit, readOnly } from '$lib/stores/billing'; export let data: PageData; @@ -82,7 +82,8 @@ diff --git a/src/routes/console/project-[project]/settings/migrations/+page.svelte b/src/routes/console/project-[project]/settings/migrations/+page.svelte index cfa193840..90f84446f 100644 --- a/src/routes/console/project-[project]/settings/migrations/+page.svelte +++ b/src/routes/console/project-[project]/settings/migrations/+page.svelte @@ -23,6 +23,7 @@ import ExportModal from './exportModal.svelte'; import Status from '$lib/components/status.svelte'; import { capitalize } from '$lib/helpers/string'; + import { readOnly } from '$lib/stores/billing'; export let data; let details: string | null = null; @@ -251,8 +252,9 @@ - + @@ -281,7 +283,8 @@ + on:click={() => (showExport = true)} + disabled={$readOnly}>Export data diff --git a/src/routes/console/project-[project]/storage/bucket-[bucket]/+page.svelte b/src/routes/console/project-[project]/storage/bucket-[bucket]/+page.svelte index 195cffc2d..2a2e07f38 100644 --- a/src/routes/console/project-[project]/storage/bucket-[bucket]/+page.svelte +++ b/src/routes/console/project-[project]/storage/bucket-[bucket]/+page.svelte @@ -46,7 +46,7 @@ import { Dependencies } from '$lib/constants'; import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; import { tooltip } from '$lib/actions/tooltip'; - import { getServiceLimit, tierToPlan, type Tier } from '$lib/stores/billing'; + import { getServiceLimit, tierToPlan, type Tier, readOnly } from '$lib/stores/billing'; import { organization } from '$lib/stores/organization'; import { wizard } from '$lib/stores/wizard'; import ChangeOrganizationTierCloud from '$routes/console/changeOrganizationTierCloud.svelte'; @@ -114,12 +114,12 @@
diff --git a/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/+page.svelte b/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/+page.svelte index d24ed367b..1305d5369 100644 --- a/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/+page.svelte +++ b/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/+page.svelte @@ -61,7 +61,9 @@ import { Button, Form, + FormItem, FormList, + InputChoice, InputSelect, InputSwitch, InputTags, @@ -78,6 +80,7 @@ import Delete from '../deleteBucket.svelte'; import { bucket } from '../store'; import UpdateMaxFileSize from './updateMaxFileSize.svelte'; + import { readOnly } from '$lib/stores/billing'; let showDelete = false; @@ -229,7 +232,9 @@ - + @@ -243,13 +248,15 @@ id="name" label="Name" placeholder="Enter name" - autocomplete={false} + readonly={$readOnly} bind:value={bucketName} /> - @@ -301,7 +308,9 @@

- @@ -317,54 +326,29 @@

-
  • - -
  • -
  • - -
  • - -
  • + + + This parameter allows you to configure whether or not the files + inside the bucket should be scanned by the Appwrite Antivirus + scanner. + + @@ -406,7 +390,7 @@
    - File Extensions + Allowed file Extensions

    Allowed file extensions. A maximum of 100 file extensions can be added. Leave blank to allow all file types. @@ -439,7 +423,7 @@ - +

    diff --git a/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/updateMaxFileSize.svelte b/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/updateMaxFileSize.svelte index 9e93117ce..74c4bd5b4 100644 --- a/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/updateMaxFileSize.svelte +++ b/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/updateMaxFileSize.svelte @@ -4,7 +4,7 @@ import { Button, Form, InputNumber, InputSelect } from '$lib/elements/forms'; import { humanFileSize } from '$lib/helpers/sizeConvertion'; import { createByteUnitPair } from '$lib/helpers/unit'; - import { getServiceLimit } from '$lib/stores/billing'; + import { getServiceLimit, readOnly } from '$lib/stores/billing'; import { organization } from '$lib/stores/organization'; import { wizard } from '$lib/stores/wizard'; import { isCloud } from '$lib/system'; @@ -55,6 +55,7 @@ - +
    diff --git a/src/routes/console/wizard/cloudOrganization/usageRates.svelte b/src/routes/console/wizard/cloudOrganization/usageRates.svelte index 72773a988..d62fbd673 100644 --- a/src/routes/console/wizard/cloudOrganization/usageRates.svelte +++ b/src/routes/console/wizard/cloudOrganization/usageRates.svelte @@ -13,6 +13,7 @@ import { organization } from '$lib/stores/organization'; import { createOrganization } from './store'; import { plansInfo } from '$lib/stores/billing'; + import { abbreviateNumber } from '$lib/helpers/numbers'; export let show = false; export let tier: string; @@ -29,24 +30,24 @@ { id: 'members', resource: 'Organization members', - unit: '' + unit: 'member' }, - { id: 'bandwith', resource: 'Bandwidth', unit: 'GB' }, + { id: 'bandwidth', resource: 'Bandwidth', unit: 'GB' }, { id: 'storage', resource: 'Storage', unit: 'GB' }, { id: 'executions', resource: 'Function executions', - unit: 'executions' + unit: ' executions' }, { id: 'users', resource: 'Active users', - unit: 'AU' + unit: ' AU' }, { id: 'realtime', resource: 'Concurrent connections', - unit: 'connections' + unit: ' connections' } ]; @@ -65,11 +66,28 @@ {#each planData as usage} - - {usage.resource} - {plan[usage.id]}{usage?.unit} - {plan[`${usage.id}Addon`]} - + {#if usage['id'] === 'members'} + + {usage.resource} + + {plan[usage.id] || 'Unlimited'} + + ${plan.memberAddon.price}/{usage?.unit} + + {:else} + {@const addon = plan[`${usage.id}Addon`]} + + {usage.resource} + + {abbreviateNumber(plan[usage.id])}{usage?.unit} + + ${addon?.price}/{['MB', 'GB', 'TB'].includes(addon?.unit) + ? addon?.value + : abbreviateNumber(addon?.value, 0)}{usage?.unit} + + {/if} {/each}