aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/products/list
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-03-29 16:52:25 -0300
committerSebastian <sebasjm@gmail.com>2024-03-29 16:52:40 -0300
commitc3cba95a9fd88eb77fd18263287d3a63a9f757e2 (patch)
tree5d05bc48742c0984d8d0aff3a4c2a94c54332803 /packages/merchant-backoffice-ui/src/paths/instance/products/list
parent81f87ede72ada7e7f313b9a4212e0c75c5f54ac9 (diff)
downloadwallet-core-c3cba95a9fd88eb77fd18263287d3a63a9f757e2.tar.xz
wip #8655
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/products/list')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/products/list/index.tsx47
1 files changed, 26 insertions, 21 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/products/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/products/list/index.tsx
index 1017a9334..dc2e08d91 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/products/list/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/products/list/index.tsx
@@ -23,6 +23,7 @@ import { HttpStatusCode, TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/t
import {
ErrorType,
HttpError,
+ useMerchantApiContext,
useTranslationContext,
} from "@gnu-taler/web-util/browser";
import { VNode, h } from "preact";
@@ -31,9 +32,9 @@ import { Loading } from "../../../../components/exception/loading.js";
import { JumpToElementById } from "../../../../components/form/JumpToElementById.js";
import { NotificationCard } from "../../../../components/menu/index.js";
import { ConfirmModal } from "../../../../components/modal/index.js";
+import { useSessionContext } from "../../../../context/session.js";
import {
- useInstanceProducts,
- useProductAPI,
+ useInstanceProducts
} from "../../../../hooks/product.js";
import { Notification } from "../../../../utils/types.js";
import { CardTable } from "./Table.js";
@@ -53,7 +54,8 @@ export default function ProductList({
onNotFound,
}: Props): VNode {
const result = useInstanceProducts();
- const { deleteProduct, updateProduct, getProduct } = useProductAPI();
+ const { lib } = useMerchantApiContext();
+ const { state } = useSessionContext();
const [deleting, setDeleting] =
useState<TalerMerchantApi.ProductDetail & WithId | null>(null);
const [notif, setNotif] = useState<Notification | undefined>(undefined);
@@ -80,7 +82,10 @@ export default function ProductList({
<NotificationCard notification={notif} />
<JumpToElementById
- testIfExist={getProduct}
+ testIfExist={async (id) => {
+ const resp = await lib.management.getProduct(state.token, id);
+ return resp.type === "ok";
+ }}
onSelect={onSelect}
description={i18n.str`jump to product with the given product ID`}
placeholder={i18n.str`product id`}
@@ -89,22 +94,22 @@ export default function ProductList({
<CardTable
instances={result.data}
onCreate={onCreate}
- onUpdate={(id, prod) =>
- updateProduct(id, prod)
- .then(() =>
- setNotif({
- message: i18n.str`product updated successfully`,
- type: "SUCCESS",
- }),
- )
- .catch((error) =>
- setNotif({
- message: i18n.str`could not update the product`,
- type: "ERROR",
- description: error.message,
- }),
- )
- }
+ onUpdate={async (id, prod) => {
+ try {
+ await lib.management.updateProduct(state.token, id, prod);
+ setNotif({
+ message: i18n.str`product updated successfully`,
+ type: "SUCCESS",
+ });
+ } catch (error) {
+ setNotif({
+ message: i18n.str`could not update the product`,
+ type: "ERROR",
+ description: error instanceof Error ? error.message : undefined,
+ });
+ }
+ return
+ }}
onSelect={(product) => onSelect(product.id)}
onDelete={(prod: TalerMerchantApi.ProductDetail & WithId) =>
setDeleting(prod)
@@ -120,7 +125,7 @@ export default function ProductList({
onCancel={() => setDeleting(null)}
onConfirm={async (): Promise<void> => {
try {
- await deleteProduct(deleting.id);
+ await lib.management.deleteProduct(state.token, deleting.id);
setNotif({
message: i18n.str`Product "${deleting.description}" (ID: ${deleting.id}) has been deleted`,
type: "SUCCESS",