Skip to content

Commit 0f95f1d

Browse files
Convert state management to use Svelte signals
1 parent 0b7a64c commit 0f95f1d

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import type { Invoice, InvoiceList } from '$lib/sdk/billing';
88
import { getApiEndpoint, sdk } from '$lib/stores/sdk';
99
import { Query } from '@appwrite.io/console';
10-
import { onMount } from 'svelte';
1110
import { trackEvent } from '$lib/actions/analytics';
1211
import { selectedInvoice, showRetryModal } from './store';
1312
import {
@@ -28,41 +27,42 @@
2827
IconRefresh
2928
} from '@appwrite.io/pink-icons-svelte';
3029
31-
let offset = 0;
32-
let invoiceList: InvoiceList = {
30+
let offset = $state(0);
31+
let invoiceList: InvoiceList = $state({
3332
invoices: [],
3433
total: 0
35-
};
34+
});
3635
3736
const limit = 5;
3837
const endpoint = getApiEndpoint();
3938
40-
onMount(request);
41-
4239
async function request() {
43-
// isLoadingInvoices = true;
4440
invoiceList = await sdk.forConsole.billing.listInvoices(page.params.organization, [
4541
Query.limit(limit),
4642
Query.offset(offset),
4743
Query.orderDesc('$createdAt')
4844
]);
4945
}
5046
51-
$: if (page.url.searchParams.get('type') === 'validate-invoice') {
52-
window.history.replaceState({}, '', page.url.pathname);
53-
request();
54-
}
55-
5647
function retryPayment(invoice: Invoice) {
5748
$selectedInvoice = invoice;
5849
$showRetryModal = true;
5950
}
6051
61-
$: if (offset !== null) {
62-
request();
63-
}
52+
const hasPaymentError = $derived(invoiceList?.invoices.some((invoice) => invoice?.lastError));
53+
54+
$effect(() => {
55+
if (page.url.searchParams.get('type') === 'validate-invoice') {
56+
window.history.replaceState({}, '', page.url.pathname);
57+
request();
58+
}
59+
});
6460
65-
$: hasPaymentError = invoiceList?.invoices.some((invoice) => invoice?.lastError);
61+
$effect(() => {
62+
if (offset !== null) {
63+
request();
64+
}
65+
});
6666
</script>
6767

6868
<CardGrid>

0 commit comments

Comments
 (0)