From 37d0f9438e6e6507c46d56324e38a5f0c391ab45 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 4 Aug 2023 13:32:08 -0300 Subject: accesstoken in memory and better login when switching between accounts --- .../src/components/exception/login.tsx | 97 ++++++++++++++++++++-- 1 file changed, 91 insertions(+), 6 deletions(-) (limited to 'packages/merchant-backoffice-ui/src/components/exception') diff --git a/packages/merchant-backoffice-ui/src/components/exception/login.tsx b/packages/merchant-backoffice-ui/src/components/exception/login.tsx index 42c5e89d0..984b6fe06 100644 --- a/packages/merchant-backoffice-ui/src/components/exception/login.tsx +++ b/packages/merchant-backoffice-ui/src/components/exception/login.tsx @@ -20,7 +20,7 @@ */ import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { h, VNode } from "preact"; +import { ComponentChildren, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { useBackendContext } from "../../context/backend.js"; import { useInstanceContext } from "../../context/instance.js"; @@ -40,7 +40,7 @@ function getTokenValuePart(t: string): string { } function normalizeToken(r: string): string { - return `secret-token:${encodeURIComponent(r)}`; + return `secret-token:${r}`; } function cleanUp(s: string): string { @@ -53,7 +53,7 @@ function cleanUp(s: string): string { export function LoginModal({ onConfirm, withMessage }: Props): VNode { const { url: backendUrl, token: baseToken } = useBackendContext(); - const { admin, token: instanceToken } = useInstanceContext(); + const { admin, token: instanceToken, id } = useInstanceContext(); const testLogin = useCredentialsChecker(); const currentToken = getTokenValuePart( (!admin ? baseToken : instanceToken) ?? "", @@ -63,6 +63,78 @@ export function LoginModal({ onConfirm, withMessage }: Props): VNode { const [url, setURL] = useState(cleanUp(backendUrl)); const { i18n } = useTranslationContext(); + if (admin && id !== "default") { + //admin trying to access another instance + return (
+
+ +
+
) + } + return (
@@ -137,8 +209,7 @@ export function LoginModal({ onConfirm, withMessage }: Props): VNode { borderTop: 0, }} > - +
); } + +function AsyncButton({onClick, children}:{onClick: () => Promise, children: ComponentChildren}):VNode { + const [running, setRunning] = useState(false) + return +} -- cgit v1.2.3 From 7d1621767cec57e9e7217f620844655279ab1af5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 7 Aug 2023 06:51:10 -0300 Subject: ui settings view --- .../merchant-backoffice-ui/src/Application.tsx | 24 +++++--- .../src/ApplicationReadyRoutes.tsx | 14 ++++- .../merchant-backoffice-ui/src/InstanceRoutes.tsx | 7 +++ .../src/components/exception/login.tsx | 2 +- .../src/components/menu/NavigationBar.tsx | 2 - .../src/components/menu/SideBar.tsx | 64 ++++++++++++++-------- .../src/components/menu/index.tsx | 7 ++- .../src/paths/instance/orders/list/ListPage.tsx | 4 +- .../paths/instance/templates/create/CreatePage.tsx | 38 ++++++------- .../src/paths/settings/index.tsx | 15 +++++ 10 files changed, 118 insertions(+), 59 deletions(-) create mode 100644 packages/merchant-backoffice-ui/src/paths/settings/index.tsx (limited to 'packages/merchant-backoffice-ui/src/components/exception') diff --git a/packages/merchant-backoffice-ui/src/Application.tsx b/packages/merchant-backoffice-ui/src/Application.tsx index 23510c456..f6a81ff8d 100644 --- a/packages/merchant-backoffice-ui/src/Application.tsx +++ b/packages/merchant-backoffice-ui/src/Application.tsx @@ -26,7 +26,7 @@ import { } from "@gnu-taler/web-util/browser"; import { Fragment, h, VNode } from "preact"; import { route } from "preact-router"; -import { useMemo } from "preact/hooks"; +import { useMemo, useState } from "preact/hooks"; import { ApplicationReadyRoutes } from "./ApplicationReadyRoutes.js"; import { Loading } from "./components/exception/loading.js"; import { @@ -42,6 +42,7 @@ import { useBackendConfig } from "./hooks/backend.js"; import { strings } from "./i18n/strings.js"; import LoginPage from "./paths/login/index.js"; import { HttpStatusCode } from "@gnu-taler/taler-util"; +import { Settings } from "./paths/settings/index.js"; export function Application(): VNode { return ( @@ -70,10 +71,19 @@ function ApplicationStatusRoutes(): VNode { : { currency: "unknown", version: "unknown" }; const ctx = useMemo(() => ({ currency, version }), [currency, version]); + const [showSettings, setShowSettings] = useState(false) + + if (showSettings) { + return + setShowSettings(true)} title="UI Settings" /> + + + } + if (!triedToLog) { return ( - + setShowSettings(true)} /> ); @@ -87,7 +97,7 @@ function ApplicationStatusRoutes(): VNode { ) { return ( - + setShowSettings(true)} /> ); @@ -98,7 +108,7 @@ function ApplicationStatusRoutes(): VNode { ) { return ( - + setShowSettings(true)} /> - + setShowSettings(true)} /> - + setShowSettings(true)} /> - + setShowSettings(true)} /> ; + if (showSettings) { + return + setShowSettings(true)} title="UI Settings" onLogout={clearTokenAndGoToRoot} /> + + + } + if (result.loading) return setShowSettings(true)} title="Loading..." />; let admin = true; let instanceNameByBackendURL; @@ -61,7 +69,7 @@ export function ApplicationReadyRoutes(): VNode { ) { return ( - + setShowSettings(true)} title="Login" onLogout={clearTokenAndGoToRoot} /> - + setShowSettings(true)} title="Error" onLogout={clearTokenAndGoToRoot} /> { + route("/settings") + }} path={path} onLogout={clearTokenAndGoToRoot} setInstanceName={setInstanceName} @@ -558,6 +564,7 @@ export function InstanceRoutes({ }} /> + {/** * Example pages */} diff --git a/packages/merchant-backoffice-ui/src/components/exception/login.tsx b/packages/merchant-backoffice-ui/src/components/exception/login.tsx index 984b6fe06..f2f94a7c5 100644 --- a/packages/merchant-backoffice-ui/src/components/exception/login.tsx +++ b/packages/merchant-backoffice-ui/src/components/exception/login.tsx @@ -229,7 +229,7 @@ export function LoginModal({ onConfirm, withMessage }: Props): VNode { ); } -function AsyncButton({onClick, children}:{onClick: () => Promise, children: ComponentChildren}):VNode { +function AsyncButton({ onClick, children }: { onClick: () => Promise, children: ComponentChildren }): VNode { const [running, setRunning] = useState(false) return