diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-03 13:37:27 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-03 14:56:30 -0300 |
commit | 4bf1ab8ba924b2a0fc4813814bdeeb66a2928382 (patch) | |
tree | 8052cd83d9935db2c054a58f7d231c528b8dfc0d /packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx | |
parent | 56da180423029a1b53d2be343eed4f073e96dc89 (diff) | |
download | wallet-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/otp_devices/list/index.tsx')
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx index 06a9f4a55..c240b99cb 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx @@ -19,57 +19,53 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { HttpStatusCode, TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util"; import { - ErrorType, - HttpError, + HttpStatusCode, + TalerError, + TalerMerchantApi, + assertUnreachable +} from "@gnu-taler/taler-util"; +import { 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 { useInstanceOtpDevices } from "../../../../hooks/otp.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; } -export default function ListOtpDevices({ - onUnauthorized, - onLoadError, - onCreate, - onSelect, - onNotFound, -}: Props): VNode { - const [position, setPosition] = useState<string | undefined>(undefined); +export default function ListOtpDevices({ onCreate, onSelect }: Props): VNode { + // const [position, setPosition] = useState<string | undefined>(undefined); const { i18n } = useTranslationContext(); const [notif, setNotif] = useState<Notification | undefined>(undefined); const { lib } = useMerchantApiContext(); const { state } = useSessionContext(); - const result = useInstanceOtpDevices({ position }, (id) => setPosition(id)); + const result = useInstanceOtpDevices(); - 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 ( @@ -77,17 +73,16 @@ export default function ListOtpDevices({ <NotificationCard notification={notif} /> <ListPage - devices={result.data.otp_devices} - onLoadMoreBefore={ - result.isReachingStart ? result.loadMorePrev : undefined - } - onLoadMoreAfter={result.isReachingEnd ? result.loadMore : undefined} + devices={result.body} + onLoadMoreBefore={result.isFirstPage ? undefined : result.loadFirst} + onLoadMoreAfter={result.isLastPage ? undefined : result.loadNext} onCreate={onCreate} onSelect={(e) => { onSelect(e.otp_device_id); }} onDelete={(e: TalerMerchantApi.OtpDeviceEntry) => { - return lib.management.deleteOtpDevice(state.token, e.otp_device_id) + return lib.management + .deleteOtpDevice(state.token, e.otp_device_id) .then(() => setNotif({ message: i18n.str`validator delete successfully`, @@ -100,7 +95,7 @@ export default function ListOtpDevices({ type: "ERROR", description: error.message, }), - ) + ); }} /> </Fragment> |