diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx')
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx | 65 |
1 files changed, 46 insertions, 19 deletions
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 8a1f85b1c..787512e2a 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 @@ -26,9 +26,7 @@ import { TalerMerchantApi, assertUnreachable, } from "@gnu-taler/taler-util"; -import { - useTranslationContext -} from "@gnu-taler/web-util/browser"; +import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { VNode, h } from "preact"; import { useState } from "preact/hooks"; import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js"; @@ -64,27 +62,26 @@ export default function OrderList({ onCreate, onSelect }: Props): VNode { const result = useInstanceOrders(filter, (d) => setFilter({ ...filter, position: d }), ); - const { lib } = useSessionContext(); + const { state, lib } = useSessionContext(); const [notif, setNotif] = useState<Notification | undefined>(undefined); const { i18n } = useTranslationContext(); - const { state } = useSessionContext(); if (!result) return <Loading />; if (result instanceof TalerError) { return <ErrorLoadingMerchant error={result} />; } if (result.type === "fail") { - switch(result.case) { + switch (result.case) { case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate />; } case HttpStatusCode.Unauthorized: { - return <LoginPage /> + return <LoginPage />; } default: { - assertUnreachable(result) + assertUnreachable(result); } } } @@ -113,8 +110,8 @@ export default function OrderList({ onCreate, onSelect }: Props): VNode { return resp.type === "ok"; }} onSelect={onSelect} - description={i18n.str`jump to order with the given product ID`} - placeholder={i18n.str`order id`} + description={i18n.str`Jump to order with the given product ID`} + placeholder={i18n.str`Order id`} /> <ListPage @@ -160,17 +157,47 @@ export default function OrderList({ onCreate, onSelect }: Props): VNode { onConfirm={(value) => { lib.instance .addRefund(state.token, orderToBeRefunded.order_id, value) - .then(() => - setNotif({ - message: i18n.str`refund created successfully`, - type: "SUCCESS", - }), - ) + .then((resp) => { + if (resp.type === "ok") { + setNotif({ + message: i18n.str`Refund created successfully`, + type: "SUCCESS", + }); + } else { + switch (resp.case) { + case HttpStatusCode.UnavailableForLegalReasons: { + setNotif({ + message: i18n.str`Could not create the refund`, + type: "ERROR", + description: i18n.str`There are pending KYC requirements.` + }); + return; + } + case HttpStatusCode.Unauthorized: + case HttpStatusCode.Forbidden: + case HttpStatusCode.NotFound: + case HttpStatusCode.Conflict: + case HttpStatusCode.Gone: { + setNotif({ + message: i18n.str`Could not create the refund`, + type: "ERROR", + description: resp.detail?.hint, + }); + return; + } + default: { + assertUnreachable(resp) + } + + } + + } + }) .catch((error) => setNotif({ - message: i18n.str`could not create the refund`, + message: i18n.str`Could not create the refund`, type: "ERROR", - description: error.message, + description: error instanceof Error ? error.message : String(error), }), ) .then(() => setOrderToBeRefunded(undefined)); @@ -208,7 +235,7 @@ function RefundModalForTable({ id, onConfirm, onCancel }: RefundProps): VNode { ); } case HttpStatusCode.Unauthorized: { - return <LoginPage /> + return <LoginPage />; } default: { assertUnreachable(result); |