diff options
Diffstat (limited to 'packages/merchant-backoffice/src/paths/instance/orders/list')
4 files changed, 0 insertions, 836 deletions
diff --git a/packages/merchant-backoffice/src/paths/instance/orders/list/List.stories.tsx b/packages/merchant-backoffice/src/paths/instance/orders/list/List.stories.tsx deleted file mode 100644 index 1dbb3f2..0000000 --- a/packages/merchant-backoffice/src/paths/instance/orders/list/List.stories.tsx +++ /dev/null @@ -1,107 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { h, VNode, FunctionalComponent } from "preact"; -import { ListPage as TestedComponent } from "./ListPage"; - -export default { - title: "Pages/Order/List", - component: TestedComponent, - argTypes: { - onShowAll: { action: "onShowAll" }, - onShowPaid: { action: "onShowPaid" }, - onShowRefunded: { action: "onShowRefunded" }, - onShowNotWired: { action: "onShowNotWired" }, - onCopyURL: { action: "onCopyURL" }, - onSelectDate: { action: "onSelectDate" }, - onLoadMoreBefore: { action: "onLoadMoreBefore" }, - onLoadMoreAfter: { action: "onLoadMoreAfter" }, - onSelectOrder: { action: "onSelectOrder" }, - onRefundOrder: { action: "onRefundOrder" }, - onSearchOrderById: { action: "onSearchOrderById" }, - onCreate: { action: "onCreate" }, - }, -}; - -function createExample<Props>( - Component: FunctionalComponent<Props>, - props: Partial<Props> -) { - const r = (args: any) => <Component {...args} />; - r.args = props; - return r; -} - -export const Example = createExample(TestedComponent, { - orders: [ - { - id: "123", - amount: "TESTKUDOS:10", - paid: false, - refundable: true, - row_id: 1, - summary: "summary", - timestamp: { - t_s: new Date().getTime() / 1000, - }, - order_id: "123", - }, - { - id: "234", - amount: "TESTKUDOS:12", - paid: true, - refundable: true, - row_id: 2, - summary: - "summary with long text, very very long text that someone want to add as a description of the order", - timestamp: { - t_s: new Date().getTime() / 1000, - }, - order_id: "234", - }, - { - id: "456", - amount: "TESTKUDOS:1", - paid: false, - refundable: false, - row_id: 3, - summary: - "summary with long text, very very long text that someone want to add as a description of the order", - timestamp: { - t_s: new Date().getTime() / 1000, - }, - order_id: "456", - }, - { - id: "234", - amount: "TESTKUDOS:12", - paid: false, - refundable: false, - row_id: 4, - summary: - "summary with long text, very very long text that someone want to add as a description of the order", - timestamp: { - t_s: new Date().getTime() / 1000, - }, - order_id: "234", - }, - ], -}); diff --git a/packages/merchant-backoffice/src/paths/instance/orders/list/ListPage.tsx b/packages/merchant-backoffice/src/paths/instance/orders/list/ListPage.tsx deleted file mode 100644 index 032801b..0000000 --- a/packages/merchant-backoffice/src/paths/instance/orders/list/ListPage.tsx +++ /dev/null @@ -1,146 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - -/** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ - -import { format } from 'date-fns'; -import { h, VNode } from 'preact'; -import { useState } from 'preact/hooks'; -import { DatePicker } from '../../../../components/picker/DatePicker'; -import { MerchantBackend, WithId } from '../../../../declaration'; -import { Translate, useTranslator } from '../../../../i18n'; -import { CardTable } from './Table'; - -export interface ListPageProps { - errorOrderId: string | undefined, - - onShowAll: () => void, - onShowPaid: () => void, - onShowRefunded: () => void, - onShowNotWired: () => void, - onCopyURL: (id: string) => void; - isAllActive: string, - isPaidActive: string, - isRefundedActive: string, - isNotWiredActive: string, - - jumpToDate?: Date, - onSelectDate: (date?: Date) => void, - - orders: (MerchantBackend.Orders.OrderHistoryEntry & WithId)[]; - onLoadMoreBefore?: () => void; - hasMoreBefore?: boolean; - hasMoreAfter?: boolean; - onLoadMoreAfter?: () => void; - - onSelectOrder: (o: MerchantBackend.Orders.OrderHistoryEntry & WithId) => void; - onRefundOrder: (o: MerchantBackend.Orders.OrderHistoryEntry & WithId) => void; - onSearchOrderById: (id: string) => void; - onCreate: () => void; -} - -export function ListPage({ orders, errorOrderId, isAllActive, onSelectOrder, onRefundOrder, onSearchOrderById, jumpToDate, onCopyURL, onShowAll, onShowPaid, onShowRefunded, onShowNotWired, onSelectDate, isPaidActive, isRefundedActive, isNotWiredActive, onCreate }: ListPageProps): VNode { - const i18n = useTranslator(); - const dateTooltip = i18n`select date to show nearby orders`; - const [pickDate, setPickDate] = useState(false); - const [orderId, setOrderId] = useState<string>(''); - - return <section class="section is-main-section"> - - <div class="level"> - <div class="level-left"> - <div class="level-item"> - <div class="field has-addons"> - <div class="control"> - <input class={errorOrderId ? "input is-danger" : "input"} type="text" value={orderId} onChange={e => setOrderId(e.currentTarget.value)} placeholder={i18n`order id`} /> - {errorOrderId && <p class="help is-danger">{errorOrderId}</p>} - </div> - <span class="has-tooltip-bottom" data-tooltip={i18n`jump to order with the given order ID`}> - <button class="button" onClick={(e) => onSearchOrderById(orderId)}> - <span class="icon"><i class="mdi mdi-arrow-right" /></span> - </button> - </span> - </div> - </div> - </div> - </div> - <div class="columns"> - <div class="column is-two-thirds"> - <div class="tabs" style={{overflow:'inherit'}}> - <ul> - <li class={isAllActive}> - <div class="has-tooltip-right" data-tooltip={i18n`remove all filters`}> - <a onClick={onShowAll}><Translate>All</Translate></a> - </div> - </li> - <li class={isPaidActive}> - <div class="has-tooltip-right" data-tooltip={i18n`only show paid orders`}> - <a onClick={onShowPaid}><Translate>Paid</Translate></a> - </div> - </li> - <li class={isRefundedActive}> - <div class="has-tooltip-right" data-tooltip={i18n`only show orders with refunds`}> - <a onClick={onShowRefunded}><Translate>Refunded</Translate></a> - </div> - </li> - <li class={isNotWiredActive}> - <div class="has-tooltip-left" data-tooltip={i18n`only show orders where customers paid, but wire payments from payment provider are still pending`}> - <a onClick={onShowNotWired}><Translate>Not wired</Translate></a> - </div> - </li> - </ul> - </div> - </div> - <div class="column "> - <div class="buttons is-right"> - <div class="field has-addons"> - {jumpToDate && <div class="control"> - <a class="button" onClick={() => onSelectDate(undefined)}> - <span class="icon" data-tooltip={i18n`clear date filter`}><i class="mdi mdi-close" /></span> - </a> - </div>} - <div class="control"> - <span class="has-tooltip-top" data-tooltip={dateTooltip}> - <input class="input" type="text" readonly value={!jumpToDate ? '' : format(jumpToDate, 'yyyy/MM/dd')} placeholder={i18n`date (YYYY/MM/DD)`} onClick={() => { setPickDate(true); }} /> - </span> - </div> - <div class="control"> - <span class="has-tooltip-left" data-tooltip={dateTooltip}> - <a class="button" onClick={() => { setPickDate(true); }}> - <span class="icon"><i class="mdi mdi-calendar" /></span> - </a> - </span> - </div> - </div> - </div> - </div> - </div> - - <DatePicker - opened={pickDate} - closeFunction={() => setPickDate(false)} - dateReceiver={onSelectDate} /> - - <CardTable orders={orders} - onCreate={onCreate} - onCopyURL={onCopyURL} - onSelect={onSelectOrder} - onRefund={onRefundOrder} /> - </section>; -} diff --git a/packages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx b/packages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx deleted file mode 100644 index 60d5fae..0000000 --- a/packages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx +++ /dev/null @@ -1,412 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { Amounts } from "@gnu-taler/taler-util"; -import { format } from "date-fns"; -import { h, VNode } from "preact"; -import { StateUpdater, useState } from "preact/hooks"; -import { - FormErrors, - FormProvider, -} from "../../../../components/form/FormProvider"; -import { Input } from "../../../../components/form/Input"; -import { InputCurrency } from "../../../../components/form/InputCurrency"; -import { InputGroup } from "../../../../components/form/InputGroup"; -import { InputSelector } from "../../../../components/form/InputSelector"; -import { ConfirmModal } from "../../../../components/modal"; -import { useConfigContext } from "../../../../context/config"; -import { MerchantBackend, WithId } from "../../../../declaration"; -import { Translate, useTranslator } from "../../../../i18n"; -import { mergeRefunds } from "../../../../utils/amount"; - -type Entity = MerchantBackend.Orders.OrderHistoryEntry & WithId; -interface Props { - orders: Entity[]; - onRefund: (value: Entity) => void; - onCopyURL: (id: string) => void; - onCreate: () => void; - onSelect: (order: Entity) => void; - onLoadMoreBefore?: () => void; - hasMoreBefore?: boolean; - hasMoreAfter?: boolean; - onLoadMoreAfter?: () => void; -} - -export function CardTable({ - orders, - onCreate, - onRefund, - onCopyURL, - onSelect, - onLoadMoreAfter, - onLoadMoreBefore, - hasMoreAfter, - hasMoreBefore, -}: Props): VNode { - const [rowSelection, rowSelectionHandler] = useState<string[]>([]); - - const i18n = useTranslator(); - - return ( - <div class="card has-table"> - <header class="card-header"> - <p class="card-header-title"> - <span class="icon"> - <i class="mdi mdi-cash-register" /> - </span> - <Translate>Orders</Translate> - </p> - - <div class="card-header-icon" aria-label="more options" /> - - <div class="card-header-icon" aria-label="more options"> - <span class="has-tooltip-left" data-tooltip={i18n`create order`}> - <button class="button is-info" type="button" onClick={onCreate}> - <span class="icon is-small"> - <i class="mdi mdi-plus mdi-36px" /> - </span> - </button> - </span> - </div> - </header> - <div class="card-content"> - <div class="b-table has-pagination"> - <div class="table-wrapper has-mobile-cards"> - {orders.length > 0 ? ( - <Table - instances={orders} - onSelect={onSelect} - onRefund={onRefund} - onCopyURL={(o) => onCopyURL(o.id)} - rowSelection={rowSelection} - rowSelectionHandler={rowSelectionHandler} - onLoadMoreAfter={onLoadMoreAfter} - onLoadMoreBefore={onLoadMoreBefore} - hasMoreAfter={hasMoreAfter} - hasMoreBefore={hasMoreBefore} - /> - ) : ( - <EmptyTable /> - )} - </div> - </div> - </div> - </div> - ); -} -interface TableProps { - rowSelection: string[]; - instances: Entity[]; - onRefund: (id: Entity) => void; - onCopyURL: (id: Entity) => void; - onSelect: (id: Entity) => void; - rowSelectionHandler: StateUpdater<string[]>; - onLoadMoreBefore?: () => void; - hasMoreBefore?: boolean; - hasMoreAfter?: boolean; - onLoadMoreAfter?: () => void; -} - -function Table({ - instances, - onSelect, - onRefund, - onCopyURL, - onLoadMoreAfter, - onLoadMoreBefore, - hasMoreAfter, - hasMoreBefore, -}: TableProps): VNode { - return ( - <div class="table-container"> - {onLoadMoreBefore && ( - <button - class="button is-fullwidth" - disabled={!hasMoreBefore} - onClick={onLoadMoreBefore} - > - <Translate>load newer orders</Translate> - </button> - )} - <table class="table is-striped is-hoverable is-fullwidth"> - <thead> - <tr> - <th style={{ minWidth: 100 }}> - <Translate>Date</Translate> - </th> - <th style={{ minWidth: 100 }}> - <Translate>Amount</Translate> - </th> - <th style={{ minWidth: 400 }}> - <Translate>Summary</Translate> - </th> - <th style={{ minWidth: 50 }} /> - </tr> - </thead> - <tbody> - {instances.map((i) => { - return ( - <tr key={i.id}> - <td - onClick={(): void => onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.timestamp.t_s === "never" - ? "never" - : format( - new Date(i.timestamp.t_s * 1000), - "yyyy/MM/dd HH:mm:ss" - )} - </td> - <td - onClick={(): void => onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.amount} - </td> - <td - onClick={(): void => onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.summary} - </td> - <td class="is-actions-cell right-sticky"> - <div class="buttons is-right"> - {i.refundable && ( - <button - class="button is-small is-danger jb-modal" - type="button" - onClick={(): void => onRefund(i)} - > - <Translate>Refund</Translate> - </button> - )} - {!i.paid && ( - <button - class="button is-small is-info jb-modal" - type="button" - onClick={(): void => onCopyURL(i)} - > - <Translate>copy url</Translate> - </button> - )} - </div> - </td> - </tr> - ); - })} - </tbody> - </table> - {onLoadMoreAfter && ( - <button - class="button is-fullwidth" - disabled={!hasMoreAfter} - onClick={onLoadMoreAfter} - > - <Translate>load older orders</Translate> - </button> - )} - </div> - ); -} - -function EmptyTable(): VNode { - return ( - <div class="content has-text-grey has-text-centered"> - <p> - <span class="icon is-large"> - <i class="mdi mdi-emoticon-sad mdi-48px" /> - </span> - </p> - <p> - <Translate>No orders have been found matching your query!</Translate> - </p> - </div> - ); -} - -interface RefundModalProps { - onCancel: () => void; - onConfirm: (value: MerchantBackend.Orders.RefundRequest) => void; - order: MerchantBackend.Orders.MerchantOrderStatusResponse; -} - -export function RefundModal({ - order, - onCancel, - onConfirm, -}: RefundModalProps): VNode { - type State = { mainReason?: string; description?: string; refund?: string }; - const [form, setValue] = useState<State>({}); - const i18n = useTranslator(); - // const [errors, setErrors] = useState<FormErrors<State>>({}); - - const refunds = ( - order.order_status === "paid" ? order.refund_details : [] - ).reduce(mergeRefunds, []); - - const config = useConfigContext(); - const totalRefunded = refunds - .map((r) => r.amount) - .reduce( - (p, c) => Amounts.add(p, Amounts.parseOrThrow(c)).amount, - Amounts.getZero(config.currency) - ); - const orderPrice = - order.order_status === "paid" - ? Amounts.parseOrThrow(order.contract_terms.amount) - : undefined; - const totalRefundable = !orderPrice - ? Amounts.getZero(totalRefunded.currency) - : refunds.length - ? Amounts.sub(orderPrice, totalRefunded).amount - : orderPrice; - - const isRefundable = Amounts.isNonZero(totalRefundable); - const duplicatedText = i18n`duplicated`; - - const errors: FormErrors<State> = { - mainReason: !form.mainReason ? i18n`required` : undefined, - description: - !form.description && form.mainReason !== duplicatedText - ? i18n`required` - : undefined, - refund: !form.refund - ? i18n`required` - : !Amounts.parse(form.refund) - ? i18n`invalid format` - : Amounts.cmp(totalRefundable, Amounts.parse(form.refund)!) === -1 - ? i18n`this value exceed the refundable amount` - : undefined, - }; - const hasErrors = Object.keys(errors).some( - (k) => (errors as any)[k] !== undefined - ); - - const validateAndConfirm = () => { - try { - if (!form.refund) return; - onConfirm({ - refund: Amounts.stringify( - Amounts.add(Amounts.parse(form.refund)!, totalRefunded).amount - ), - reason: - form.description === undefined - ? form.mainReason || "" - : `${form.mainReason}: ${form.description}`, - }); - } catch (err) { - console.log(err); - } - }; - - //FIXME: parameters in the translation - return ( - <ConfirmModal - description="refund" - danger - active - disabled={!isRefundable || hasErrors} - onCancel={onCancel} - onConfirm={validateAndConfirm} - > - {refunds.length > 0 && ( - <div class="columns"> - <div class="column is-12"> - <InputGroup - name="asd" - label={`${Amounts.stringify(totalRefunded)} was already refunded`} - > - <table class="table is-fullwidth"> - <thead> - <tr> - <th> - <Translate>date</Translate> - </th> - <th> - <Translate>amount</Translate> - </th> - <th> - <Translate>reason</Translate> - </th> - </tr> - </thead> - <tbody> - {refunds.map((r) => { - return ( - <tr key={r.timestamp.t_s}> - <td> - {r.timestamp.t_s === "never" - ? "never" - : format( - new Date(r.timestamp.t_s * 1000), - "yyyy-MM-dd HH:mm:ss" - )} - </td> - <td>{r.amount}</td> - <td>{r.reason}</td> - </tr> - ); - })} - </tbody> - </table> - </InputGroup> - </div> - </div> - )} - - {isRefundable && ( - <FormProvider<State> - errors={errors} - object={form} - valueHandler={(d) => setValue(d as any)} - > - <InputCurrency<State> - name="refund" - label={i18n`Refund`} - tooltip={i18n`amount to be refunded`} - > - <Translate>Max refundable:</Translate>{" "} - {Amounts.stringify(totalRefundable)} - </InputCurrency> - <InputSelector - name="mainReason" - label={i18n`Reason`} - values={[ - i18n`Choose one...`, - duplicatedText, - i18n`requested by the customer`, - i18n`other`, - ]} - tooltip={i18n`why this order is being refunded`} - /> - {form.mainReason && form.mainReason !== duplicatedText ? ( - <Input<State> - label={i18n`Description`} - name="description" - tooltip={i18n`more information to give context`} - /> - ) : undefined} - </FormProvider> - )} - </ConfirmModal> - ); -} diff --git a/packages/merchant-backoffice/src/paths/instance/orders/list/index.tsx b/packages/merchant-backoffice/src/paths/instance/orders/list/index.tsx deleted file mode 100644 index 47e143f..0000000 --- a/packages/merchant-backoffice/src/paths/instance/orders/list/index.tsx +++ /dev/null @@ -1,171 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - -/** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ - -import { h, VNode, Fragment } from 'preact'; -import { useState } from 'preact/hooks'; -import { Loading } from '../../../../components/exception/loading'; -import { NotificationCard } from '../../../../components/menu'; -import { MerchantBackend, WithId } from '../../../../declaration'; -import { HttpError } from '../../../../hooks/backend'; -import { InstanceOrderFilter, useInstanceOrders, useOrderAPI, useOrderDetails } from '../../../../hooks/order'; -import { useTranslator } from '../../../../i18n'; -import { Notification } from '../../../../utils/types'; -import { RefundModal } from './Table'; -import { ListPage } from './ListPage'; - -interface Props { - onUnauthorized: () => VNode; - onLoadError: (error: HttpError) => VNode; - onNotFound: () => VNode; - onSelect: (id: string) => void; - onCreate: () => void; -} - -export default function ({ onUnauthorized, onLoadError, onCreate, onSelect, onNotFound }: Props): VNode { - const [filter, setFilter] = useState<InstanceOrderFilter>({}) - const [orderToBeRefunded, setOrderToBeRefunded] = useState<MerchantBackend.Orders.OrderHistoryEntry | undefined>(undefined) - - const setNewDate = (date?: Date) => setFilter(prev => ({ ...prev, date })) - - const result = useInstanceOrders(filter, setNewDate) - const { refundOrder, getPaymentURL } = useOrderAPI() - - const [notif, setNotif] = useState<Notification | undefined>(undefined) - - if (result.clientError && result.isUnauthorized) return onUnauthorized() - if (result.clientError && result.isNotfound) return onNotFound() - if (result.loading) return <Loading /> - if (!result.ok) return onLoadError(result) - - const isPaidActive = filter.paid === 'yes' ? "is-active" : '' - const isRefundedActive = filter.refunded === 'yes' ? "is-active" : '' - const isNotWiredActive = filter.wired === 'no' ? "is-active" : '' - const isAllActive = filter.paid === undefined && filter.refunded === undefined && filter.wired === undefined ? 'is-active' : '' - - const i18n = useTranslator() - const [errorOrderId, setErrorOrderId] = useState<string | undefined>(undefined) - - async function testIfOrderExistAndSelect(orderId: string) { - if (!orderId) { - setErrorOrderId(i18n`Enter an order id`) - return; - } - try { - await getPaymentURL(orderId) - onSelect(orderId) - setErrorOrderId(undefined) - } catch { - setErrorOrderId(i18n`order not found`) - } - } - - return <Fragment> - <NotificationCard notification={notif} /> - - <ListPage - orders={result.data.orders.map(o => ({ ...o, id: o.order_id }))} - onLoadMoreBefore={result.loadMorePrev} hasMoreBefore={!result.isReachingStart} - onLoadMoreAfter={result.loadMore} hasMoreAfter={!result.isReachingEnd} - - onSelectOrder={(order) => onSelect(order.id)} - onRefundOrder={(value) => setOrderToBeRefunded(value)} - - errorOrderId={errorOrderId} - isAllActive={isAllActive} - isNotWiredActive={isNotWiredActive} - isPaidActive={isPaidActive} - isRefundedActive={isRefundedActive} - jumpToDate={filter.date} - onCopyURL={(id) => getPaymentURL(id).then((resp) => copyToClipboard(resp.data))} - - onCreate={onCreate} - onSearchOrderById={testIfOrderExistAndSelect} - onSelectDate={setNewDate} - onShowAll={() => setFilter({})} - onShowPaid={() => setFilter({ paid: 'yes' })} - onShowRefunded={() => setFilter({ refunded: 'yes' })} - onShowNotWired={() => setFilter({ wired: 'no' })} - - /> - - {orderToBeRefunded && <RefundModalForTable - id={orderToBeRefunded.order_id} - onCancel={() => setOrderToBeRefunded(undefined)} - onConfirm={(value) => refundOrder(orderToBeRefunded.order_id, value) - .then(() => setNotif({ - message: i18n`refund created successfully`, - type: "SUCCESS" - })) - .catch((error) => setNotif({ - message: i18n`could not create the refund`, - type: "ERROR", - description: error.message - })) - .then(() => setOrderToBeRefunded(undefined))} - onLoadError={(error) => { - setNotif({ - message: i18n`could not create the refund`, - type: "ERROR", - description: error.message - }); - setOrderToBeRefunded(undefined); - return <div />; - }} - onUnauthorized={onUnauthorized} - onNotFound={() => { - setNotif({ - message: i18n`could not get the order to refund`, - type: "ERROR", - // description: error.message - }); - setOrderToBeRefunded(undefined); - return <div />; - }} />} - </Fragment> -} - -interface RefundProps { - id: string; - onUnauthorized: () => VNode; - onLoadError: (error: HttpError) => VNode; - onNotFound: () => VNode; - onCancel: () => void; - onConfirm: (m: MerchantBackend.Orders.RefundRequest) => void; -} - -function RefundModalForTable({ id, onUnauthorized, onLoadError, onNotFound, onConfirm, onCancel }: RefundProps) { - const result = useOrderDetails(id); - - if (result.clientError && result.isUnauthorized) return onUnauthorized() - if (result.clientError && result.isNotfound) return onNotFound() - if (result.loading) return <Loading /> - if (!result.ok) return onLoadError(result) - - return <RefundModal - order={result.data} - onCancel={onCancel} - onConfirm={onConfirm} - /> -} - -async function copyToClipboard(text: string) { - return navigator.clipboard.writeText(text) -} |