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.tsx53
1 files changed, 23 insertions, 30 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 adbfb93cd..5a8be71b0 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
@@ -19,15 +19,14 @@
* @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 { VNode, h } from "preact";
import { useState } from "preact/hooks";
+import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js";
import { Loading } from "../../../../components/exception/loading.js";
import { JumpToElementById } from "../../../../components/form/JumpToElementById.js";
import { NotificationCard } from "../../../../components/menu/index.js";
@@ -37,12 +36,10 @@ import {
useInstanceTemplates
} from "../../../../hooks/templates.js";
import { Notification } from "../../../../utils/types.js";
+import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js";
import { ListPage } from "./ListPage.js";
interface Props {
- onUnauthorized: () => VNode;
- onLoadError: (error: HttpError<TalerErrorDetail>) => VNode;
- onNotFound: () => VNode;
onCreate: () => void;
onSelect: (id: string) => void;
onNewOrder: (id: string) => void;
@@ -50,36 +47,32 @@ interface Props {
}
export default function ListTemplates({
- onUnauthorized,
- onLoadError,
onCreate,
onQR,
onSelect,
onNewOrder,
- onNotFound,
}: Props): VNode {
- const [position, setPosition] = useState<string | undefined>(undefined);
const { i18n } = useTranslationContext();
const [notif, setNotif] = useState<Notification | undefined>(undefined);
const { lib } = useMerchantApiContext();
- const result = useInstanceTemplates({ position }, (id) => setPosition(id));
+ const result = useInstanceTemplates();
const [deleting, setDeleting] =
useState<TalerMerchantApi.TemplateEntry | null>(null);
const { state } = useSessionContext();
- 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 (
@@ -88,7 +81,7 @@ export default function ListTemplates({
<JumpToElementById
testIfExist={async (id) => {
- const resp = await lib.management.getTemplate(state.token, id)
+ const resp = await lib.management.getTemplateDetails(state.token, id)
return resp.type === "ok"
}}
onSelect={onSelect}
@@ -97,11 +90,11 @@ export default function ListTemplates({
/>
<ListPage
- templates={result.data.templates}
+ templates={result.body}
onLoadMoreBefore={
- result.isReachingStart ? result.loadMorePrev : undefined
+ result.isFirstPage ? undefined: result.loadFirst
}
- onLoadMoreAfter={result.isReachingEnd ? result.loadMore : undefined}
+ onLoadMoreAfter={result.isLastPage ? undefined : result.loadNext}
onCreate={onCreate}
onSelect={(e) => {
onSelect(e.template_id);