diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx')
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx index b28e59b29..c7edce834 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx @@ -18,9 +18,7 @@ import { TalerError, assertUnreachable, } from "@gnu-taler/taler-util"; -import { - useTranslationContext -} from "@gnu-taler/web-util/browser"; +import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js"; @@ -41,8 +39,7 @@ export interface Props { export default function Update({ oid, onBack }: Props): VNode { const result = useOrderDetails(oid); const [notif, setNotif] = useState<Notification | undefined>(undefined); - const { lib: api } = useSessionContext(); - const { state } = useSessionContext(); + const { state, lib } = useSessionContext(); const { i18n } = useTranslationContext(); @@ -64,7 +61,7 @@ export default function Update({ oid, onBack }: Props): VNode { ); } case HttpStatusCode.Unauthorized: { - return <LoginPage /> + return <LoginPage />; } default: { assertUnreachable(result); @@ -83,19 +80,47 @@ export default function Update({ oid, onBack }: Props): VNode { if (state.status !== "loggedIn") { return; } - api.instance + lib.instance .addRefund(state.token, 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), }), ); }} |