diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index 5b2060abf..91a38a268 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -227,6 +227,8 @@ export enum Submit { OrganizationBackupPaymentAdded = 'submit_organization_backup_payment_added', OrganizationBackupPaymentUpdated = 'submit_organization_backup_payment_updated', OrganizationBackupPaymentRemoved = 'submit_organization_backup_payment_removed', + OrganizationBillingAddressAdded = 'submit_organization_billing_address_added', + OrganizationBillingAddressRemoved = 'submit_organization_billing_address_removed', PromoCodeRedeemed = 'submit_promo_code_redeemed', SupportTicket = 'submit_support_ticket' } diff --git a/src/lib/components/tab.svelte b/src/lib/components/tab.svelte index f3825acbf..519b24517 100644 --- a/src/lib/components/tab.svelte +++ b/src/lib/components/tab.svelte @@ -22,7 +22,6 @@ await goto(href); await waitUntil(() => { - console.log('tickUntil', el); return el.classList.contains('is-selected'); }, 1000); el.focus(); diff --git a/src/lib/constants.ts b/src/lib/constants.ts index a5896580d..f5cf6587d 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -5,6 +5,7 @@ export const INTERVAL = 5 * 60000; // default interval to check for feedback export enum Dependencies { CREDIT = 'dependency:credit', INVOICES = 'dependency:invoices', + ADDRESS = 'dependency:address', PAYMENT_METHODS = 'dependency:paymentMethods', ORGANIZATION = 'dependency:organization', PROJECT = 'dependency:project', diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index ad21aa84e..07159fb91 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -1,7 +1,6 @@ import type { Client, Query } from '@appwrite.io/console'; import type { Organization } from '../stores/organization'; import type { PaymentMethod } from '@stripe/stripe-js'; -import type BillingAddress from '$routes/console/account/payments/billingAddress.svelte'; export type PaymentMethodData = { $id: string; @@ -161,7 +160,7 @@ export type Address = { }; export type AddressesList = { - addresses: Address[]; + billingAddresses: Address[]; total: number; }; @@ -197,6 +196,11 @@ export type Plan = { realtimeAddon: AdditionalResource | null; }; +export type PlanList = { + plans: Plan[]; + total: number; +}; + export class Billing { client: Client; @@ -515,7 +519,7 @@ export class Billing { async setBillingAddress( organizationId: string, billingAddressId: string - ): Promise { + ): Promise { const path = `/organizations/${organizationId}/billing-address`; const params = { organizationId, @@ -532,7 +536,7 @@ export class Billing { ); } - async removeBillingAddress(organizationId: string): Promise { + async removeBillingAddress(organizationId: string): Promise { const path = `/organizations/${organizationId}/billing-address`; const params = { organizationId @@ -787,7 +791,7 @@ export class Billing { ); } - async getPlans(): Promise { + async getPlanList(): Promise { const path = `/console/plans`; const params = {}; const uri = new URL(this.client.config.endpoint + path); diff --git a/src/routes/console/account/payments/addressModal.svelte b/src/routes/console/account/payments/addressModal.svelte index aa3245710..3d20f508d 100644 --- a/src/routes/console/account/payments/addressModal.svelte +++ b/src/routes/console/account/payments/addressModal.svelte @@ -6,22 +6,32 @@ import { Button, InputNumber, InputSelect, InputText } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdk } from '$lib/stores/sdk'; + import { onMount } from 'svelte'; export let show = false; - //TODO: fetch countries from appwrite - const options = [ - { - value: 'US', - label: 'United States' - } - ]; let country: string; let address: string; let address2: string; let city: string; let state: string; let zip: number; + let options = [ + { + value: 'US', + label: 'United States' + } + ]; + + onMount(async () => { + const countryList = await sdk.forProject.locale.listCountries(); + options = countryList.countries.map((country) => { + return { + value: country.code, + label: country.name + }; + }); + }); async function handleSubmit() { try { @@ -33,19 +43,19 @@ state, zip?.toString() ); - await invalidate(Dependencies.PAYMENT_METHODS); + await invalidate(Dependencies.ADDRESS); show = false; addNotification({ type: 'success', - message: `Address has been deleted` + message: `Address has been added` }); - trackEvent(Submit.BillingAddressDeleted); + trackEvent(Submit.BillingAddressCreated); } catch (error) { addNotification({ type: 'error', message: error.message }); - trackError(error, Submit.BillingAddressDeleted); + trackError(error, Submit.BillingAddressCreated); } } diff --git a/src/routes/console/account/payments/editPaymentModal.svelte b/src/routes/console/account/payments/editPaymentModal.svelte index 708541437..0f1820659 100644 --- a/src/routes/console/account/payments/editPaymentModal.svelte +++ b/src/routes/console/account/payments/editPaymentModal.svelte @@ -67,6 +67,6 @@ - + diff --git a/src/routes/console/account/payments/paymentModal.svelte b/src/routes/console/account/payments/paymentModal.svelte index c429632a5..704f99c75 100644 --- a/src/routes/console/account/payments/paymentModal.svelte +++ b/src/routes/console/account/payments/paymentModal.svelte @@ -50,6 +50,6 @@ - + diff --git a/src/routes/console/organization-[organization]/billing/+page.svelte b/src/routes/console/organization-[organization]/billing/+page.svelte index 42860d055..836c78f7d 100644 --- a/src/routes/console/organization-[organization]/billing/+page.svelte +++ b/src/routes/console/organization-[organization]/billing/+page.svelte @@ -12,8 +12,8 @@ import { failedInvoice, paymentMethods } from '$lib/stores/billing'; import type { PaymentMethodData } from '$lib/sdk/billing'; - $: defaultPaymentMethod = $paymentMethods.paymentMethods.find( - (method: PaymentMethodData) => method.$id === $organization.paymentMethodId + $: defaultPaymentMethod = $paymentMethods?.paymentMethods?.find( + (method: PaymentMethodData) => method.$id === $organization?.paymentMethodId ); diff --git a/src/routes/console/organization-[organization]/billing/availableCredit.svelte b/src/routes/console/organization-[organization]/billing/availableCredit.svelte index f09997221..d59e33834 100644 --- a/src/routes/console/organization-[organization]/billing/availableCredit.svelte +++ b/src/routes/console/organization-[organization]/billing/availableCredit.svelte @@ -38,7 +38,7 @@ await sdk.forConsole.billing.addCredit($organization.$id, coupon); addNotification({ type: 'success', - message: `A new payment method has been added to ${$organization.name}` + message: `Credit has been added to ${$organization.name}` }); invalidate(Dependencies.ORGANIZATION); trackEvent(Submit.CouponRedeemed, { @@ -55,6 +55,7 @@ } async function request() { + if (!$organization?.$id) return; creditList = await sdk.forConsole.billing.listCredits($organization.$id, [ Query.limit(limit), Query.offset(offset) diff --git a/src/routes/console/organization-[organization]/billing/billingAddress.svelte b/src/routes/console/organization-[organization]/billing/billingAddress.svelte index 03de455f7..8fbf3e209 100644 --- a/src/routes/console/organization-[organization]/billing/billingAddress.svelte +++ b/src/routes/console/organization-[organization]/billing/billingAddress.svelte @@ -1,9 +1,39 @@ @@ -21,18 +51,24 @@ - - Add new billing address + {/if} + { + showCreate = true; + showDropdown = false; + }}>Add new billing address @@ -43,3 +79,5 @@ + + diff --git a/src/routes/console/organization-[organization]/billing/paymentMethods.svelte b/src/routes/console/organization-[organization]/billing/paymentMethods.svelte index 1a694540b..e55771912 100644 --- a/src/routes/console/organization-[organization]/billing/paymentMethods.svelte +++ b/src/routes/console/organization-[organization]/billing/paymentMethods.svelte @@ -13,11 +13,13 @@ import type { PaymentMethodData } from '$lib/sdk/billing'; import DeleteOrgPayment from './deleteOrgPayment.svelte'; import ReplaceCard from './replaceCard.svelte'; + import EditPaymentModal from '$routes/console/account/payments/editPaymentModal.svelte'; let showDropdown = false; let showDropdownBackup = false; let showPayment = false; + let showEdit = false; let showDelete = false; let showReplace = false; let isSelectedBackup = false; @@ -65,13 +67,13 @@ } } - $: if ($organization.backupPaymentMethodId) { + $: if ($organization?.backupPaymentMethodId) { sdk.forConsole.billing .getPaymentMethod($organization.backupPaymentMethodId) .then((res) => (backupPaymentMethod = res)); } - $: if ($organization.paymentMethodId) { + $: if ($organization?.paymentMethodId) { sdk.forConsole.billing .getPaymentMethod($organization.paymentMethodId) .then((res) => (defaultPaymentMethod = res)); @@ -107,7 +109,8 @@ { - console.log('test'); + showEdit = true; + showDropdown = false; }}> Edit @@ -189,7 +192,9 @@ { - console.log('test'); + showEdit = true; + isSelectedBackup = true; + showDropdownBackup = false; }}> Edit @@ -247,8 +252,9 @@ {/each} {/if} - (showPayment = true)} - >Add new payment method + (showPayment = true)}> + Add new payment method + @@ -264,6 +270,13 @@ {#if showPayment && isCloud && hasStripePublicKey} {/if} +{#if showEdit && isCloud && hasStripePublicKey} + +{/if} {#if showReplace && isCloud && hasStripePublicKey} {/if} diff --git a/src/routes/console/organization-[organization]/billing/store.ts b/src/routes/console/organization-[organization]/billing/store.ts index 0ed4377ba..b1d20630f 100644 --- a/src/routes/console/organization-[organization]/billing/store.ts +++ b/src/routes/console/organization-[organization]/billing/store.ts @@ -1,7 +1,8 @@ import { page } from '$app/stores'; +import type { AddressesList } from '$lib/sdk/billing'; import { derived } from 'svelte/store'; -export const addressList = derived(page, ($page) => $page.data.addressList as string | null); +export const addressList = derived(page, ($page) => $page.data.addressList as AddressesList); export const aggregationList = derived( page, ($page) => $page.data.aggregationList as string | null diff --git a/src/routes/console/wizard/cloudOrganization/usageRates.svelte b/src/routes/console/wizard/cloudOrganization/usageRates.svelte index 9daa5144f..4afe45cb8 100644 --- a/src/routes/console/wizard/cloudOrganization/usageRates.svelte +++ b/src/routes/console/wizard/cloudOrganization/usageRates.svelte @@ -1,6 +1,5 @@ @@ -36,11 +71,11 @@ Rate - {#each usageRates[tier] as usage} + {#each planData as usage} {usage.resource} - {usage.amount}{usage?.unit} - {usage.rate} + {plan[usage.id]}{usage?.unit} + {plan[`${usage.id}Addon`]} {/each} diff --git a/src/routes/console/wizard/cloudOrganizationChangeTier/step1.svelte b/src/routes/console/wizard/cloudOrganizationChangeTier/step1.svelte index 646cbf805..dcf49e0c2 100644 --- a/src/routes/console/wizard/cloudOrganizationChangeTier/step1.svelte +++ b/src/routes/console/wizard/cloudOrganizationChangeTier/step1.svelte @@ -96,5 +96,5 @@ {/if} - {#if $organization.billingPlan === 'tier-0'}TODO: add transfer modal{/if} +