diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-03 13:37:27 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-03 14:56:30 -0300 |
commit | 4bf1ab8ba924b2a0fc4813814bdeeb66a2928382 (patch) | |
tree | 8052cd83d9935db2c054a58f7d231c528b8dfc0d /packages/merchant-backoffice-ui/src/paths/instance/orders/list | |
parent | 56da180423029a1b53d2be343eed4f073e96dc89 (diff) | |
download | wallet-core-4bf1ab8ba924b2a0fc4813814bdeeb66a2928382.tar.xz |
wip #8655: fixing broken build
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/orders/list')
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/instance/orders/list/ListPage.tsx | 12 | ||||
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx | 196 |
2 files changed, 92 insertions, 116 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/list/ListPage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/list/ListPage.tsx index 7b88985dc..12762c3b3 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/list/ListPage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/list/ListPage.tsx @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { TalerMerchantApi } from "@gnu-taler/taler-util"; +import { AbsoluteTime, TalerMerchantApi } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { format } from "date-fns"; import { Fragment, VNode, h } from "preact"; @@ -43,8 +43,8 @@ export interface ListPageProps { isNotWiredActive: string; isWiredActive: string; - jumpToDate?: Date; - onSelectDate: (date?: Date) => void; + jumpToDate?: AbsoluteTime; + onSelectDate: (date?: AbsoluteTime) => void; orders: (TalerMerchantApi.OrderHistoryEntry & WithId)[]; onLoadMoreBefore?: () => void; @@ -177,7 +177,7 @@ export function ListPage({ class="input" type="text" readonly - value={!jumpToDate ? "" : format(jumpToDate, dateFormatForSettings(settings))} + value={!jumpToDate || jumpToDate.t_ms === "never" ? "" : format(jumpToDate.t_ms, dateFormatForSettings(settings))} placeholder={i18n.str`date (${dateFormatForSettings(settings)})`} onClick={() => { setPickDate(true); @@ -207,7 +207,9 @@ export function ListPage({ <DatePicker opened={pickDate} closeFunction={() => setPickDate(false)} - dateReceiver={onSelectDate} + dateReceiver={(d) => { + onSelectDate(AbsoluteTime.fromMilliseconds(d.getTime())) + }} /> <CardTable diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx index a50f02a2d..7a3fb2d22 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx @@ -19,83 +19,84 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { HttpStatusCode, TalerErrorDetail, TalerMerchantApi, stringifyPayUri } from "@gnu-taler/taler-util"; import { - ErrorType, - HttpError, + AbsoluteTime, + HttpStatusCode, + TalerError, + TalerMerchantApi, + assertUnreachable, +} from "@gnu-taler/taler-util"; +import { useMerchantApiContext, useTranslationContext, } from "@gnu-taler/web-util/browser"; -import { Fragment, VNode, h } from "preact"; +import { VNode, h } from "preact"; import { useState } from "preact/hooks"; +import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js"; import { Loading } from "../../../../components/exception/loading.js"; import { JumpToElementById } from "../../../../components/form/JumpToElementById.js"; import { NotificationCard } from "../../../../components/menu/index.js"; +import { useSessionContext } from "../../../../context/session.js"; import { InstanceOrderFilter, useInstanceOrders, useOrderDetails, } from "../../../../hooks/order.js"; import { Notification } from "../../../../utils/types.js"; +import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { ListPage } from "./ListPage.js"; import { RefundModal } from "./Table.js"; -import { useSessionContext } from "../../../../context/session.js"; interface Props { - onUnauthorized: () => VNode; - onLoadError: (error: HttpError<TalerErrorDetail>) => VNode; - onNotFound: () => VNode; onSelect: (id: string) => void; onCreate: () => void; } -export default function OrderList({ - onUnauthorized, - onLoadError, - onCreate, - onSelect, - onNotFound, -}: Props): VNode { - const [filter, setFilter] = useState<InstanceOrderFilter>({ paid: "no" }); +export default function OrderList({ onCreate, onSelect }: Props): VNode { + const [filter, setFilter] = useState<InstanceOrderFilter>({ paid: false }); const [orderToBeRefunded, setOrderToBeRefunded] = useState< TalerMerchantApi.OrderHistoryEntry | undefined >(undefined); - const setNewDate = (date?: Date): void => + const setNewDate = (date?: AbsoluteTime): void => setFilter((prev) => ({ ...prev, date })); - const result = useInstanceOrders(filter, setNewDate); + const result = useInstanceOrders(filter, (d) => + setFilter({ ...filter, position: d }), + ); const { lib } = useMerchantApiContext(); const [notif, setNotif] = useState<Notification | undefined>(undefined); const { i18n } = useTranslationContext(); - const { state } = useSessionContext() - - if (result.loading) return <Loading />; - if (!result.ok) { - if ( - result.type === ErrorType.CLIENT && - result.status === HttpStatusCode.Unauthorized - ) - return onUnauthorized(); - if ( - result.type === ErrorType.CLIENT && - result.status === HttpStatusCode.NotFound - ) - return onNotFound(); - return onLoadError(result); - } + const { state } = useSessionContext(); - const isNotPaidActive = filter.paid === "no" ? "is-active" : ""; - const isPaidActive = filter.paid === "yes" && filter.wired === undefined ? "is-active" : ""; - const isRefundedActive = filter.refunded === "yes" ? "is-active" : ""; - const isNotWiredActive = filter.wired === "no" && filter.paid === "yes" ? "is-active" : ""; - const isWiredActive = filter.wired === "yes" ? "is-active" : ""; + if (!result) return <Loading />; + if (result instanceof TalerError) { + return <ErrorLoadingMerchant error={result} />; + } + // if (result.type === "fail") { + // switch (result.case) { + // case HttpStatusCode.NotFound: { + // return <NotFoundPageOrAdminCreate />; + // } + // default: { + // assertUnreachable(result.case); + // } + // } + // } + + const isNotPaidActive = filter.paid === false ? "is-active" : ""; + const isPaidActive = + filter.paid === true && filter.wired === undefined ? "is-active" : ""; + const isRefundedActive = filter.refunded === true ? "is-active" : ""; + const isNotWiredActive = + filter.wired === false && filter.paid === true ? "is-active" : ""; + const isWiredActive = filter.wired === true ? "is-active" : ""; const isAllActive = filter.paid === undefined && - filter.refunded === undefined && - filter.wired === undefined + filter.refunded === undefined && + filter.wired === undefined ? "is-active" : ""; @@ -105,11 +106,8 @@ export default function OrderList({ <JumpToElementById testIfExist={async (order) => { - if (state.status !== "loggedIn") { - return false; - } - const resp = await lib.management.getOrder(state.token, order) - return resp.type === "ok" + const resp = await lib.management.getOrderDetails(state.token, order); + return resp.type === "ok"; }} onSelect={onSelect} description={i18n.str`jump to order with the given product ID`} @@ -117,11 +115,11 @@ export default function OrderList({ /> <ListPage - orders={result.data.orders.map((o) => ({ ...o, id: o.order_id }))} - onLoadMoreBefore={result.loadMorePrev} - hasMoreBefore={!result.isReachingStart} - onLoadMoreAfter={result.loadMore} - hasMoreAfter={!result.isReachingEnd} + orders={result.body.map((o) => ({ ...o, id: o.order_id }))} + onLoadMoreBefore={result.loadFirst} + hasMoreBefore={!result.isFirstPage} + onLoadMoreAfter={result.loadNext} + hasMoreAfter={!result.isLastPage} onSelectOrder={(order) => onSelect(order.id)} onRefundOrder={(value) => setOrderToBeRefunded(value)} isAllActive={isAllActive} @@ -131,30 +129,27 @@ export default function OrderList({ isNotPaidActive={isNotPaidActive} isRefundedActive={isRefundedActive} jumpToDate={filter.date} + onSelectDate={setNewDate} onCopyURL={async (id) => { - if (state.status !== "loggedIn") { - return false; - } - const resp = await lib.management.getOrder(state.token, id) + const resp = await lib.management.getOrderDetails(state.token, id); if (resp.type === "ok") { if (resp.body.order_status === "unpaid") { - copyToClipboard(resp.body.taler_pay_uri) + copyToClipboard(resp.body.taler_pay_uri); } else { if (resp.body.contract_terms.fulfillment_url) { - copyToClipboard(resp.body.contract_terms.fulfillment_url) + copyToClipboard(resp.body.contract_terms.fulfillment_url); } } - copyToClipboard(resp.body.order_status) + copyToClipboard(resp.body.order_status); } }} onCreate={onCreate} - onSelectDate={setNewDate} onShowAll={() => setFilter({})} - onShowNotPaid={() => setFilter({ paid: "no" })} - onShowPaid={() => setFilter({ paid: "yes" })} - onShowRefunded={() => setFilter({ refunded: "yes" })} - onShowNotWired={() => setFilter({ wired: "no", paid: "yes" })} - onShowWired={() => setFilter({ wired: "yes" })} + onShowNotPaid={() => setFilter({ paid: false })} + onShowPaid={() => setFilter({ paid: true })} + onShowRefunded={() => setFilter({ refunded: true })} + onShowNotWired={() => setFilter({ wired: false, paid: true })} + onShowWired={() => setFilter({ wired: true })} /> {orderToBeRefunded && ( @@ -162,7 +157,8 @@ export default function OrderList({ id={orderToBeRefunded.order_id} onCancel={() => setOrderToBeRefunded(undefined)} onConfirm={(value) => { - lib.management.addRefund(state.token, orderToBeRefunded.order_id, value) + lib.management + .addRefund(state.token, orderToBeRefunded.order_id, value) .then(() => setNotif({ message: i18n.str`refund created successfully`, @@ -176,27 +172,7 @@ export default function OrderList({ description: error.message, }), ) - .then(() => setOrderToBeRefunded(undefined)) - - }} - onLoadError={(error) => { - setNotif({ - message: i18n.str`could not create the refund`, - type: "ERROR", - description: error.message, - }); - setOrderToBeRefunded(undefined); - return <div />; - }} - onUnauthorized={onUnauthorized} - onNotFound={() => { - setNotif({ - message: i18n.str`could not get the order to refund`, - type: "ERROR", - // description: error.message - }); - setOrderToBeRefunded(undefined); - return <div />; + .then(() => setOrderToBeRefunded(undefined)); }} /> )} @@ -206,41 +182,39 @@ export default function OrderList({ interface RefundProps { id: string; - onUnauthorized: () => VNode; - onLoadError: (error: HttpError<TalerErrorDetail>) => VNode; - onNotFound: () => VNode; onCancel: () => void; onConfirm: (m: TalerMerchantApi.RefundRequest) => void; } -function RefundModalForTable({ - id, - onUnauthorized, - onLoadError, - onNotFound, - onConfirm, - onCancel, -}: RefundProps): VNode { +function RefundModalForTable({ id, onConfirm, onCancel }: RefundProps): VNode { const result = useOrderDetails(id); - if (result.loading) return <Loading />; - if (!result.ok) { - if ( - result.type === ErrorType.CLIENT && - result.status === HttpStatusCode.Unauthorized - ) - return onUnauthorized(); - if ( - result.type === ErrorType.CLIENT && - result.status === HttpStatusCode.NotFound - ) - return onNotFound(); - return onLoadError(result); + if (!result) return <Loading />; + if (result instanceof TalerError) { + return <ErrorLoadingMerchant error={result} />; + } + if (result.type === "fail") { + switch (result.case) { + case HttpStatusCode.NotFound: { + return <NotFoundPageOrAdminCreate />; + } + case HttpStatusCode.BadGateway: { + return <div>Failed to obtain a response from the exchange</div>; + } + case HttpStatusCode.GatewayTimeout: { + return ( + <div>The merchant's interaction with the exchange took too long</div> + ); + } + default: { + assertUnreachable(result); + } + } } return ( <RefundModal - order={result.data} + order={result.body} onCancel={onCancel} onConfirm={onConfirm} /> |