summaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx15
1 files changed, 10 insertions, 5 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx
index 40ca6ac98..adbfb93cd 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/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 { Fragment, 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 {
- useInstanceTemplates,
- useTemplateAPI,
+ useInstanceTemplates
} from "../../../../hooks/templates.js";
import { Notification } from "../../../../utils/types.js";
import { ListPage } from "./ListPage.js";
@@ -60,10 +61,11 @@ export default function ListTemplates({
const [position, setPosition] = useState<string | undefined>(undefined);
const { i18n } = useTranslationContext();
const [notif, setNotif] = useState<Notification | undefined>(undefined);
- const { deleteTemplate, testTemplateExist } = useTemplateAPI();
+ const { lib } = useMerchantApiContext();
const result = useInstanceTemplates({ position }, (id) => setPosition(id));
const [deleting, setDeleting] =
useState<TalerMerchantApi.TemplateEntry | null>(null);
+ const { state } = useSessionContext();
if (result.loading) return <Loading />;
if (!result.ok) {
@@ -85,7 +87,10 @@ export default function ListTemplates({
<NotificationCard notification={notif} />
<JumpToElementById
- testIfExist={testTemplateExist}
+ testIfExist={async (id) => {
+ const resp = await lib.management.getTemplate(state.token, id)
+ return resp.type === "ok"
+ }}
onSelect={onSelect}
description={i18n.str`jump to template with the given template ID`}
placeholder={i18n.str`template id`}
@@ -122,7 +127,7 @@ export default function ListTemplates({
onCancel={() => setDeleting(null)}
onConfirm={async (): Promise<void> => {
try {
- await deleteTemplate(deleting.template_id);
+ await lib.management.deleteTemplate(state.token, deleting.template_id);
setNotif({
message: i18n.str`Template "${deleting.template_description}" (ID: ${deleting.template_id}) has been deleted`,
type: "SUCCESS",