diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/admin')
3 files changed, 20 insertions, 11 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx index 731ea8939..d53d93e8b 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx @@ -123,7 +123,7 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode { newValue.auth_token = undefined; newValue.auth = newToken === null || newToken === undefined ? { method: "external" } - : { method: "token", token: `secret-token:${newToken}` }; + : { method: "token", token: newToken }; if (!newValue.address) newValue.address = {}; if (!newValue.jurisdiction) newValue.jurisdiction = {}; // remove above use conversion diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx index 0e8ea1f5b..431015d6f 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx @@ -26,7 +26,6 @@ import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; import { NotificationCard } from "../../../components/menu/index.js"; import { useSessionContext } from "../../../context/session.js"; -import { useAdminAPI } from "../../../hooks/instance.js"; import { Notification } from "../../../utils/types.js"; import { CreatePage } from "./CreatePage.js"; @@ -38,11 +37,10 @@ interface Props { export type Entity = TalerMerchantApi.InstanceConfigurationMessage; export default function Create({ onBack, onConfirm, forceId }: Props): VNode { - const { createInstance } = useAdminAPI(); const [notif, setNotif] = useState<Notification | undefined>(undefined); const { i18n } = useTranslationContext(); const { lib } = useMerchantApiContext(); - const { logIn } = useSessionContext(); + const { state, logIn } = useSessionContext(); return ( <Fragment> @@ -54,9 +52,11 @@ export default function Create({ onBack, onConfirm, forceId }: Props): VNode { onCreate={async ( d: TalerMerchantApi.InstanceConfigurationMessage, ) => { + if (state.status !== "loggedIn") return; try { - await createInstance(d); + await lib.management.createInstance(state.token, d); if (d.auth.token) { + //if auth has been updated, request a new access token const result = await lib.authenticate.createAccessTokenBearer( d.auth.token, { 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 d3fa78b65..5b8cf2a5c 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/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"; @@ -30,9 +31,10 @@ import { useState } from "preact/hooks"; import { Loading } from "../../../components/exception/loading.js"; import { NotificationCard } from "../../../components/menu/index.js"; import { DeleteModal, PurgeModal } from "../../../components/modal/index.js"; -import { useAdminAPI, useBackendInstances } from "../../../hooks/instance.js"; +import { useBackendInstances } from "../../../hooks/instance.js"; import { Notification } from "../../../utils/types.js"; import { View } from "./View.js"; +import { useSessionContext } from "../../../context/session.js"; interface Props { onCreate: () => void; @@ -55,9 +57,10 @@ export default function Instances({ useState<TalerMerchantApi.Instance | null>(null); const [purging, setPurging] = useState<TalerMerchantApi.Instance | null>(null); - const { deleteInstance, purgeInstance } = useAdminAPI(); const [notif, setNotif] = useState<Notification | undefined>(undefined); const { i18n } = useTranslationContext(); + const { lib } = useMerchantApiContext(); + const { state } = useSessionContext(); if (result.loading) return <Loading />; if (!result.ok) { @@ -90,9 +93,12 @@ export default function Instances({ element={deleting} onCancel={() => setDeleting(null)} onConfirm={async (): Promise<void> => { + if (state.status !== "loggedIn") { + return; + } try { - await deleteInstance(deleting.id); - // pushNotification({ message: 'delete_success', type: 'SUCCESS' }) + await lib.management.deleteInstance(state.token, deleting.id); + // pushNotification({message: 'delete_success', type: 'SUCCESS' }) setNotif({ message: i18n.str`Instance "${deleting.name}" (ID: ${deleting.id}) has been deleted`, type: "SUCCESS", @@ -103,7 +109,7 @@ export default function Instances({ type: "ERROR", description: error instanceof Error ? error.message : undefined, }); - // pushNotification({ message: 'delete_error', type: 'ERROR' }) + // pushNotification({message: 'delete_error', type: 'ERROR' }) } setDeleting(null); }} @@ -114,8 +120,11 @@ export default function Instances({ element={purging} onCancel={() => setPurging(null)} onConfirm={async (): Promise<void> => { + if (state.status !== "loggedIn") { + return; + } try { - await purgeInstance(purging.id); + await lib.management.deleteInstance(state.token, purging.id, { purge: true }); setNotif({ message: i18n.str`Instance '${purging.name}' (ID: ${purging.id}) has been disabled`, type: "SUCCESS", |