summaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx54
1 files changed, 27 insertions, 27 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx
index 2714c8e02..e1a7f87f0 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx
@@ -13,70 +13,70 @@
You should have received a copy of the GNU General Public License along with
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-import { ErrorType, HttpError, useMerchantApiContext } from "@gnu-taler/web-util/browser";
-import { Fragment, h, VNode } from "preact";
+import { HttpStatusCode, TalerError, assertUnreachable } from "@gnu-taler/taler-util";
+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 { DeleteModal } from "../../../components/modal/index.js";
+import { useSessionContext } from "../../../context/session.js";
import { useInstanceDetails } from "../../../hooks/instance.js";
+import { LoginPage } from "../../login/index.js";
+import { NotFoundPageOrAdminCreate } from "../../notfound/index.js";
import { DetailPage } from "./DetailPage.js";
-import { HttpStatusCode, TalerErrorDetail } from "@gnu-taler/taler-util";
-import { useSessionContext } from "../../../context/session.js";
interface Props {
- onUnauthorized: () => VNode;
- onLoadError: (error: HttpError<TalerErrorDetail>) => VNode;
onUpdate: () => void;
- onNotFound: () => VNode;
onDelete: () => void;
}
export default function Detail({
onUpdate,
- onLoadError,
- onUnauthorized,
onDelete,
- onNotFound,
}: Props): VNode {
const { state } = useSessionContext();
const result = useInstanceDetails();
const [deleting, setDeleting] = useState<boolean>(false);
// const { deleteInstance } = useInstanceAPI();
- const { lib } = useMerchantApiContext();
+ const { lib } = 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 />
+ }
+ case HttpStatusCode.NotFound: {
+ return <NotFoundPageOrAdminCreate />;
+ }
+ default: {
+ assertUnreachable(result)
+ }
+ }
+ }
+
return (
<Fragment>
<DetailPage
- selected={result.data}
+ selected={result.body}
onUpdate={onUpdate}
onDelete={() => setDeleting(true)}
/>
{deleting && (
<DeleteModal
- element={{ name: result.data.name, id: state.instance }}
+ element={{ name: result.body.name, id: state.instance }}
onCancel={() => setDeleting(false)}
onConfirm={async (): Promise<void> => {
if (state.status !== "loggedIn") {
return
}
try {
- await lib.management.deleteCurrentInstance(state.token);
+ await lib.instance.deleteCurrentInstance(state.token);
onDelete();
} catch (error) {
//FIXME: show message error