mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: update card, billing addres (wip)
This commit is contained in:
1 parent
42570c01d0
commit
4bacc238d8
9 files changed
+179
-23
No files matched your search
@@ -12,6 +12,7 @@ export type Organization = Models.Team<Record<string, unknown>> & {
|
||||
billingNextInvoiceDate: string;
|
||||
billingTrialStartDate?: string;
|
||||
billingTrialDays?: number;
|
||||
amount: number;
|
||||
};
|
||||
|
||||
export const newOrgModal = writable<boolean>(false);
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
<script lang="ts">
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import { Modal } from '$lib/components';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { Button, InputNumber, InputSelect, InputText } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
|
||||
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;
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await sdk.forConsole.billing.createAddress(
|
||||
country,
|
||||
address,
|
||||
address2,
|
||||
city,
|
||||
state,
|
||||
zip?.toString()
|
||||
);
|
||||
await invalidate(Dependencies.PAYMENT_METHODS);
|
||||
show = false;
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `Address has been deleted`
|
||||
});
|
||||
trackEvent(Submit.BillingAddressDeleted);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
trackError(error, Submit.BillingAddressDeleted);
|
||||
}
|
||||
}
|
||||
|
||||
$: isButtonDisabled = !country || !address || !city || !state || !zip;
|
||||
</script>
|
||||
|
||||
<Modal bind:show onSubmit={handleSubmit} size="big">
|
||||
<svelte:fragment slot="header">Add billing address</svelte:fragment>
|
||||
<InputSelect
|
||||
bind:value={country}
|
||||
{options}
|
||||
label="Country or region"
|
||||
placeholder="Select country or region"
|
||||
id="country"
|
||||
required />
|
||||
<InputText
|
||||
bind:value={address}
|
||||
id="address"
|
||||
label="Street address"
|
||||
placeholder="Enter street address"
|
||||
required />
|
||||
<InputText
|
||||
bind:value={address2}
|
||||
id="address2"
|
||||
label="Address line 2"
|
||||
placeholder="Unit number, floor, etc." />
|
||||
<InputText
|
||||
bind:value={city}
|
||||
id="city"
|
||||
label="City or suburb"
|
||||
placeholder="Enter your city"
|
||||
required />
|
||||
<InputText
|
||||
bind:value={state}
|
||||
id="state"
|
||||
label="State"
|
||||
placeholder="Enter your state"
|
||||
required />
|
||||
<InputNumber
|
||||
bind:value={zip}
|
||||
id="zip"
|
||||
label="Postal code"
|
||||
placeholder="Enter postal code"
|
||||
required />
|
||||
<svelte:fragment slot="footer">
|
||||
<Button text on:click={() => (show = false)}>Cancel</Button>
|
||||
<Button submit disabled={isButtonDisabled}>Save</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
@@ -1,5 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { CardGrid, Empty, Heading } from '$lib/components';
|
||||
import { addressList } from '$routes/console/organization-[organization]/billing/store';
|
||||
import AddressModal from './addressModal.svelte';
|
||||
|
||||
let show = false;
|
||||
|
||||
$: console.log($addressList);
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
@@ -9,8 +15,10 @@
|
||||
View or update your billing address. This address will appear on your invoice.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<Empty>
|
||||
<Empty on:click={() => (show = true)}>
|
||||
<p class="text">Add a billing address</p>
|
||||
</Empty>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
|
||||
<AddressModal bind:show />
|
||||
@@ -1,30 +1,47 @@
|
||||
<script lang="ts">
|
||||
// import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import { Modal } from '$lib/components';
|
||||
import { Button, FormList } from '$lib/elements/forms';
|
||||
import { onMount } from 'svelte';
|
||||
import { initializeStripe, updateStripeCard } from '$lib/stores/stripe';
|
||||
import { Button, FormList, InputNumber, InputSelect } from '$lib/elements/forms';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
|
||||
export let show = false;
|
||||
export let selectedPaymentMethod: string;
|
||||
let error: string;
|
||||
|
||||
onMount(async () => {
|
||||
await initializeStripe();
|
||||
});
|
||||
const options = [
|
||||
{ value: '01', label: '01' },
|
||||
{ value: '02', label: '02' },
|
||||
{ value: '03', label: '03' },
|
||||
{ value: '04', label: '04' },
|
||||
{ value: '05', label: '05' },
|
||||
{ value: '06', label: '06' },
|
||||
{ value: '07', label: '07' },
|
||||
{ value: '08', label: '08' },
|
||||
{ value: '09', label: '09' },
|
||||
{ value: '10', label: '10' },
|
||||
{ value: '11', label: '11' },
|
||||
{ value: '12', label: '12' }
|
||||
];
|
||||
|
||||
let error: string;
|
||||
let month: string;
|
||||
let year: number;
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await updateStripeCard(selectedPaymentMethod);
|
||||
show = false;
|
||||
await sdk.forConsole.billing.updatePaymentMethod(
|
||||
selectedPaymentMethod,
|
||||
month,
|
||||
year?.toString()
|
||||
);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: 'Your payment method has been updated'
|
||||
});
|
||||
invalidate(Dependencies.PAYMENT_METHODS);
|
||||
show = false;
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
@@ -34,9 +51,19 @@
|
||||
<Modal bind:error onSubmit={handleSubmit} size="big" bind:show>
|
||||
<svelte:fragment slot="header">Update payment method</svelte:fragment>
|
||||
<FormList>
|
||||
<div id="payment-element">
|
||||
<!-- Elements will create form elements here -->
|
||||
</div>
|
||||
<InputSelect
|
||||
id="month"
|
||||
label="Month"
|
||||
bind:value={month}
|
||||
{options}
|
||||
required
|
||||
placeholder="Select expiry month" />
|
||||
<InputNumber
|
||||
id="year"
|
||||
label="Year"
|
||||
bind:value={year}
|
||||
required
|
||||
placeholder="Select expiry year" />
|
||||
</FormList>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary on:click={() => (show = false)}>Cancel</Button>
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Dependencies } from '$lib/constants';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
export const load: PageLoad = async ({ parent, depends }) => {
|
||||
export const load: PageLoad = async ({ params, parent, depends }) => {
|
||||
await parent();
|
||||
depends(Dependencies.PAYMENT_METHODS);
|
||||
depends(Dependencies.ORGANIZATION);
|
||||
@@ -10,6 +10,8 @@ export const load: PageLoad = async ({ parent, depends }) => {
|
||||
depends(Dependencies.INVOICES);
|
||||
|
||||
return {
|
||||
paymentMethods: await sdk.forConsole.billing.listPaymentMethods()
|
||||
paymentMethods: await sdk.forConsole.billing.listPaymentMethods(),
|
||||
addressList: await sdk.forConsole.billing.listAddresses(),
|
||||
aggregationList: await sdk.forConsole.billing.listUsage(params.organization)
|
||||
};
|
||||
};
|
||||
@@ -45,9 +45,11 @@
|
||||
</div>
|
||||
|
||||
<p class="text">
|
||||
{#if $organization.billingPlan !== 'tier-0' && $organization.billingTrialDays}
|
||||
{#if $organization.billingPlan !== 'tier-0' && !$organization.billingTrialDays}
|
||||
<span class="u-color-text-gray"> Esimated total: </span>
|
||||
{/if}
|
||||
<!-- TODO: add estimated total from aggregation -->
|
||||
|
||||
${currentTier.price}
|
||||
</p>
|
||||
</div>
|
||||
@@ -60,7 +62,6 @@
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
<!-- TODO: add change plan method -->
|
||||
<Button text on:click={() => wizard.start(ChangeOrganizationTierCloud)}
|
||||
>Change plan</Button>
|
||||
<Button secondary href={`${base}/console/organization-${$organization?.$id}/usage`}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { page } from '$app/stores';
|
||||
import { derived } from 'svelte/store';
|
||||
|
||||
export const addressList = derived(page, ($page) => $page.data.addressList as string | null);
|
||||
export const aggregationList = derived(
|
||||
page,
|
||||
($page) => $page.data.aggregationList as string | null
|
||||
);
|
||||
@@ -9,19 +9,31 @@
|
||||
|
||||
$: rates = usageRates[$organization.billingPlan];
|
||||
|
||||
$: bandwidth = data.usage.aggregations.reduce((acc, curr) => acc + curr.usageBandwidth, 0);
|
||||
$: bandwidth = data.aggregationList.aggregations.reduce(
|
||||
(acc, curr) => acc + curr.usageBandwidth,
|
||||
0
|
||||
);
|
||||
$: bandwidthLimit = rates.filter((r) => r.resource === 'Bandwidth')[0].amount;
|
||||
|
||||
$: users = data.usage.aggregations.reduce((acc, curr) => acc + curr.usageUsers, 0);
|
||||
$: users = data.aggregationList.aggregations.reduce((acc, curr) => acc + curr.usageUsers, 0);
|
||||
$: usersLimit = rates.filter((r) => r.resource === 'Active users')[0].amount;
|
||||
|
||||
$: executions = data.usage.aggregations.reduce((acc, curr) => acc + curr.usageExecutions, 0);
|
||||
$: executions = data.aggregationList.aggregations.reduce(
|
||||
(acc, curr) => acc + curr.usageExecutions,
|
||||
0
|
||||
);
|
||||
$: executionsLimit = rates.filter((r) => r.resource === 'Function executions')[0].amount;
|
||||
|
||||
$: storage = data.usage.aggregations.reduce((acc, curr) => acc + curr.usageStorage, 0);
|
||||
$: storage = data.aggregationList.aggregations.reduce(
|
||||
(acc, curr) => acc + curr.usageStorage,
|
||||
0
|
||||
);
|
||||
$: storageLimit = rates.filter((r) => r.resource === 'Storage')[0].amount;
|
||||
|
||||
$: realtime = data.usage.aggregations.reduce((acc, curr) => acc + curr.usageRealtime, 0);
|
||||
$: realtime = data.aggregationList.aggregations.reduce(
|
||||
(acc, curr) => acc + curr.usageRealtime,
|
||||
0
|
||||
);
|
||||
$: realtimeLimit = rates.filter((r) => r.resource === 'Concurrent connections')[0].amount;
|
||||
</script>
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@ export const load: PageLoad = async ({ params }) => {
|
||||
const usage = await sdk.forConsole.billing.listUsage(params.organization);
|
||||
console.log(usage);
|
||||
return {
|
||||
usage
|
||||
aggregationList: usage
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user