aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/index.tsx
diff options
context:
space:
mode:
authorChristian Blättler <blatc2@bfh.ch>2024-05-07 18:12:20 +0200
committerChristian Blättler <blatc2@bfh.ch>2024-05-07 18:12:20 +0200
commit04447178039569db4da0fd60c819e9fe1bc1df20 (patch)
tree2a93ecf076ddc63218cb676fb7cea1dd9ad31881 /packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/index.tsx
parent7b3157df9746d12f712e6a4604eccc8ed6b7d0c3 (diff)
downloadwallet-core-04447178039569db4da0fd60c819e9fe1bc1df20.tar.xz
update token families code to allign with new standards
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/index.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/index.tsx63
1 files changed, 31 insertions, 32 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/index.tsx
index 4f582d7f3..068235e14 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/index.tsx
@@ -28,59 +28,58 @@ import { Fragment, h, VNode } from "preact";
import { useState } from "preact/hooks";
import { Loading } from "../../../../components/exception/loading.js";
import { NotificationCard } from "../../../../components/menu/index.js";
-import { MerchantBackend, WithId } from "../../../../declaration.js";
import { Notification } from "../../../../utils/types.js";
import { UpdatePage } from "./UpdatePage.js";
-import { HttpStatusCode } from "@gnu-taler/taler-util";
-import { useTokenFamilyAPI, useTokenFamilyDetails } from "../../../../hooks/tokenfamily.js";
+import { HttpStatusCode, TalerError, TalerMerchantApi, assertUnreachable } from "@gnu-taler/taler-util";
+import { useTokenFamilyDetails } from "../../../../hooks/tokenfamily.js";
+import { useSessionContext } from "../../../../context/session.js";
+import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js";
+import { LoginPage } from "../../../login/index.js";
+import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js";
-export type Entity = MerchantBackend.TokenFamilies.TokenFamilyPatchDetail & WithId;
+type Entity = TalerMerchantApi.TokenFamilyUpdateRequest;
interface Props {
onBack?: () => void;
onConfirm: () => void;
- onUnauthorized: () => VNode;
- onNotFound: () => VNode;
- onLoadError: (e: HttpError<MerchantBackend.ErrorDetail>) => VNode;
slug: string;
}
export default function UpdateTokenFamily({
slug,
onConfirm,
onBack,
- onUnauthorized,
- onNotFound,
- onLoadError,
}: Props): VNode {
- const { updateTokenFamily } = useTokenFamilyAPI();
const result = useTokenFamilyDetails(slug);
const [notif, setNotif] = useState<Notification | undefined>(undefined);
+ const { lib, state } = useSessionContext();
const { i18n } = useTranslationContext();
- 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.Unauthorized: {
+ return <LoginPage />
+ }
+ default: {
+ assertUnreachable(result);
+ }
+ }
}
const family: Entity = {
- id: slug,
- name: result.data.name,
- description: result.data.description,
- description_i18n: result.data.description_i18n || {},
- duration: result.data.duration,
- valid_after: result.data.valid_after,
- valid_before: result.data.valid_before,
+ name: result.body.name,
+ description: result.body.description,
+ description_i18n: result.body.description_i18n || {},
+ duration: result.body.duration,
+ valid_after: result.body.valid_after,
+ valid_before: result.body.valid_before,
};
return (
@@ -90,7 +89,7 @@ export default function UpdateTokenFamily({
tokenFamily={family}
onBack={onBack}
onUpdate={(data) => {
- return updateTokenFamily(slug, data)
+ return lib.instance.updateTokenFamily(state.token, slug, data)
.then(onConfirm)
.catch((error) => {
setNotif({