|
7 | 7 | import type { Invoice, InvoiceList } from '$lib/sdk/billing';
|
8 | 8 | import { getApiEndpoint, sdk } from '$lib/stores/sdk';
|
9 | 9 | import { Query } from '@appwrite.io/console';
|
10 |
| - import { onMount } from 'svelte'; |
11 | 10 | import { trackEvent } from '$lib/actions/analytics';
|
12 | 11 | import { selectedInvoice, showRetryModal } from './store';
|
13 | 12 | import {
|
|
28 | 27 | IconRefresh
|
29 | 28 | } from '@appwrite.io/pink-icons-svelte';
|
30 | 29 |
|
31 |
| - let offset = 0; |
32 |
| - let invoiceList: InvoiceList = { |
| 30 | + let offset = $state(0); |
| 31 | + let invoiceList: InvoiceList = $state({ |
33 | 32 | invoices: [],
|
34 | 33 | total: 0
|
35 |
| - }; |
| 34 | + }); |
36 | 35 |
|
37 | 36 | const limit = 5;
|
38 | 37 | const endpoint = getApiEndpoint();
|
39 | 38 |
|
40 |
| - onMount(request); |
41 |
| -
|
42 | 39 | async function request() {
|
43 |
| - // isLoadingInvoices = true; |
44 | 40 | invoiceList = await sdk.forConsole.billing.listInvoices(page.params.organization, [
|
45 | 41 | Query.limit(limit),
|
46 | 42 | Query.offset(offset),
|
47 | 43 | Query.orderDesc('$createdAt')
|
48 | 44 | ]);
|
49 | 45 | }
|
50 | 46 |
|
51 |
| - $: if (page.url.searchParams.get('type') === 'validate-invoice') { |
52 |
| - window.history.replaceState({}, '', page.url.pathname); |
53 |
| - request(); |
54 |
| - } |
55 |
| -
|
56 | 47 | function retryPayment(invoice: Invoice) {
|
57 | 48 | $selectedInvoice = invoice;
|
58 | 49 | $showRetryModal = true;
|
59 | 50 | }
|
60 | 51 |
|
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 | + }); |
64 | 60 |
|
65 |
| - $: hasPaymentError = invoiceList?.invoices.some((invoice) => invoice?.lastError); |
| 61 | + $effect(() => { |
| 62 | + if (offset !== null) { |
| 63 | + request(); |
| 64 | + } |
| 65 | + }); |
66 | 66 | </script>
|
67 | 67 |
|
68 | 68 | <CardGrid>
|
|
0 commit comments