From 516f8ce9de2da30862e319afb4880334687e2d13 Mon Sep 17 00:00:00 2001 From: Arman Date: Mon, 17 Jul 2023 14:53:55 +0200 Subject: [PATCH] fix: some svelte check errors --- src/lib/components/regionCard.svelte | 1 - src/lib/elements/table/body.svelte | 1 + src/lib/stores/billing.ts | 16 ++--- .../console/createOrganizationCloud.svelte | 6 -- .../billing/+page.ts | 4 +- .../billing/paymentModal.svelte | 36 +++++++--- .../invoices/+page.svelte | 1 - .../usage/[[period]]/+page.ts | 63 ---------------- .../settings/usage/[[period]]/+page.ts | 34 +++++---- src/routes/console/wizard/step1.svelte | 33 ++++----- src/routes/console/wizard/step2.svelte | 71 +------------------ src/routes/console/wizard/step3.svelte | 2 +- src/routes/console/wizard/store.ts | 1 - 13 files changed, 74 insertions(+), 195 deletions(-) diff --git a/src/lib/components/regionCard.svelte b/src/lib/components/regionCard.svelte index 924dbc8c0..e12bef707 100644 --- a/src/lib/components/regionCard.svelte +++ b/src/lib/components/regionCard.svelte @@ -4,7 +4,6 @@ export let value: string | number | boolean; export let disabled = false; export let padding = 1; - export let icon: string = null; export let fullHeight = true; export let borderRadius: 'xsmall' | 'small' | 'medium' | 'large' = 'small'; diff --git a/src/lib/elements/table/body.svelte b/src/lib/elements/table/body.svelte index f784e8587..f5682dda7 100644 --- a/src/lib/elements/table/body.svelte +++ b/src/lib/elements/table/body.svelte @@ -11,6 +11,7 @@ {#if isCloud && limitReached && name} + Upgrade your plan to add {name} to your organization diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index e189156e7..f87bf54e3 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -1,7 +1,6 @@ import type { Client } from '@appwrite.io/console'; import type { Organization } from './organization'; import type { PaymentMethod } from '@stripe/stripe-js'; -import type { P } from 'vitest/dist/types-fafda418'; export type PaymentMethodData = { $id: string; @@ -441,16 +440,15 @@ export const tierFree = { description: 'For personal, passion projects.' }; -export const tierStarter = { - price: 10, - name: 'Starter', - description: 'For small organizations that want flexibility.' -}; - export const tierPro = { - price: 20, + price: 15, name: 'Pro', - description: 'For organizations that need the ability scale easily.' + description: 'For pro developers and production projects that need the ability to scale.' +}; +export const tierScale = { + price: 685, + name: 'Scale', + description: 'For scaling teams that need dedicated support.' }; export const apperanceLight = { diff --git a/src/routes/console/createOrganizationCloud.svelte b/src/routes/console/createOrganizationCloud.svelte index 6d968c390..7e3e2bf96 100644 --- a/src/routes/console/createOrganizationCloud.svelte +++ b/src/routes/console/createOrganizationCloud.svelte @@ -30,12 +30,6 @@ $createOrganization.paymentMethodId ); - //Add credit - if ($createOrganization?.promoCodes?.length) { - $createOrganization.promoCodes.forEach(async (code) => { - await sdk.forConsole.billing.addCredit(org.$id, code); - }); - } //Add budget if ($createOrganization?.billingBudget) { await sdk.forConsole.billing.updateBudget( diff --git a/src/routes/console/organization-[organization]/billing/+page.ts b/src/routes/console/organization-[organization]/billing/+page.ts index f321f366a..0c9b12344 100644 --- a/src/routes/console/organization-[organization]/billing/+page.ts +++ b/src/routes/console/organization-[organization]/billing/+page.ts @@ -2,12 +2,12 @@ import { Dependencies } from '$lib/constants'; import { sdk } from '$lib/stores/sdk'; import type { PageLoad } from './$types'; -export const load: PageLoad = async ({ params, parent, depends }) => { +export const load: PageLoad = async ({ parent, depends }) => { await parent(); depends(Dependencies.PAYMENT_METHODS); return { - // paymentMethods: await sdk.forConsole.billing.listPaymentMethods(params.organization) + paymentMethods: await sdk.forConsole.billing.listPaymentMethods() // budget: await sdk.forConsole.billing.(params.organization) }; }; diff --git a/src/routes/console/organization-[organization]/billing/paymentModal.svelte b/src/routes/console/organization-[organization]/billing/paymentModal.svelte index 29d064b8b..2f7987f2b 100644 --- a/src/routes/console/organization-[organization]/billing/paymentModal.svelte +++ b/src/routes/console/organization-[organization]/billing/paymentModal.svelte @@ -2,7 +2,7 @@ // import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; import { Modal } from '$lib/components'; import { InputText, Button, FormList } from '$lib/elements/forms'; - import { paymentMethods, publicKey } from './store'; + import { paymentMethods } from './store'; import { loadStripe, type Stripe, @@ -15,7 +15,12 @@ import { invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import { app } from '$lib/stores/app'; - import { apperanceDark, apperanceLight } from '$lib/stores/billing'; + import { + apperanceDark, + apperanceLight, + publicStripeKey, + type PaymentList + } from '$lib/stores/billing'; export let show = false; @@ -26,13 +31,24 @@ let clientSecret: string; let paymentMethod: PaymentMethod; + let isStripeInitialized = false; + let methods: PaymentList; onMount(async () => { - stripe = await loadStripe(publicKey); + methods = await sdk.forConsole.billing.listPaymentMethods(); + if (methods?.total) { + $organization.paymentMethodId = methods[0].id; + } else if (!isStripeInitialized) initialize(); + }); + + async function initialize() { + stripe = await loadStripe(publicStripeKey); + isStripeInitialized = true; + try { clientSecret = $paymentMethods?.paymentMethods[0]?.clientSecret; if (!clientSecret) { - paymentMethod = await sdk.forConsole.billing.createPaymentMethod($organization.$id); + paymentMethod = await sdk.forConsole.billing.createPaymentMethod(); } const options = { clientSecret: clientSecret ? clientSecret : paymentMethod.clientSecret, @@ -45,7 +61,7 @@ } catch (e) { error = e.message; } - }); + } async function createForm() { const paymentElement = elements.create('payment'); @@ -61,16 +77,14 @@ }, redirect: 'if_required' }); - paymentMethod = await sdk.forConsole.billing.createPaymentMethod($organization.$id); + paymentMethod = await sdk.forConsole.billing.createPaymentMethod(); const { setupIntent } = await stripe.retrieveSetupIntent(paymentMethod.clientSecret); if (setupIntent && setupIntent.status === 'succeeded') { await sdk.forConsole.billing.setOrganizationPaymentMethod( $organization.$id, - paymentMethod.$id, - setupIntent.payment_method as string + paymentMethod.$id ); await invalidate(Dependencies.PAYMENT_METHODS); - show = false; console.log('test'); // const paymentElement = elements.getElement('payment'); // paymentElement.destroy(); @@ -81,6 +95,10 @@ // trackError(StripeError, Submit.ProjectCreate); } } + + $: if ($organization.paymentMethodId === null && !isStripeInitialized) { + initialize(); + } diff --git a/src/routes/console/organization-[organization]/invoices/+page.svelte b/src/routes/console/organization-[organization]/invoices/+page.svelte index 8874c7fe1..90b0e423c 100644 --- a/src/routes/console/organization-[organization]/invoices/+page.svelte +++ b/src/routes/console/organization-[organization]/invoices/+page.svelte @@ -3,7 +3,6 @@ import { DropList, DropListItem, - DropListLink, EmptySearch, Heading, PaginationInline diff --git a/src/routes/console/organization-[organization]/usage/[[period]]/+page.ts b/src/routes/console/organization-[organization]/usage/[[period]]/+page.ts index 5026fe606..36014e5a3 100644 --- a/src/routes/console/organization-[organization]/usage/[[period]]/+page.ts +++ b/src/routes/console/organization-[organization]/usage/[[period]]/+page.ts @@ -1,68 +1,5 @@ import { sdk } from '$lib/stores/sdk'; -import { Query } from '@appwrite.io/console'; import type { PageLoad } from './$types'; -import { error } from '@sveltejs/kit'; - -const MOCKDATA = [ - { - name: 'test', - projectUsage: [ - { - name: 'Bandwidth', - icon: 'chart-bar', - unit: 'GB', - max: 16, - used: 8, - status: null - }, - { - name: 'Storage', - icon: 'folder', - unit: 'GB', - max: 3.5, - used: 3.7, - status: 'error' - }, - { - name: 'Compute', - icon: 'lightning-bolt', - unit: 'hrs', - max: 2, - used: 1.8, - status: 'warning' - } - ] - }, - { - name: 'Lol', - projectUsage: [ - { - name: 'Bandwidth', - icon: 'chart-bar', - unit: 'GB', - max: 16, - used: 8, - status: null - }, - { - name: 'Storage', - icon: 'folder', - unit: 'GB', - max: 10.5, - used: 3.7, - status: null - }, - { - name: 'Compute', - icon: 'lightning-bolt', - unit: 'hrs', - max: 2, - used: 1.5, - status: null - } - ] - } -]; export const load: PageLoad = async ({ params }) => { const usage = await sdk.forConsole.billing.listUsage(params.organization); diff --git a/src/routes/console/project-[project]/settings/usage/[[period]]/+page.ts b/src/routes/console/project-[project]/settings/usage/[[period]]/+page.ts index ad4566362..8f06624a7 100644 --- a/src/routes/console/project-[project]/settings/usage/[[period]]/+page.ts +++ b/src/routes/console/project-[project]/settings/usage/[[period]]/+page.ts @@ -1,20 +1,18 @@ -// import type { Models } from '@appwrite.io/console'; -// import { sdk } from '$lib/stores/sdk'; -// import type { PageLoad } from './$types'; -// import { error } from '@sveltejs/kit'; +import type { Models } from '@appwrite.io/console'; +import { sdk } from '$lib/stores/sdk'; +import type { PageLoad } from './$types'; +import { error } from '@sveltejs/kit'; -// export const load: PageLoad = async ({ params }) => { -// try { -// const response = await sdk.forProject.functions.getFunctionUsage( -// params.function, -// params.period ?? '30d' -// ); +export const load: PageLoad = async ({ params }) => { + try { + const response = await sdk.forProject.project.getUsage(params.period ?? '30d'); -// return { -// count: response.executionsTotal as unknown as Models.Metric[], -// errors: response.buildsFailure as unknown as Models.Metric[] -// }; -// } catch (e) { -// throw error(e.code, e.message); -// } -// }; + return { + response + // count: response.executionsTotal as unknown as Models.Metric[], + // errors: response.buildsFailure as unknown as Models.Metric[] + }; + } catch (e) { + throw error(e.code, e.message); + } +}; diff --git a/src/routes/console/wizard/step1.svelte b/src/routes/console/wizard/step1.svelte index 6dec604a9..e3c01a4d6 100644 --- a/src/routes/console/wizard/step1.svelte +++ b/src/routes/console/wizard/step1.svelte @@ -3,7 +3,7 @@ import { Pill } from '$lib/elements'; import { InputText, FormList } from '$lib/elements/forms'; import { WizardStep } from '$lib/layout'; - import { tierFree, tierPro, tierStarter } from '$lib/stores/billing'; + import { tierFree, tierPro, tierScale } from '$lib/stores/billing'; import { organizationList } from '$lib/stores/organization'; import { createOrganization } from './store'; @@ -63,21 +63,7 @@ {/if} -
  • - - -
    -

    - {tierStarter.name} - ${tierStarter.price}/month per organization member -

    -

    - {tierStarter.description} -

    -
    - 14 DAY FREE TRIAL -
    -
    -
  • +
  • @@ -94,5 +80,20 @@
  • +
  • + + +
    +

    + {tierScale.name} - ${tierScale.price}/month + exta usage +

    +

    + {tierScale.description} +

    +
    + 14 DAY FREE TRIAL +
    +
    +
  • diff --git a/src/routes/console/wizard/step2.svelte b/src/routes/console/wizard/step2.svelte index c931dec15..efc0ed510 100644 --- a/src/routes/console/wizard/step2.svelte +++ b/src/routes/console/wizard/step2.svelte @@ -1,18 +1,10 @@