|
28 | 28 | IconExternalLink, |
29 | 29 | IconRefresh |
30 | 30 | } from '@appwrite.io/pink-icons-svelte'; |
| 31 | + import { addNotification } from '$lib/stores/notifications'; |
31 | 32 |
|
32 | 33 | let limit = $state(5); |
33 | 34 | let offset = $state(0); |
|
40 | 41 | const endpoint = getApiEndpoint(); |
41 | 42 | const hasPaymentError = $derived(invoiceList?.invoices.some((invoice) => invoice?.lastError)); |
42 | 43 |
|
43 | | - /** |
44 | | - * Special case handling for the first page! |
45 | | - * |
46 | | - * As per Damodar - `there is some logic to **hide current cycle invoice** in the endpoint`. |
47 | | - * |
48 | | - * Due to this, the first page always loads `limit - 1` invoices which is inconsistent! |
49 | | - * Therefore, we load `limit + 1` to counter that so the returned invoices are consistent. |
50 | | - */ |
51 | | - onMount(() => request(true)); |
| 44 | + onMount(loadInvoices); |
52 | 45 |
|
53 | | - async function request(patchQuery: boolean = false) { |
| 46 | + async function loadInvoices() { |
54 | 47 | isLoadingInvoices = true; |
55 | | - invoiceList = await sdk.forConsole.billing.listInvoices(page.params.organization, [ |
56 | | - Query.orderDesc('$createdAt'), |
57 | | -
|
58 | | - // first page extra must have an extra limit! |
59 | | - Query.limit(patchQuery ? limit + 1 : limit), |
60 | | -
|
61 | | - // so an invoice isn't repeated on 2nd page! |
62 | | - Query.offset(patchQuery ? offset : offset + 1) |
63 | | - ]); |
64 | | -
|
65 | | - isLoadingInvoices = false; |
| 48 | + try { |
| 49 | + invoiceList = await sdk.forConsole.billing.listInvoices(page.params.organization, [ |
| 50 | + Query.orderDesc('$createdAt'), |
| 51 | + Query.limit(limit), |
| 52 | + Query.offset(offset) |
| 53 | + ]); |
| 54 | + } catch (error) { |
| 55 | + addNotification({ |
| 56 | + type: 'error', |
| 57 | + message: error.message |
| 58 | + }); |
| 59 | + } finally { |
| 60 | + isLoadingInvoices = false; |
| 61 | + } |
66 | 62 | } |
67 | 63 |
|
68 | 64 | function retryPayment(invoice: Invoice) { |
|
73 | 69 | $effect(() => { |
74 | 70 | if (page.url.searchParams.get('type') === 'validate-invoice') { |
75 | 71 | window.history.replaceState({}, '', page.url.pathname); |
76 | | - request(); |
| 72 | + loadInvoices(); |
77 | 73 | } |
78 | 74 | }); |
79 | 75 |
|
|
197 | 193 | hidePages |
198 | 194 | bind:offset |
199 | 195 | total={invoiceList.total} |
200 | | - on:change={() => request()} /> |
| 196 | + on:change={loadInvoices} /> |
201 | 197 | </Layout.Stack> |
202 | 198 | {/if} |
203 | 199 | {:else} |
|
0 commit comments