taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit c70c2851d4bd2b2661969b3a7926b2377655cd6b
parent b2a86eed8fad115643a2e82bf4ad042aa98ce793
Author: Florian Dold <florian@dold.me>
Date:   Tue, 27 Aug 2024 00:07:27 +0200

auditor SPA: formatting, fix baseUrl

Diffstat:
Mpackages/auditor-backoffice-ui/src/ApplicationReadyRoutes.tsx | 74++++++++++++++++++++++++++++++++++----------------------------------------
Mpackages/auditor-backoffice-ui/src/InstanceRoutes.tsx | 7+------
Mpackages/auditor-backoffice-ui/src/context/backend.ts | 43++++++++++++++++++-------------------------
Mpackages/auditor-backoffice-ui/src/hooks/backend.ts | 5+----
Mpackages/auditor-backoffice-ui/src/hooks/index.ts | 8++++----
Mpackages/auditor-backoffice-ui/src/paths/finance/index.tsx | 31++++++++++++-------------------
6 files changed, 70 insertions(+), 98 deletions(-)

diff --git a/packages/auditor-backoffice-ui/src/ApplicationReadyRoutes.tsx b/packages/auditor-backoffice-ui/src/ApplicationReadyRoutes.tsx @@ -26,10 +26,11 @@ import { Route, Router } from "preact-router"; import { useState } from "preact/hooks"; import { InstanceRoutes } from "./InstanceRoutes.js"; import { Loading } from "./components/exception/loading.js"; +import { NotYetReadyAppMenu } from "./components/menu/index.js"; import { - NotYetReadyAppMenu -} from "./components/menu/index.js"; -import { useBackendContext, useBackendTokenContext } from "./context/backend.js"; + useBackendContext, + useBackendTokenContext, +} from "./context/backend.js"; import { useBackendToken } from "./hooks/backend.js"; import { LoginPage } from "./paths/login/index.js"; import { Settings } from "./paths/settings/index.js"; @@ -39,49 +40,42 @@ import { Settings } from "./paths/settings/index.js"; * @returns */ export function ApplicationReadyRoutes(): VNode { - const { i18n } = useTranslationContext(); - const [unauthorized, setUnauthorized] = useState(false) - const [backendToken, setToken] = useState(false) - const { url: backendURL } = useBackendContext(); - const { token } = useBackendTokenContext(); + const { i18n } = useTranslationContext(); + const [unauthorized, setUnauthorized] = useState(false); + const [backendToken, setToken] = useState(false); + const { url: backendURL } = useBackendContext(); + const { token } = useBackendTokenContext(); - //TODO FIX bearer - const result = useBackendToken(); - if (result.loading) return <Loading />; - if (!result.ok) { - return ( - <LoginPage /> - ); - } - const [showSettings, setShowSettings] = useState(false) + //TODO FIX bearer + const result = useBackendToken(); + if (result.loading) return <Loading />; + if (!result.ok) { + return <LoginPage />; + } + const [showSettings, setShowSettings] = useState(false); - if (showSettings) { - return <Fragment> - <NotYetReadyAppMenu onShowSettings={() => setShowSettings(true)} title="UI Settings" /> - <Settings onClose={() => setShowSettings(false)} /> - </Fragment> - } - - const history = createHashHistory(); + if (showSettings) { return ( - <Router history={history}> - <Route - default - component={DefaultMainRoute} - /> - </Router> + <Fragment> + <NotYetReadyAppMenu + onShowSettings={() => setShowSettings(true)} + title="UI Settings" + /> + <Settings onClose={() => setShowSettings(false)} /> + </Fragment> ); + } + + const history = createHashHistory(); + return ( + <Router history={history}> + <Route default component={DefaultMainRoute} /> + </Router> + ); } function DefaultMainRoute({ - url, //from preact-router + url, //from preact-router }: any): VNode { - //TODO - url = "app/#" + url; - - return ( - <InstanceRoutes - path={url} - /> - ); + return <InstanceRoutes path={url} />; } diff --git a/packages/auditor-backoffice-ui/src/InstanceRoutes.tsx b/packages/auditor-backoffice-ui/src/InstanceRoutes.tsx @@ -21,7 +21,6 @@ */ import { TranslatedString } from "@gnu-taler/taler-util"; -import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { VNode, h } from "preact"; import { Route, Router, route } from "preact-router"; import { useEffect, useErrorBoundary, useMemo, useState } from "preact/hooks"; @@ -278,8 +277,6 @@ export function InstanceRoutes({ path, // setInstanceName }: Props): VNode { - const { i18n } = useTranslationContext(); - type GlobalNotifState = | (Notification & { to: string | undefined }) | undefined; @@ -287,9 +284,7 @@ export function InstanceRoutes({ useState<GlobalNotifState>(undefined); const [error] = useErrorBoundary(); - const { title, endpoint, entity } = getInstanceTitle( - path.replace("app/#", ""), - ); + const { title, endpoint, entity } = getInstanceTitle(path); const value = useMemo( () => ({ title, path, endpoint, entity }), diff --git a/packages/auditor-backoffice-ui/src/context/backend.ts b/packages/auditor-backoffice-ui/src/context/backend.ts @@ -25,39 +25,32 @@ import { useContext } from "preact/hooks"; import { useBackendURL } from "../hooks/index.js"; interface BackendContextType { - url: string, + url: string; } const BackendContext = createContext<BackendContextType>({ - url: "", + url: "", }); -function useBackendContextState( - defaultUrl?: string, -): BackendContextType { - const [url] = useBackendURL(defaultUrl); - - return { - url, - }; -} - export const BackendContextProvider = ({ - children, - defaultUrl, - }: { - children: any; - defaultUrl?: string; + children, + defaultUrl, +}: { + children: any; + defaultUrl?: string; }): VNode => { - const value = useBackendContextState(defaultUrl); - - return h(BackendContext.Provider, { value, children }); + const [url] = useBackendURL(defaultUrl); + + return h(BackendContext.Provider, { + value: { + url, + }, + children, + }); }; - - export const useBackendContext = (): BackendContextType => - useContext(BackendContext); + useContext(BackendContext); interface BackendTokenType { token: string; @@ -67,4 +60,5 @@ const BackendTokenContext = createContext<BackendTokenType>({} as any); export const BackendTokenContextProvider = BackendTokenContext.Provider; -export const useBackendTokenContext = (): BackendTokenType => useContext(BackendTokenContext); -\ No newline at end of file +export const useBackendTokenContext = (): BackendTokenType => + useContext(BackendTokenContext); diff --git a/packages/auditor-backoffice-ui/src/hooks/backend.ts b/packages/auditor-backoffice-ui/src/hooks/backend.ts @@ -208,12 +208,9 @@ export function useBackendBaseRequest(): useBackendBaseRequestType { } export function useBackendRequest(): useBackendInstanceRequestType { - const { url: rootBackendUrl } = useBackendContext(); - // const {id} = useInstanceContext(); + const { url: baseUrl } = useBackendContext(); const { request: requestHandler } = useApiContext(); - //TODO: check - const baseUrl = "http://localhost:8083/"; const token = "D4CST1Z6AHN3RT03M0T9NSTF2QGHTB5ZD2D3RYZB4HAWG8SX0JEFWBXCKXZHMB7Y3Z7KVFW0B3XPXD5BHCFP8EB0R6CNH2KAWDWVET0"; diff --git a/packages/auditor-backoffice-ui/src/hooks/index.ts b/packages/auditor-backoffice-ui/src/hooks/index.ts @@ -32,22 +32,22 @@ export function useBackendURL(url?: string): [string, StateUpdater<string>] { return [value!, checkedSetter]; } -const calculateRootPath = () => { +function calculateRootPath() { const rootPath = typeof window !== undefined ? window.location.origin + window.location.pathname : "/"; - /** + /* * By default, auditor backend serves the html content * from the /webui root. This should cover most of the * cases and the rootPath will be the auditor backend * URL where the instances are */ return rootPath.replace("/spa/", ""); -}; +} -export function useSimpleLocalStorage( +function useSimpleLocalStorage( key: string, initialValue?: string, ): [string | undefined, StateUpdater<string | undefined>] { diff --git a/packages/auditor-backoffice-ui/src/paths/finance/index.tsx b/packages/auditor-backoffice-ui/src/paths/finance/index.tsx @@ -20,19 +20,15 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { - ErrorType, - useTranslationContext, -} from "@gnu-taler/web-util/browser"; +import { HttpStatusCode } from "@gnu-taler/taler-util"; +import { ErrorType, useTranslationContext } from "@gnu-taler/web-util/browser"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { Loading } from "../../components/exception/loading.js"; import { NotificationCard } from "../../components/menu/index.js"; +import { getKeyFiguresData } from "../../hooks/finance.js"; import { Notification } from "../../utils/types.js"; import { ListPage } from "./ListPage.js"; -import { HttpStatusCode } from "@gnu-taler/taler-util"; -import { getKeyFiguresData } from "../../hooks/finance.js"; - interface Props { onUnauthorized: () => VNode; @@ -42,13 +38,12 @@ interface Props { } export default function FinanceDashboard({ - onUnauthorized, - // onLoadError, - onCreate, - onSelect, - onNotFound, - }: Props): VNode { - + onUnauthorized, + // onLoadError, + onCreate, + onSelect, + onNotFound, +}: Props): VNode { const result = getKeyFiguresData(); const [notif, setNotif] = useState<Notification | undefined>(undefined); @@ -67,14 +62,13 @@ export default function FinanceDashboard({ result.status === HttpStatusCode.NotFound ) return onNotFound(); - else - return onNotFound(); + else return onNotFound(); } return ( <section class="section is-main-section"> <NotificationCard notification={notif} /> - <ListPage data={result} /> + <ListPage data={result} /> </section> ); -} -\ No newline at end of file +}