taler-typescript-core

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

commit 939f3dbd8a9fdc822f53d32a6523d9b7357ca3c5
parent b8c266263cc4991ae121ec07a378fbc58a7f6bdf
Author: Florian Dold <dold@taler.net>
Date:   Thu, 26 Nov 2026 17:08:42 +0100

merchant web UI: make fountain management an opt-in workflow

Expose the fountain preference under Advanced tools and apply it to
navigation and direct routes. Bind the newly issued onboarding code to
the creating session.

Diffstat:
Mpackages/taler-merchant-webui/src/App.tsx | 21+++++++++++++++++++++
Apackages/taler-merchant-webui/src/routes/FountainsRoute.tsx | 161+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-merchant-webui/src/routes/fountains.test.tsx | 320++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mpackages/taler-merchant-webui/src/screens/PersonalizationScreen.tsx | 46+++++++++++++++++++++++++++++++++++++---------
Mpackages/taler-merchant-webui/src/screens/screens.test.tsx | 2++
Mpackages/taler-merchant-webui/src/screens/token-setup/wizard.test.tsx | 17++++++++++++++---
Mpackages/taler-merchant-webui/src/stores/preferences.ts | 12+++++++++++-
Mpackages/taler-merchant-webui/src/tutorial/tutorialData.tsx | 2+-
Mpackages/taler-merchant-webui/src/ui/Menu.tsx | 20++++++++++++++++----
Mpackages/taler-merchant-webui/src/ui/menuStructure.ts | 11++++++++---
10 files changed, 590 insertions(+), 22 deletions(-)

