From 237c4e8adae997e84f5fb7a8fe5c03b1148e99dc Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 27 Mar 2024 01:05:10 -0300 Subject: wip #8655 --- .../src/paths/admin/create/CreatePage.tsx | 2 +- .../src/paths/admin/create/index.tsx | 8 +++--- .../src/paths/admin/list/index.tsx | 21 ++++++++++----- .../src/paths/instance/details/index.tsx | 12 ++++++--- .../src/paths/instance/templates/list/index.tsx | 2 +- .../src/paths/instance/token/DetailPage.tsx | 7 +++-- .../src/paths/instance/token/index.tsx | 12 +++++---- .../src/paths/instance/update/index.tsx | 30 +++++++++++++--------- 8 files changed, 57 insertions(+), 37 deletions(-) (limited to 'packages/merchant-backoffice-ui/src/paths') 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(undefined); const { i18n } = useTranslationContext(); const { lib } = useMerchantApiContext(); - const { logIn } = useSessionContext(); + const { state, logIn } = useSessionContext(); return ( @@ -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(null); const [purging, setPurging] = useState(null); - const { deleteInstance, purgeInstance } = useAdminAPI(); const [notif, setNotif] = useState(undefined); const { i18n } = useTranslationContext(); + const { lib } = useMerchantApiContext(); + const { state } = useSessionContext(); if (result.loading) return ; if (!result.ok) { @@ -90,9 +93,12 @@ export default function Instances({ element={deleting} onCancel={() => setDeleting(null)} onConfirm={async (): Promise => { + 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 => { + 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", 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 b76abee30..2714c8e02 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx @@ -13,12 +13,12 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ -import { ErrorType, HttpError } from "@gnu-taler/web-util/browser"; +import { ErrorType, HttpError, useMerchantApiContext } from "@gnu-taler/web-util/browser"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { Loading } from "../../../components/exception/loading.js"; import { DeleteModal } from "../../../components/modal/index.js"; -import { useInstanceAPI, useInstanceDetails } from "../../../hooks/instance.js"; +import { useInstanceDetails } from "../../../hooks/instance.js"; import { DetailPage } from "./DetailPage.js"; import { HttpStatusCode, TalerErrorDetail } from "@gnu-taler/taler-util"; import { useSessionContext } from "../../../context/session.js"; @@ -42,7 +42,8 @@ export default function Detail({ const result = useInstanceDetails(); const [deleting, setDeleting] = useState(false); - const { deleteInstance } = useInstanceAPI(); + // const { deleteInstance } = useInstanceAPI(); + const { lib } = useMerchantApiContext(); if (result.loading) return ; if (!result.ok) { @@ -71,8 +72,11 @@ export default function Detail({ element={{ name: result.data.name, id: state.instance }} onCancel={() => setDeleting(false)} onConfirm={async (): Promise => { + if (state.status !== "loggedIn") { + return + } try { - await deleteInstance(); + await lib.management.deleteCurrentInstance(state.token); onDelete(); } catch (error) { //FIXME: show message error 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 2138d24a4..40ca6ac98 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 @@ -92,7 +92,7 @@ export default function ListTemplates({ /> { if (hasToken) { - const oldToken = - `secret-token:${form.old_token}` as AccessToken; + const oldToken = form.old_token as AccessToken; onClearToken(oldToken); } else { onClearToken(undefined); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/token/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/token/index.tsx index 13b5c45f1..f3c9a52ea 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/token/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/token/index.tsx @@ -13,16 +13,16 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ -import { AccessToken, HttpStatusCode, TalerErrorDetail } from "@gnu-taler/taler-util"; +import { HttpStatusCode, TalerErrorDetail } from "@gnu-taler/taler-util"; import { ErrorType, HttpError, useMerchantApiContext, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; import { Loading } from "../../../components/exception/loading.js"; import { NotificationCard } from "../../../components/menu/index.js"; -import { useInstanceAPI, useInstanceDetails } from "../../../hooks/instance.js"; +import { useSessionContext } from "../../../context/session.js"; +import { useInstanceDetails } from "../../../hooks/instance.js"; import { Notification } from "../../../utils/types.js"; import { DetailPage } from "./DetailPage.js"; -import { useSessionContext } from "../../../context/session.js"; interface Props { onUnauthorized: () => VNode; @@ -43,7 +43,7 @@ export default function Token({ const { lib } = useMerchantApiContext(); const { logIn } = useSessionContext(); const [notif, setNotif] = useState(undefined); - const { clearAccessToken } = useInstanceAPI(); + // const { clearAccessToken } = useInstanceAPI(); const result = useInstanceDetails() if (result.loading) return ; @@ -71,7 +71,9 @@ export default function Token({ hasToken={hasToken} onClearToken={async (currentToken): Promise => { try { - await clearAccessToken(currentToken); + await lib.management.updateCurrentInstanceAuthentication(currentToken, { + method: "external", + }) onChange(); } catch (error) { if (error instanceof Error) { diff --git a/packages/merchant-backoffice-ui/src/paths/instance/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/update/index.tsx index d28ca0555..32e4e149c 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/update/index.tsx @@ -13,11 +13,12 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ -import { HttpStatusCode, TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util"; +import { HttpStatusCode, TalerErrorDetail, TalerMerchantApi, TalerMerchantInstanceHttpClient } from "@gnu-taler/taler-util"; import { ErrorType, HttpError, HttpResponse, + useMerchantApiContext, useTranslationContext, } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; @@ -25,13 +26,12 @@ import { useState } from "preact/hooks"; import { Loading } from "../../../components/exception/loading.js"; import { NotificationCard } from "../../../components/menu/index.js"; import { - useInstanceAPI, useInstanceDetails, useManagedInstanceDetails, - useManagementAPI, } from "../../../hooks/instance.js"; import { Notification } from "../../../utils/types.js"; import { UpdatePage } from "./UpdatePage.js"; +import { useSessionContext } from "../../../context/session.js"; export interface Props { onBack: () => void; @@ -44,19 +44,21 @@ export interface Props { } export default function Update(props: Props): VNode { - const { updateInstance } = useInstanceAPI(); + const { lib } = useMerchantApiContext(); + const updateInstance = lib.management.updateCurrentInstance.bind(lib.management) const result = useInstanceDetails(); - return CommonUpdate(props, result, updateInstance, ); + return CommonUpdate(props, result, updateInstance,); } export function AdminUpdate(props: Props & { instanceId: string }): VNode { - const { updateInstance } = useManagementAPI( - props.instanceId, - ); + const { lib } = useMerchantApiContext(); + const t = lib.instance(props.instanceId) + const updateInstance = lib.instance(props.instanceId).updateCurrentInstance.bind(t) const result = useManagedInstanceDetails(props.instanceId); - return CommonUpdate(props, result, updateInstance, ); + return CommonUpdate(props, result, updateInstance,); } + function CommonUpdate( { onBack, @@ -69,10 +71,11 @@ function CommonUpdate( TalerMerchantApi.QueryInstancesResponse, TalerErrorDetail >, - updateInstance: any, + updateInstance: typeof TalerMerchantInstanceHttpClient.prototype.updateCurrentInstance, ): VNode { const [notif, setNotif] = useState(undefined); const { i18n } = useTranslationContext(); + const { state } = useSessionContext(); if (result.loading) return ; if (!result.ok) { @@ -99,11 +102,14 @@ function CommonUpdate( onUpdate={( d: TalerMerchantApi.InstanceReconfigurationMessage, ): Promise => { - return updateInstance(d) + if (state.status !== "loggedIn") { + return Promise.resolve(); + } + return updateInstance(state.token, d) .then(onConfirm) .catch((error: Error) => setNotif({ - message: i18n.str`Failed to create instance`, + message: i18n.str`Failed to update instance`, type: "ERROR", description: error.message, }), -- cgit v1.2.3