summaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-04-03 13:37:27 -0300
committerSebastian <sebasjm@gmail.com>2024-04-03 14:56:30 -0300
commit4bf1ab8ba924b2a0fc4813814bdeeb66a2928382 (patch)
tree8052cd83d9935db2c054a58f7d231c528b8dfc0d /packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx
parent56da180423029a1b53d2be343eed4f073e96dc89 (diff)
downloadwallet-core-4bf1ab8ba924b2a0fc4813814bdeeb66a2928382.tar.gz
wallet-core-4bf1ab8ba924b2a0fc4813814bdeeb66a2928382.tar.bz2
wallet-core-4bf1ab8ba924b2a0fc4813814bdeeb66a2928382.zip
wip #8655: fixing broken builddev/sebasjm/refactor-merchant-2
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx44
1 files changed, 19 insertions, 25 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx
index b9470ddac..9de632218 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx
@@ -19,38 +19,32 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
-import { HttpStatusCode, TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
+import { HttpStatusCode, TalerError, TalerMerchantApi, assertUnreachable } from "@gnu-taler/taler-util";
import {
- ErrorType,
- HttpError,
useMerchantApiContext,
- useTranslationContext,
+ useTranslationContext
} from "@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
import { useState } from "preact/hooks";
+import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js";
import { Loading } from "../../../../components/exception/loading.js";
import { NotificationCard } from "../../../../components/menu/index.js";
+import { useSessionContext } from "../../../../context/session.js";
import { useProductDetails } from "../../../../hooks/product.js";
import { Notification } from "../../../../utils/types.js";
+import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js";
import { UpdatePage } from "./UpdatePage.js";
-import { useSessionContext } from "../../../../context/session.js";
export type Entity = TalerMerchantApi.ProductAddDetail;
interface Props {
onBack?: () => void;
onConfirm: () => void;
- onUnauthorized: () => VNode;
- onNotFound: () => VNode;
- onLoadError: (e: HttpError<TalerErrorDetail>) => VNode;
pid: string;
}
export default function UpdateProduct({
pid,
onConfirm,
onBack,
- onUnauthorized,
- onNotFound,
- onLoadError,
}: Props): VNode {
const result = useProductDetails(pid);
const [notif, setNotif] = useState<Notification | undefined>(undefined);
@@ -59,26 +53,26 @@ export default function UpdateProduct({
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 />;
+ }
+ default: {
+ assertUnreachable(result.case);
+ }
+ }
}
return (
<Fragment>
<NotificationCard notification={notif} />
<UpdatePage
- product={{ ...result.data, product_id: pid }}
+ product={{ ...result.body, product_id: pid }}
onBack={onBack}
onUpdate={(data) => {
return lib.management.updateProduct(state.token, pid, data)