summaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx51
1 files changed, 22 insertions, 29 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx
index 5b8cf2a5c..5b492e45c 100644
--- a/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx
@@ -19,36 +19,29 @@
* @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 { DeleteModal, PurgeModal } from "../../../components/modal/index.js";
+import { useSessionContext } from "../../../context/session.js";
import { useBackendInstances } from "../../../hooks/instance.js";
import { Notification } from "../../../utils/types.js";
+import { LoginPage } from "../../login/index.js";
import { View } from "./View.js";
-import { useSessionContext } from "../../../context/session.js";
interface Props {
onCreate: () => void;
onUpdate: (id: string) => void;
instances: TalerMerchantApi.Instance[];
- onUnauthorized: () => VNode;
- onNotFound: () => VNode;
- onLoadError: (error: HttpError<TalerErrorDetail>) => VNode;
}
export default function Instances({
- onUnauthorized,
- onLoadError,
- onNotFound,
onCreate,
onUpdate,
}: Props): VNode {
@@ -59,29 +52,29 @@ export default function Instances({
useState<TalerMerchantApi.Instance | null>(null);
const [notif, setNotif] = useState<Notification | undefined>(undefined);
const { i18n } = useTranslationContext();
- const { lib } = useMerchantApiContext();
+ const { lib } = useSessionContext();
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.Unauthorized: {
+ return <LoginPage />
+ }
+ default: {
+ assertUnreachable(result.case)
+ }
+ }
}
return (
<Fragment>
<NotificationCard notification={notif} />
<View
- instances={result.data.instances}
+ instances={result.body.instances}
onDelete={setDeleting}
onCreate={onCreate}
onPurge={setPurging}
@@ -97,7 +90,7 @@ export default function Instances({
return;
}
try {
- await lib.management.deleteInstance(state.token, deleting.id);
+ await lib.instance.deleteInstance(state.token, deleting.id);
// pushNotification({message: 'delete_success', type: 'SUCCESS' })
setNotif({
message: i18n.str`Instance "${deleting.name}" (ID: ${deleting.id}) has been deleted`,
@@ -124,7 +117,7 @@ export default function Instances({
return;
}
try {
- await lib.management.deleteInstance(state.token, purging.id, { purge: true });
+ await lib.instance.deleteInstance(state.token, purging.id, { purge: true });
setNotif({
message: i18n.str`Instance '${purging.name}' (ID: ${purging.id}) has been disabled`,
type: "SUCCESS",