Skip to content

Commit 4eda58b

Browse files
committed
improvements.
1 parent 09884a9 commit 4eda58b

5 files changed

Lines changed: 47 additions & 43 deletions

File tree

src/routes/(console)/account/payments/editPaymentModal.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
let {
1313
show = $bindable(false),
1414
isLinked = false,
15-
selectedPaymentMethod,
15+
selectedPaymentMethod
1616
}: {
1717
show: boolean;
1818
isLinked?: boolean;
1919
selectedPaymentMethod: PaymentMethodData;
20-
} = $props()
20+
} = $props();
2121
2222
let year: number | null = $state(null);
2323
let month: string | null = $state(null);

src/routes/(console)/organization-[organization]/billing/+page.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
import { Alert } from '@appwrite.io/pink-svelte';
2121
import { goto, invalidate } from '$app/navigation';
2222
import { Dependencies } from '$lib/constants';
23-
import { base } from '$app/paths';
2423
import type { PageData } from './$types';
24+
import { resolve } from '$app/paths';
2525
2626
export let data: PageData;
2727
2828
$: organization = data.organization;
29+
$: baseUrl = resolve('/(console)/organization-[organization]/billing', {
30+
organization: organization.$id
31+
});
2932
3033
onMount(async () => {
3134
if (page.url.searchParams.has('type')) {
@@ -47,7 +50,7 @@
4750
organization.$id,
4851
invoice.clientSecret,
4952
organization.paymentMethodId,
50-
`${base}/organization-${organization.$id}/billing?type=validate-invoice&invoice=${invoice.$id}`
53+
`${baseUrl}?type=validate-invoice&invoice=${invoice.$id}`
5154
);
5255
}
5356
@@ -140,8 +143,7 @@
140143
methods={data?.paymentMethods}
141144
organization={data?.organization}
142145
backupMethod={data.backupPaymentMethod}
143-
primaryMethod={data.primaryPaymentMethod}
144-
/>
146+
primaryMethod={data.primaryPaymentMethod} />
145147

146148
<BillingAddress
147149
organization={data?.organization}

src/routes/(console)/organization-[organization]/billing/+page.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ export const load: PageLoad = async ({ parent, depends, url, route }) => {
8383

8484
// make number
8585
const credits = availableCredit ? availableCredit.available : null;
86-
const {
87-
backup,
88-
primary
89-
} = getOrganizationPaymentMethods(organization, paymentMethods)
86+
const { backup, primary } = getOrganizationPaymentMethods(organization, paymentMethods);
9087

9188
return {
9289
paymentMethods,

src/routes/(console)/organization-[organization]/billing/deleteOrgPayment.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@
6868
bind:error
6969
bind:open={showDelete}
7070
title="Remove payment method"
71-
onSubmit={isBackup ? removeBackupMethod : removeDefaultMethod}
72-
>
71+
onSubmit={isBackup ? removeBackupMethod : removeDefaultMethod}>
7372
<Typography.Text>
7473
Are you sure you want to remove the payment method from <b>{$organization?.name}</b>?
7574
</Typography.Text>

src/routes/(console)/organization-[organization]/billing/replaceCard.svelte

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,29 @@
1313
import { PaymentBoxes } from '$lib/components/billing';
1414
import type { PaymentMethod } from '@stripe/stripe-js';
1515
16-
export let organization: Organization;
17-
export let show = false;
18-
export let isBackup = false;
19-
export let methods: PaymentList;
16+
let {
17+
show = false,
18+
isBackup = false,
19+
methods,
20+
organization
21+
}: {
22+
show?: boolean;
23+
isBackup?: boolean;
24+
methods: PaymentList;
25+
organization: Organization;
26+
} = $props();
2027
21-
let name: string;
22-
let error: string = null;
23-
let selectedPaymentMethodId: string;
24-
let showState: boolean = false;
25-
let state: string = '';
26-
let paymentMethod: PaymentMethod | null = null;
28+
let name: string | null = $state(null);
29+
let error: string | null = $state(null);
30+
let showState: boolean = $state(false);
31+
let countryState: string | null = $state(null);
32+
let paymentMethod: PaymentMethod | null = $state(null);
33+
let selectedPaymentMethodId: string | null = $state(null);
34+
35+
const filteredMethods = $derived(methods?.paymentMethods.filter((method) => !!method?.last4));
36+
const submitEvent = $derived(
37+
isBackup ? Submit.OrganizationBackupPaymentDelete : Submit.OrganizationPaymentDelete
38+
);
2739
2840
onMount(async () => {
2941
if (!organization.paymentMethodId && !organization.backupPaymentMethodId) {
@@ -45,12 +57,12 @@
4557
async function handleSubmit() {
4658
try {
4759
if (selectedPaymentMethodId === '$new') {
48-
if (showState && !state) {
60+
if (showState && !countryState) {
4961
throw Error('Please select a state');
5062
}
5163
let method: PaymentMethodData;
5264
if (showState) {
53-
method = await setPaymentMethod(paymentMethod.id, name, state);
65+
method = await setPaymentMethod(paymentMethod.id, name, countryState);
5466
} else {
5567
const card = await submitStripeCard(name, organization.$id);
5668
if (card && Object.hasOwn(card, 'id')) {
@@ -69,21 +81,17 @@
6981
? await addBackupPaymentMethod(selectedPaymentMethodId)
7082
: await addPaymentMethod(selectedPaymentMethodId);
7183
84+
await invalidate(Dependencies.PAYMENT_METHODS);
85+
7286
addNotification({
7387
type: 'success',
7488
message: `Your ${isBackup ? 'backup' : 'default'} payment method has been updated`
7589
});
76-
await invalidate(Dependencies.PAYMENT_METHODS);
77-
trackEvent(
78-
isBackup ? Submit.OrganizationBackupPaymentDelete : Submit.OrganizationPaymentDelete
79-
);
90+
trackEvent(submitEvent);
8091
show = false;
81-
} catch (e) {
82-
error = e.message;
83-
trackError(
84-
e,
85-
isBackup ? Submit.OrganizationBackupPaymentDelete : Submit.OrganizationPaymentDelete
86-
);
92+
} catch (err) {
93+
error = err.message;
94+
trackError(err, submitEvent);
8795
}
8896
}
8997
@@ -93,8 +101,8 @@
93101
organization.$id,
94102
paymentMethodId
95103
);
96-
} catch (e) {
97-
error = e.message;
104+
} catch (err) {
105+
error = err.message;
98106
}
99107
}
100108
@@ -104,23 +112,21 @@
104112
organization.$id,
105113
paymentMethodId
106114
);
107-
} catch (e) {
108-
error = e.message;
115+
} catch (err) {
116+
error = err.message;
109117
}
110118
}
111-
112-
$: filteredMethods = methods?.paymentMethods.filter((method) => !!method?.last4);
113119
</script>
114120

115121
<FakeModal bind:show bind:error onSubmit={handleSubmit} size="big" title="Replace payment method">
116122
<p class="text">Replace the existing payment method for your organization.</p>
117123

118124
<PaymentBoxes
119-
methods={filteredMethods}
120125
bind:name
121-
bind:paymentMethod
122126
bind:showState
123-
bind:state
127+
bind:paymentMethod
128+
methods={filteredMethods}
129+
bind:state={countryState}
124130
bind:group={selectedPaymentMethodId}
125131
defaultMethod={organization?.paymentMethodId}
126132
backupMethod={organization?.backupPaymentMethodId}

0 commit comments

Comments
 (0)