diff --git a/packages/taler-merchant-webui/src/App.tsx b/packages/taler-merchant-webui/src/App.tsx @@ -56,6 +56,7 @@ import { ReportsRoute } from "./routes/ReportsRoute.js"; import { WebhooksRoute } from "./routes/WebhooksRoute.js"; import { CreateWebhookRoute } from "./routes/CreateWebhookRoute.js"; import { SubscriptionsRoute } from "./routes/SubscriptionsRoute.js"; +import { FountainsRoute } from "./routes/FountainsRoute.js"; import { CreateSubscriptionRoute } from "./routes/CreateSubscriptionRoute.js"; import { PaymentServicesRoute } from "./routes/PaymentServicesRoute.js"; import { DevicesRoute } from "./routes/DevicesRoute.js"; @@ -892,6 +893,26 @@ export function AppContent(): VNode { <Route path="/subscriptions"> <SubscriptionsRoute /> </Route> + <Route path="/fountains/new"> + <FountainsRoute mode="new" /> + </Route> + <Route path="/fountains/:id/edit"> + {(params) => + withRouteId(params.id, (id) => ( + <FountainsRoute mode="edit" id={id} /> + )) + } + </Route> + <Route path="/fountains/:id"> + {(params) => + withRouteId(params.id, (id) => ( + <FountainsRoute mode="detail" id={id} /> + )) + } + </Route> + <Route path="/fountains"> + <FountainsRoute /> + </Route> <Route path="/settings/server"> <ServerInfoRoute /> </Route> diff --git a/packages/taler-merchant-webui/src/routes/FountainsRoute.tsx b/packages/taler-merchant-webui/src/routes/FountainsRoute.tsx @@ -0,0 +1,161 @@ +/* + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + 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 type { VNode } from "preact"; +import { useEffect, useRef, useState } from "preact/hooks"; +import { useLocation } from "wouter-preact"; +import { useFountains, useFountainDetails } from "../api/hooks/useFountains.js"; +import { useTokenFamilies } from "../api/hooks/useTokenFamilies.js"; +import { runProtectedMutation, mapRemoteResource } from "../api/contracts.js"; +import { accountBaseUrl } from "../api/client.js"; +import { getClientConfig } from "../api/hooks/common.js"; +import { + captureSessionIdentity, + isCurrentSessionIdentity, + session, + currentBackendUrl, +} from "../stores/session.js"; +import { fountainsEnabled } from "../stores/preferences.js"; +import { useTranslation } from "../context/translation.js"; +import { Link } from "../routing/Link.js"; +import { Header } from "../ui/Header.js"; +import { FountainsScreen } from "../screens/FountainsScreen.js"; +import { FountainDetailsScreen } from "../screens/FountainDetailsScreen.js"; +import { FountainFormScreen } from "../screens/FountainFormScreen.js"; +import { FountainCreatedScreen } from "../screens/FountainCreatedScreen.js"; +import { fountainImportUri, CreatedFountain } from "../utils/fountains.js"; +import { resourcePath } from "../routing/resourcePath.js"; + +export interface FountainsRouteProps { + mode?: "list" | "new" | "detail" | "edit"; + id?: string; +} + +export function FountainsRoute(props: FountainsRouteProps): VNode { + const { t } = useTranslation(); + if (!fountainsEnabled.value) { + return ( + <Header + title={t`Fountains`} + subtitle={t`To manage fountains, turn on “Show advanced tools” and “Enable fountains” in Personalization.`} + > + <Link + href="/personalization" + class="text-sm font-semibold text-blue-700 hover:underline" + > + {t`Personalization`} + </Link> + </Header> + ); + } + // Subscribe to session changes and unmount any form/credential from the old account. + const active = session.value; + const identity = captureSessionIdentity(); + const key = JSON.stringify([ + currentBackendUrl.value, + active.account, + identity?.generation, + active.token, + ]); + return ( + <FountainSessionRoute key={`${key}:${props.mode}:${props.id}`} {...props} /> + ); +} + +function FountainSessionRoute({ + mode = "list", + id, +}: FountainsRouteProps): VNode { + const [, navigate] = useLocation(); + const actions = useFountains(); + const { resource: details } = useFountainDetails(id); + const { resource: families } = useTokenFamilies({ + enabled: mode === "new" || mode === "edit", + }); + const [created, setCreated] = useState<CreatedFountain>(); + const mounted = useRef(true); + useEffect( + () => () => { + mounted.current = false; + }, + [], + ); + const back = () => navigate("/fountains"); + if (mode === "list") + return ( + <FountainsScreen + resource={actions.resource} + pagination={actions.pagination} + onCreate={() => navigate("/fountains/new")} + onDelete={actions.deleteFountain} + /> + ); + if (created) + return ( + <FountainCreatedScreen + fountain={created} + onDone={() => { + const createdId = created.id; + setCreated(undefined); + navigate(resourcePath("/fountains", createdId)); + }} + /> + ); + if (mode === "detail" || (mode === "edit" && !details.data)) + return ( + <FountainDetailsScreen + id={id!} + resource={details} + onBack={back} + onEdit={() => navigate(resourcePath("/fountains", id!, "edit"))} + /> + ); + return ( + <FountainFormScreen + editing={mode === "edit"} + supportsDisplayName={actions.fountainDisplayName} + initial={mode === "edit" ? details.data : undefined} + families={mapRemoteResource(families, (rows) => + rows.map((f) => ({ slug: f.slug, name: f.name })), + )} + onCancel={back} + onSave={(body) => + runProtectedMutation(async () => { + const identity = captureSessionIdentity(); + if (!identity) throw new Error("No authenticated merchant session"); + const baseUrl = accountBaseUrl(getClientConfig()).href; + if (mode === "edit") { + await actions.updateFountain(id!, body); + if (mounted.current && isCurrentSessionIdentity(identity)) + navigate(resourcePath("/fountains", id!)); + } else { + const result = await actions.createFountain(body); + if (mounted.current && isCurrentSessionIdentity(identity)) + setCreated({ + id: result.fountain_id, + description: body.description, + uri: fountainImportUri( + baseUrl, + result.fountain_id, + result.fountain_secret, + ), + }); + } + }) + } + /> + ); +} diff --git a/packages/taler-merchant-webui/src/routes/fountains.test.tsx b/packages/taler-merchant-webui/src/routes/fountains.test.tsx @@ -18,6 +18,8 @@ import assert from "node:assert/strict"; import test from "node:test"; import { render, VNode } from "preact"; import { act } from "preact/test-utils"; +import { Router } from "wouter-preact"; +import { mutate } from "swr"; import { encodeCrock, FountainCreateRequest, @@ -25,6 +27,7 @@ import { TalerUriAction, TalerUris, } from "@gnu-taler/taler-util"; +import { FountainsRoute, type FountainsRouteProps } from "./FountainsRoute.js"; import { FountainsScreen } from "../screens/FountainsScreen.js"; import { FountainFormScreen } from "../screens/FountainFormScreen.js"; import { FountainCreatedScreen } from "../screens/FountainCreatedScreen.js"; @@ -33,9 +36,14 @@ import { fountainImportUri, fountainValidationError, } from "../utils/fountains.js"; +import { useHttpLibForTesting } from "../api/client.js"; import { normalizeApiFailure } from "../api/failure.js"; import { RemoteResource } from "../api/contracts.js"; -import { ok, conflict } from "../testing/fake-http.js"; +import { FakeHttpLib, ok, conflict, noContent } from "../testing/fake-http.js"; +import { session, signIn, signOut } from "../stores/session.js"; +import { preferences } from "../stores/preferences.js"; +import { Menu } from "../ui/Menu.js"; +import { useHashLocation } from "../routing/useHashLocation.js"; import { PRINT_ROOT_ID } from "../utils/print.js"; import type { TranslateFn } from "../context/translation.js"; @@ -71,6 +79,26 @@ function mount(view: VNode) { }, }; } +function mountEnabledRoute(props: FountainsRouteProps) { + const previous = preferences.value; + preferences.value = { + ...previous, + advancedTools: true, + fountainManagement: true, + }; + const view = mount( + <Router hook={useHashLocation}> + <FountainsRoute {...props} /> + </Router>, + ); + return { + container: view.container, + close() { + view.close(); + preferences.value = previous; + }, + }; +} function field(container: HTMLElement, selector: string, value: string) { const input = container.querySelector<HTMLInputElement>(selector); assert.ok(input, selector); @@ -105,6 +133,64 @@ function assertSecretNotPersisted() { assert.ok(!values.join(" ").includes(secret)); } +test("fountain navigation requires both saved preferences", async () => { + const old = preferences.value; + const view = mount(<Menu serverUrl={backend} accountName="cafe" />); + try { + for (const advancedTools of [false, true]) { + for (const fountainManagement of [false, true]) { + await act(async () => { + preferences.value = { ...old, advancedTools, fountainManagement }; + }); + assert.equal( + !!view.container.querySelector('a[href="#/fountains"]'), + advancedTools && fountainManagement, + ); + assert.equal( + !!view.container.querySelector('a[href="#/subscriptions"]'), + advancedTools, + ); + } + } + } finally { + view.close(); + preferences.value = old; + } +}); + +test("disabled fountain routes link to Personalization before making requests", async () => { + const old = preferences.value; + const http = new FakeHttpLib(); + const restore = useHttpLibForTesting(http); + signIn("cafe", "secret-token:portal", backend); + try { + for (const advancedTools of [false, true]) { + preferences.value = { + ...old, + advancedTools, + fountainManagement: !advancedTools, + }; + for (const mode of ["list", "detail", "edit", "new"] as const) { + const view = mount(<FountainsRoute mode={mode} id="campaign" />); + try { + await flush(); + assert.ok( + view.container.querySelector('a[href="#/personalization"]'), + ); + assert.equal(view.container.querySelector("form"), null); + } finally { + view.close(); + } + } + } + assert.equal(http.requests.length, 0); + } finally { + restore(); + signOut(); + preferences.value = old; + } +}); + test("fountain lists distinguish loading, failure and empty data", () => { for (const state of [ { ...resource(undefined), isLoading: true }, @@ -314,3 +400,235 @@ test("creation view copies, prints and downloads the same import URI", async (t) view.close(); } }); + +async function openRoute(mode: "new" | "edit" = "new", failing = false) { + const http = new FakeHttpLib().handle((req) => { + if (req.method === "POST") + return failing + ? conflict({ code: 1 }) + : ok({ fountain_id: "campaign", fountain_secret: secret }); + if (req.method === "PATCH" || req.method === "DELETE") return noContent(); + // A failed refresh must never lose the creation response. + return { status: 500, body: { code: 1 } }; + }); + const restore = useHttpLibForTesting(http); + signIn("cafe", "secret-token:portal", backend); + if (mode === "edit") + await mutate( + ["getFountainDetails", backend, "cafe", session.value.token, "campaign"], + { + ...defaultFountain, + description: "Original", + name_i18n: { de: "Campus" }, + extra_data: { campaign: 7 }, + }, + false, + ); + const view = mountEnabledRoute({ + mode, + id: mode === "edit" ? "campaign" : undefined, + }); + return { + ...view, + http, + cleanup() { + view.close(); + restore(); + signOut(); + }, + }; +} + +test("creation reveals a session-bound code once without caching or persisting it", async () => { + const view = await openRoute(); + try { + field(view.container, "#fountain-description", "Campus"); + await submit(view.container); + assert.match(view.container.textContent ?? "", /Fountain created/); + assert.ok(view.container.textContent?.includes(secret)); + const request = view.http.requests.find((r) => r.method === "POST")!; + assert.equal(request.url, `${backend}instances/cafe/private/fountains`); + assert.equal(request.headers?.Authorization, "Bearer secret-token:portal"); + assert.equal( + view.http.requests.filter((r) => r.method === "POST").length, + 1, + ); + assertSecretNotPersisted(); + await click(view.container, "I have saved it — Done"); + assert.ok(!view.container.textContent?.includes(secret)); + assert.equal(window.location.hash, "#/fountains/campaign"); + } finally { + view.cleanup(); + } +}); + +test("changing accounts clears the import code, and failed creation retains the form", async () => { + const view = await openRoute(); + try { + await submit(view.container); + assert.ok(view.container.textContent?.includes(secret)); + await act(async () => signIn("other", "secret-token:other", backend)); + await flush(); + assert.ok(!view.container.textContent?.includes(secret)); + assertSecretNotPersisted(); + } finally { + view.cleanup(); + } + const failed = await openRoute("new", true); + try { + field(failed.container, "#fountain-description", "Retain this"); + await submit(failed.container); + assert.match(failed.container.textContent ?? "", /Could not save fountain/); + assert.equal( + failed.container.querySelector<HTMLInputElement>("#fountain-description")! + .value, + "Retain this", + ); + assert.equal( + failed.http.requests.filter((r) => r.method === "POST").length, + 1, + ); + } finally { + failed.cleanup(); + } +}); + +test("editing an existing fountain sends the full grant replacement and no credential", async () => { + const view = await openRoute("edit"); + try { + await flush(); + field(view.container, "#fountain-description", "Updated"); + await submit(view.container); + const request = view.http.requests.find((r) => r.method === "PATCH")!; + assert.ok(request); + assert.deepEqual(request.body, { + ...defaultFountain, + description: "Updated", + }); + assert.equal( + request.url, + `${backend}instances/cafe/private/fountains/campaign`, + ); + assert.ok(!view.container.textContent?.includes(secret)); + } finally { + view.cleanup(); + } +}); + +test("failed deletion keeps the confirmation and fountain visible", async () => { + const view = mount( + <FountainsScreen + resource={resource([{ fountain_id: "campaign", description: "Campus" }])} + onCreate={() => {}} + onDelete={async (id) => { + assert.equal(id, "campaign"); + throw normalizeApiFailure({ + type: "fail", + case: 403, + body: { code: 21 }, + }); + }} + />, + ); + try { + await click(view.container, "Delete"); + const confirm = [...document.body.querySelectorAll("button")].find( + (b) => b.textContent?.trim() === "Delete fountain", + )!; + assert.ok(confirm.disabled); + field(document.body, "#revoke-fountain-id", "Campaign"); + assert.ok(confirm.disabled); + field(document.body, "#revoke-fountain-id", " campaign "); + assert.equal(confirm.disabled, false); + await click(document.body, "Delete fountain"); + assert.match(document.body.textContent ?? "", /Could not delete this item/); + assert.ok(view.container.querySelector('a[href="#/fountains/campaign"]')); + assert.ok(document.body.querySelector('[role="dialog"]')); + await click(document.body, "Cancel"); + assert.ok(!document.body.querySelector('[role="dialog"]')); + } finally { + view.close(); + } +}); + +test("an indeterminate creation shows recovery guidance and never retries automatically", async () => { + const http = new FakeHttpLib().handle((req) => { + if (req.method === "POST") throw new TypeError("Connection lost"); + return ok({ fountains: [] }); + }); + const restore = useHttpLibForTesting(http); + signIn("cafe", "secret-token:portal", backend); + const view = mountEnabledRoute({ mode: "new" }); + try { + field(view.container, "#fountain-description", "Check before retrying"); + await submit(view.container); + assert.match(view.container.textContent ?? "", /may have been created/); + assert.equal( + view.container.querySelector<HTMLInputElement>("#fountain-description")! + .value, + "Check before retrying", + ); + assert.equal(http.requests.filter((r) => r.method === "POST").length, 1); + } finally { + view.close(); + restore(); + signOut(); + } +}); + +test("logout and changing backends clear the import code", async () => { + for (const changeSession of [ + () => signOut(), + () => signIn("cafe", "secret-token:portal", "https://other.example/"), + ]) { + const view = await openRoute(); + try { + await submit(view.container); + assert.ok(view.container.textContent?.includes(secret)); + await act(async () => changeSession()); + await flush(); + assert.ok(!view.container.textContent?.includes(secret)); + } finally { + view.cleanup(); + } + } +}); + +test("a creation response from a replaced session cannot reveal its secret", async () => { + const http = new FakeHttpLib() + .on( + "POST", + "/private/fountains", + ok({ fountain_id: "campaign", fountain_secret: secret }), + ) + .otherwise(ok({ fountains: [] })); + let finish!: () => void; + const gate = new Promise<void>((resolve) => { + finish = resolve; + }); + const restore = useHttpLibForTesting({ + fetch: async (url, options) => { + const response = await http.fetch(url, options); + if (options?.method === "POST") await gate; + return response; + }, + }); + signIn("cafe", "secret-token:portal", backend); + const view = mountEnabledRoute({ mode: "new" }); + try { + await submit(view.container); + // Repeated submissions while the POST is pending must not create another fountain. + await submit(view.container); + assert.equal(http.requests.filter((r) => r.method === "POST").length, 1); + await act(async () => signIn("other", "secret-token:other", backend)); + await act(async () => finish()); + await flush(); + assert.ok(!view.container.textContent?.includes(secret)); + assertSecretNotPersisted(); + } finally { + finish(); + view.close(); + restore(); + signOut(); + } +}); diff --git a/packages/taler-merchant-webui/src/screens/PersonalizationScreen.tsx b/packages/taler-merchant-webui/src/screens/PersonalizationScreen.tsx @@ -18,11 +18,7 @@ import { FormActionFooter } from "../ui/FormActionFooter.js"; import type { VNode } from "preact"; import { useState } from "preact/hooks"; import { Header } from "../ui/Header.js"; -import { - DateFormat, - preferences, - updatePreference, -} from "../stores/preferences.js"; +import { DateFormat, preferences } from "../stores/preferences.js"; import { useTranslation } from "../context/translation.js"; import { AbsoluteTime } from "@gnu-taler/taler-util"; @@ -39,6 +35,9 @@ export function PersonalizationScreen(): VNode { const [draftTokenSetupWizard, setDraftTokenSetupWizard] = useState( preferences.value.tokenSetupWizard, ); + const [draftFountainManagement, setDraftFountainManagement] = useState( + preferences.value.fountainManagement, + ); const [saveMessage, setSaveMessage] = useState<string | null>(null); const notifySaved = ( @@ -51,9 +50,13 @@ export function PersonalizationScreen(): VNode { }; const handleSavePreferences = () => { - updatePreference("dateFormat", draftDateFormat); - updatePreference("advancedTools", draftAdvancedTools); - updatePreference("tokenSetupWizard", draftTokenSetupWizard); + preferences.value = { + ...preferences.value, + dateFormat: draftDateFormat, + advancedTools: draftAdvancedTools, + tokenSetupWizard: draftTokenSetupWizard, + fountainManagement: draftFountainManagement, + }; notifySaved(t`✓ All preferences saved successfully to this browser`); }; @@ -129,7 +132,7 @@ export function PersonalizationScreen(): VNode { {t`Show advanced tools`} </label> <span class="mt-1 block font-normal text-gray-500"> - {t`Adds specialist statistics and Discounts & Passes management to the navigation. This changes discoverability, not permissions.`} + {t`Adds specialist statistics and Discounts & Passes to the navigation.`} </span> </span> </div> @@ -158,6 +161,31 @@ export function PersonalizationScreen(): VNode { </div> )} + {draftAdvancedTools && ( + <div class="flex items-start gap-3 text-sm text-gray-700"> + <input + id="pref-fountains" + type="checkbox" + checked={draftFountainManagement} + onChange={(e) => + setDraftFountainManagement(e.currentTarget.checked) + } + aria-describedby="pref-fountains-description" + class="mt-0.5 h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500" + /> + <div> + <label + htmlFor="pref-fountains" + class="block font-semibold" + >{t`Enable fountains`}</label> + <p + id="pref-fountains-description" + class="text-xs text-gray-500" + >{t`Distribute discounts and passes directly to wallets.`}</p> + </div> + </div> + )} + {/* Explicit Save Action */} <FormActionFooter variant="inline"> {saveMessage && ( diff --git a/packages/taler-merchant-webui/src/screens/screens.test.tsx b/packages/taler-merchant-webui/src/screens/screens.test.tsx @@ -7414,6 +7414,7 @@ test("the menu the tutorial mocks is the menu the app renders", () => { document.body.appendChild(container); updatePreference("advancedTools", true); + updatePreference("fountainManagement", true); render( <Menu serverUrl="https://example.com/" accountName="default" />, container, @@ -7448,6 +7449,7 @@ test("the menu the tutorial mocks is the menu the app renders", () => { render(null, container); updatePreference("advancedTools", false); + updatePreference("fountainManagement", false); document.body.removeChild(container); }); diff --git a/packages/taler-merchant-webui/src/screens/token-setup/wizard.test.tsx b/packages/taler-merchant-webui/src/screens/token-setup/wizard.test.tsx @@ -299,10 +299,15 @@ test("saved stamp counts select a preset or reveal the custom input", () => { } }); -test("old preferences preserve existing settings and default the wizard off", () => { +test("old preferences preserve existing settings and default the optional tools off", () => { assert.deepEqual( codecForPreferences().decode({ dateFormat: "dmy", advancedTools: true }), - { dateFormat: "dmy", advancedTools: true, tokenSetupWizard: false }, + { + dateFormat: "dmy", + advancedTools: true, + tokenSetupWizard: false, + fountainManagement: false, + }, ); }); @@ -510,25 +515,31 @@ test("editing fields does not clear a failed save", async () => { } }); -test("wizard preference is conditional and saves explicitly", async () => { +test("advanced tool preferences are conditional and save explicitly", async () => { const previous = preferences.value; preferences.value = { ...previous, advancedTools: false, tokenSetupWizard: false, + fountainManagement: false, }; const ui = mount(<PersonalizationScreen />); try { assert.equal(ui.container.querySelector("#pref-token-setup-wizard"), null); + assert.equal(ui.container.querySelector("#pref-fountains"), null); check(ui.container, "#pref-advanced-tools"); check(ui.container, "#pref-token-setup-wizard"); + check(ui.container, "#pref-fountains"); + assert.equal(preferences.value.fountainManagement, false); assert.equal(preferences.value.tokenSetupWizard, false); await submit(ui.container); assert.equal(preferences.value.tokenSetupWizard, true); + assert.equal(preferences.value.fountainManagement, true); check(ui.container, "#pref-advanced-tools"); await submit(ui.container); assert.equal(preferences.value.advancedTools, false); assert.equal(preferences.value.tokenSetupWizard, true); + assert.equal(preferences.value.fountainManagement, true); } finally { ui.close(); preferences.value = previous; diff --git a/packages/taler-merchant-webui/src/stores/preferences.ts b/packages/taler-merchant-webui/src/stores/preferences.ts @@ -22,7 +22,7 @@ import { codecForEither, codecOptionalDefault, } from "@gnu-taler/taler-util"; -import type { Signal } from "@preact/signals"; +import { computed, type Signal } from "@preact/signals"; import { persistedSignal } from "./persisted.js"; /** @@ -34,12 +34,14 @@ export interface Preferences { dateFormat: DateFormat; /** Show specialist and diagnostic screens in the navigation. */ advancedTools: boolean; + fountainManagement: boolean; tokenSetupWizard: boolean; } const defaults: Preferences = { dateFormat: "ymd", advancedTools: false, + fountainManagement: false, tokenSetupWizard: false, }; @@ -55,6 +57,10 @@ export const codecForPreferences = (): Codec<Preferences> => ) .property("advancedTools", codecForBoolean()) .property( + "fountainManagement", + codecOptionalDefault(codecForBoolean(), false), + ) + .property( "tokenSetupWizard", codecOptionalDefault(codecForBoolean(), false), ) @@ -68,6 +74,10 @@ const store = persistedSignal<Preferences>( export const preferences: Signal<Preferences> = store.signal; +export const fountainsEnabled = computed( + () => preferences.value.advancedTools && preferences.value.fountainManagement, +); + export function updatePreference<K extends keyof Preferences>( key: K, value: Preferences[K], diff --git a/packages/taler-merchant-webui/src/tutorial/tutorialData.tsx b/packages/taler-merchant-webui/src/tutorial/tutorialData.tsx @@ -1089,7 +1089,7 @@ function buildTutorialChapters(t: TranslateFn): TutorialChapter[] { blocks: [ { kind: "p", - text: t`Turn on **Show advanced tools** to add specialist statistics and Discounts & Passes management to the navigation. This only makes those tools easier to find; it does not grant new permissions or change what the server allows.`, + text: t`To manage fountains, select **Show advanced tools**, then **Enable fountains**, and save your preferences.`, }, ], // The same compact form is already visible immediately above. Showing diff --git a/packages/taler-merchant-webui/src/ui/Menu.tsx b/packages/taler-merchant-webui/src/ui/Menu.tsx @@ -19,7 +19,7 @@ import { useLayoutEffect, useRef } from "preact/hooks"; import { useLocation } from "wouter-preact"; import { Link } from "../routing/Link.js"; import { TalerLogo } from "./TalerLogo.js"; -import { preferences } from "../stores/preferences.js"; +import { fountainsEnabled, preferences } from "../stores/preferences.js"; import { useTranslation } from "../context/translation.js"; import { ADMIN_MENU_GROUP, @@ -72,6 +72,8 @@ function translateMenuText( return t`Connect`; case "Webhooks": return t`Webhooks`; + case "Fountains": + return t`Fountains`; case "Machine access": // API credentials for tills and other machines, not physical access. return t`Machine access`; @@ -109,7 +111,10 @@ export function Menu({ }: MenuProps): VNode { const [location] = useLocation(); const { t, lang, setLanguage, languages } = useTranslation(); - const showAdvanced = preferences.value.advancedTools; + const enabledTools = { + advancedTools: preferences.value.advancedTools, + fountains: fountainsEnabled.value, + }; const desktopSidebar = useRef<HTMLElement>(null); const mobileSidebar = useRef<HTMLElement>(null); @@ -124,7 +129,14 @@ export function Menu({ behavior: "instant", }); } - }, [location, isMobileOpen, showAdvanced, showAdministration, lang]); + }, [ + location, + isMobileOpen, + enabledTools.advancedTools, + enabledTools.fountains, + showAdministration, + lang, + ]); const isActivePath = (path: string) => { if (path === "/orders") @@ -175,7 +187,7 @@ export function Menu({ : MENU_GROUPS ).map((group) => { const entries = group.items.filter( - (entry) => !entry.advanced || showAdvanced, + (entry) => !entry.requires || enabledTools[entry.requires], ); if (entries.length === 0) return null; return ( diff --git a/packages/taler-merchant-webui/src/ui/menuStructure.ts b/packages/taler-merchant-webui/src/ui/menuStructure.ts @@ -37,7 +37,7 @@ export interface MenuEntry { label: string; href: string; aliases?: string[]; - advanced?: boolean; + requires?: "advancedTools" | "fountains"; externalShell?: boolean; } @@ -58,7 +58,12 @@ export const MENU_GROUPS: MenuGroup[] = [ { label: "Counter till", href: "/pos", externalShell: true }, { label: "Templates", href: "/templates" }, { label: "Inventory", href: "/inventory" }, - { label: "Discounts & Passes", href: "/subscriptions", advanced: true }, + { + label: "Discounts & Passes", + href: "/subscriptions", + requires: "advancedTools", + }, + { label: "Fountains", href: "/fountains", requires: "fountains" }, ], }, { @@ -69,7 +74,7 @@ export const MENU_GROUPS: MenuGroup[] = [ href: "/money/payout-accounts", aliases: ["/money/transfers"], }, - { label: "Statistics", href: "/statistics", advanced: true }, + { label: "Statistics", href: "/statistics", requires: "advancedTools" }, { label: "Reports", href: "/reports/scheduled",