JezK
Edit File: sc-invoices-list.cjs.entry.js.map
{"file":"sc-invoices-list.entry.cjs.js","mappings":";;;;;;;;;;;AAAA,MAAM,iBAAiB,GAAG,m3BAAm3B,CAAC;AAC94B,6BAAe,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8ECwDC,UAAE;;;;;;;;;;;;;8EAYF,UAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8KAuDM,UAAE;;;;;;;;;;;;;;;;;;;;;;6JA4BmB,eAAO,CAAC,UAAE;;;;;;;;;;;;;;;2UA8BxB,UAAE,+PAI0B,eAAO,CAAC,UAAE,6CAA6C,UAAE,6BACxH,UAAE;;;;;;;;","names":[],"sources":["src/components/controllers/dashboard/invoices-list/sc-invoices-list.scss?tag=sc-invoices-list&encapsulation=shadow","src/components/controllers/dashboard/invoices-list/sc-invoices-list.tsx"],"sourcesContent":[":host {\n display: block;\n}\n.orders-list {\n display: grid;\n gap: 0.75em;\n\n &__heading {\n display: flex;\n flex-wrap: wrap;\n align-items: flex-end;\n justify-content: space-between;\n }\n\n &__title {\n font-size: var(--sc-font-size-x-large);\n font-weight: var(--sc-font-weight-bold);\n line-height: var(--sc-line-height-dense);\n }\n\n a {\n text-decoration: none;\n font-weight: var(--sc-font-weight-semibold);\n display: inline-flex;\n align-items: center;\n gap: 0.25em;\n color: var(--sc-color-primary-500);\n }\n}\n\n.order__row {\n color: var(--sc-color-gray-800);\n text-decoration: none;\n display:grid;\n align-items:center;\n justify-content: space-between;\n gap: 0;\n grid-template-columns: 1fr 1fr 1fr auto;\n margin:0;\n padding: var(--sc-spacing-small) var(--sc-spacing-large);\n\n &:not(:last-child) {\n border-bottom: 1px solid var(--sc-color-gray-200);\n }\n\n &:hover {\n background: var(--sc-color-gray-50);\n }\n}\n\n.order__date {\n font-weight: var(--sc-font-weight-semibold);\n}\n\n.order__row {\n\n}\n","import { Component, Element, h, Prop, State } from '@stencil/core';\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { addQueryArgs } from '@wordpress/url';\n\nimport apiFetch from '../../../../functions/fetch';\nimport { onFirstVisible } from '../../../../functions/lazy';\nimport { Checkout, Invoice, Order } from '../../../../types';\n\n@Component({\n tag: 'sc-invoices-list',\n styleUrl: 'sc-invoices-list.scss',\n shadow: true,\n})\nexport class ScInvoicesList {\n @Element() el: HTMLScInvoicesListElement;\n /** Query to fetch invoices */\n @Prop({ mutable: true }) query: {\n page: number;\n per_page: number;\n } = {\n page: 1,\n per_page: 10,\n };\n @Prop() allLink: string;\n @Prop() heading: string;\n @Prop() isCustomer: boolean;\n\n @State() invoices: Array<Invoice> = [];\n\n /** Loading state */\n @State() loading: boolean;\n @State() busy: boolean;\n\n /** Error message */\n @State() error: string;\n\n @State() pagination: {\n total: number;\n total_pages: number;\n } = {\n total: 0,\n total_pages: 0,\n };\n\n /** Only fetch if visible */\n componentWillLoad() {\n onFirstVisible(this.el, () => {\n this.initialFetch();\n });\n }\n\n async initialFetch() {\n try {\n this.loading = true;\n await this.getInvoices();\n } catch (e) {\n console.error(this.error);\n this.error = e?.message || __('Something went wrong', 'surecart');\n } finally {\n this.loading = false;\n }\n }\n\n async fetchInvoices() {\n try {\n this.busy = true;\n await this.getInvoices();\n } catch (e) {\n console.error(this.error);\n this.error = e?.message || __('Something went wrong', 'surecart');\n } finally {\n this.busy = false;\n }\n }\n\n /** Get all invoices */\n async getInvoices() {\n if (!this.isCustomer) {\n return;\n }\n const response = (await await apiFetch({\n path: addQueryArgs(`surecart/v1/invoices/`, {\n expand: ['checkout'],\n ...this.query,\n }),\n parse: false,\n })) as Response;\n this.pagination = {\n total: parseInt(response.headers.get('X-WP-Total')),\n total_pages: parseInt(response.headers.get('X-WP-TotalPages')),\n };\n this.invoices = (await response.json()) as Invoice[];\n return this.invoices;\n }\n\n nextPage() {\n this.query.page = this.query.page + 1;\n this.fetchInvoices();\n }\n\n prevPage() {\n this.query.page = this.query.page - 1;\n this.fetchInvoices();\n }\n\n renderLoading() {\n return (\n <sc-card noPadding>\n <sc-stacked-list>\n <sc-stacked-list-row style={{ '--columns': '4' }} mobile-size={500}>\n {[...Array(4)].map(() => (\n <sc-skeleton style={{ width: '100px', display: 'inline-block' }}></sc-skeleton>\n ))}\n </sc-stacked-list-row>\n </sc-stacked-list>\n </sc-card>\n );\n }\n\n renderEmpty() {\n return (\n <div>\n <sc-divider style={{ '--spacing': '0' }}></sc-divider>\n <slot name=\"empty\">\n <sc-empty icon=\"shopping-bag\">{__(\"You don't have any invoices.\", 'surecart')}</sc-empty>\n </slot>\n </div>\n );\n }\n\n getInvoiceRedirectUrl(invoice: Invoice) {\n // if it's open, redirect to checkout for payment.\n if (invoice.status === 'open') {\n return `${window.scData.pages.checkout}?checkout_id=${(invoice?.checkout as Checkout)?.id}`;\n }\n\n // else it's paid(as we're fetching only open/paid), redirect to order detail page.\n return addQueryArgs(window.location.href, {\n action: 'show',\n model: 'order',\n id: ((invoice?.checkout as Checkout)?.order as Order)?.id,\n });\n }\n\n renderList() {\n return this.invoices.map(invoice => {\n const { checkout, due_date_date } = invoice;\n if (!checkout) return null;\n const { amount_due_display_amount } = checkout as Checkout;\n return (\n <sc-stacked-list-row href={this.getInvoiceRedirectUrl(invoice)} style={{ '--columns': '4' }} mobile-size={500}>\n <div>#{invoice?.order_number}</div>\n <div>{due_date_date && invoice?.status === 'open' ? sprintf(__('Due %s', 'surecart'), due_date_date) : '—'}</div>\n <div class=\"invoices-list__status\">\n <sc-invoice-status-badge status={invoice?.status}></sc-invoice-status-badge>\n </div>\n <div>{amount_due_display_amount}</div>\n </sc-stacked-list-row>\n );\n });\n }\n\n renderContent() {\n if (this.loading) {\n return this.renderLoading();\n }\n\n if (this.invoices?.length === 0) {\n return this.renderEmpty();\n }\n\n return (\n <sc-card no-padding>\n <sc-stacked-list>{this.renderList()}</sc-stacked-list>\n </sc-card>\n );\n }\n\n render() {\n return (\n <sc-dashboard-module class=\"invoices-list\" error={this.error}>\n <span slot=\"heading\">\n <slot name=\"heading\">{this.heading || __('Invoices', 'surecart')}</slot>\n </span>\n\n {!!this.allLink && !!this.invoices?.length && (\n <sc-button type=\"link\" href={this.allLink} slot=\"end\" aria-label={sprintf(__('View all %s', 'surecart'), this.heading || __('Invoices', 'surecart'))}>\n {__('View all', 'surecart')}\n <sc-icon aria-hidden=\"true\" name=\"chevron-right\" slot=\"suffix\"></sc-icon>\n </sc-button>\n )}\n\n {this.renderContent()}\n\n {!this.allLink && (\n <sc-pagination\n page={this.query.page}\n perPage={this.query.per_page}\n total={this.pagination.total}\n totalPages={this.pagination.total_pages}\n totalShowing={this?.invoices?.length}\n onScNextPage={() => this.nextPage()}\n onScPrevPage={() => this.prevPage()}\n ></sc-pagination>\n )}\n\n {this.busy && <sc-block-ui></sc-block-ui>}\n </sc-dashboard-module>\n );\n }\n}\n"],"version":3}