taler-typescript-core

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

commit b8c266263cc4991ae121ec07a378fbc58a7f6bdf
parent 8ee32bb6434784be3b21831f40e07312aad02d97
Author: Florian Dold <dold@taler.net>
Date:   Mon, 23 Nov 2026 17:35:34 +0100

merchant web UI: list, inspect and revoke fountains

Page by cursor on merchants that support it, and require the fountain ID
to confirm revocation. Select name and pagination support from the
merchant protocol version.

Diffstat:
Mpackages/taler-merchant-webui/src/api/hooks.ts | 1+
Apackages/taler-merchant-webui/src/api/hooks/useFountains.ts | 192+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-merchant-webui/src/api/merchantBackendFeatures.test.ts | 23++++++++++++++++-------
Mpackages/taler-merchant-webui/src/api/merchantBackendFeatures.ts | 10++++++++++
Mpackages/taler-merchant-webui/src/routes/fountains.test.tsx | 35+++++++++++++++++++++++++++++++++++
Apackages/taler-merchant-webui/src/screens/FountainDetailsScreen.tsx | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apackages/taler-merchant-webui/src/screens/FountainsScreen.tsx | 171+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-merchant-webui/src/screens/screens.test.tsx | 5+++++
Mpackages/taler-merchant-webui/src/stories/story-data.tsx | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-merchant-webui/src/stories/story-messages.ts | 16++++++++++++++++
Mpackages/taler-merchant-webui/src/ui/ConfirmDeleteModal.tsx | 13++++++++++---
11 files changed, 641 insertions(+), 10 deletions(-)

diff --git a/packages/taler-merchant-webui/src/api/hooks.ts b/packages/taler-merchant-webui/src/api/hooks.ts @@ -27,6 +27,7 @@ export * from "./hooks/useAccessTokens.js"; export * from "./hooks/useBusinessSettings.js"; export * from "./hooks/useWebhooks.js"; export * from "./hooks/useTokenFamilies.js"; +export * from "./hooks/useFountains.js"; export * from "./hooks/useOtpDevices.js"; export * from "./hooks/useReportsAndStats.js"; export * from "./hooks/useTransfersAndKyc.js"; diff --git a/packages/taler-merchant-webui/src/api/hooks/useFountains.ts b/packages/taler-merchant-webui/src/api/hooks/useFountains.ts @@ -0,0 +1,192 @@ +/* + 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 { useEffect, useState } from "preact/hooks"; +import { mutate } from "swr"; +import { useMerchantSWR as useSWR } from "../swr.js"; +import { + FountainCreateRequest, + FountainCreateResponse, + type FountainEntry, + MerchantFountainDetails, +} from "@gnu-taler/taler-util"; +import { merchantClient } from "../client.js"; +import { unwrap, unwrapEmpty } from "../failure.js"; +import { captureSessionIdentity, session } from "../../stores/session.js"; +import { getClientConfig } from "./common.js"; +import { getMerchantBackendFeatures } from "../merchantBackendFeatures.js"; +import { useMerchantConfig } from "./useMerchantConfig.js"; +import { remoteResource } from "../contracts.js"; + +interface FountainPage { + rows: FountainEntry[]; + trail: number[]; +} + +const pageSize = 20; +// Keep the cursor trail across list/detail route remounts within one login. +let lastPage: { scope: string; trail: number[] } | undefined; + +export function useFountains() { + const token = session.value.token; + const config = getClientConfig(); + const scope = JSON.stringify([ + config.rootUrl.href, + config.account, + captureSessionIdentity()?.generation, + ]); + const [trail, setTrail] = useState<number[]>(() => + lastPage?.scope === scope ? lastPage.trail : [], + ); + const merchant = useMerchantConfig(); + const { fountainPagination: paged, fountainDisplayName } = + getMerchantBackendFeatures(merchant.config?.version); + const key = [ + "listFountains", + config.rootUrl.href, + config.account, + token, + paged ? trail : "legacy", + ]; + const swr = useSWR<FountainPage>( + token && merchant.config ? key : null, + async () => { + const { fountains } = unwrap( + await merchantClient(config).listFountains( + token!, + paged ? { limit: -(pageSize + 1), offset: trail.at(-1) } : {}, + ), + ); + if ( + paged && + fountains.length > pageSize && + !Number.isSafeInteger(fountains[pageSize - 1]?.fountain_serial) + ) + throw new Error("Invalid fountain pagination cursor"); + return { rows: paged ? fountains : fountains.reverse(), trail }; + }, + { keepPreviousData: true }, + ); + const displayedTrail = paged ? (swr.data?.trail ?? trail) : trail; + const start = paged ? 0 : trail.length * pageSize; + const rows = swr.data?.rows.slice(start, start + pageSize); + const hasNext = (swr.data?.rows.length ?? 0) > start + pageSize; + const pending = + paged && + (displayedTrail.length !== trail.length || + displayedTrail.at(-1) !== trail.at(-1)); + useEffect(() => { + if (!swr.data || pending) return; + if (rows?.length === 0 && trail.length) { + setTrail(trail.slice(0, -1)); + return; + } + lastPage = { scope, trail }; + }, [scope, trail, swr.data, pending]); + // A successful mutation must stay successful when a follow-up read fails. + // In particular, never lose a one-time credential to cache revalidation. + const refresh = () => { + void swr.mutate().catch(() => {}); + }; + function authenticatedClient() { + if (!token) throw new Error("No authenticated merchant session"); + return merchantClient(config); + } + return { + fountainDisplayName, + resource: merchant.config + ? { ...remoteResource(swr), data: rows } + : { ...merchant.resource, data: undefined }, + pagination: { + page: displayedTrail.length + 1, + pending, + hasNext, + previous: () => setTrail(displayedTrail.slice(0, -1)), + next: () => { + if (hasNext && rows?.length) + setTrail([ + ...displayedTrail, + paged ? rows[pageSize - 1]!.fountain_serial! : start + pageSize, + ]); + }, + }, + async createFountain( + body: FountainCreateRequest, + ): Promise<FountainCreateResponse> { + const result = unwrap( + await authenticatedClient().createFountain(token!, body), + ); + if (trail.length) { + lastPage = { scope, trail: [] }; + setTrail([]); + } + refresh(); + return result; + }, + async updateFountain( + id: string, + body: MerchantFountainDetails, + ): Promise<void> { + unwrapEmpty(await authenticatedClient().updateFountain(token!, id, body)); + refresh(); + void mutate( + ["getFountainDetails", config.rootUrl.href, config.account, token, id], + (previous: MerchantFountainDetails | undefined) => ({ + ...previous, + ...body, + }), + ).catch(() => {}); + }, + async deleteFountain(id: string): Promise<void> { + unwrapEmpty(await authenticatedClient().deleteFountain(token!, id)); + // A previous page may have cached this row as its lookahead. + void mutate( + (cachedKey) => + Array.isArray(cachedKey) && + cachedKey[0] === "listFountains" && + cachedKey[1] === config.rootUrl.href && + cachedKey[2] === config.account && + cachedKey[3] === token, + (page: FountainPage | undefined) => + page && { + ...page, + rows: page.rows.filter((row) => row.fountain_id !== id), + }, + false, + ) + .then(refresh) + .catch(() => {}); + void mutate( + ["getFountainDetails", config.rootUrl.href, config.account, token, id], + undefined, + false, + ).catch(() => {}); + }, + }; +} + +export function useFountainDetails(id?: string) { + const token = session.value.token; + const config = getClientConfig(); + const swr = useSWR( + token && id + ? ["getFountainDetails", config.rootUrl.href, config.account, token, id] + : null, + async () => + unwrap(await merchantClient(config).getFountainDetails(token!, id!)), + ); + return { resource: remoteResource(swr) }; +} diff --git a/packages/taler-merchant-webui/src/api/merchantBackendFeatures.test.ts b/packages/taler-merchant-webui/src/api/merchantBackendFeatures.test.ts @@ -25,15 +25,24 @@ test("report delivery endpoints require a backend supporting protocol v45", () = } }); -test("challenge signatures require merchant protocol v43", () => { - for (const [version, signing] of [ - [undefined, false], - ["42:0:30", false], - ["43:0:31", true], - ["44:0:32", true], - ["45:0:33", true], +test("fountain display names require merchant protocol v46", () => { + assert.equal( + getMerchantBackendFeatures("45:0:33").fountainDisplayName, + false, + ); + assert.equal(getMerchantBackendFeatures("46:0:34").fountainDisplayName, true); +}); + +test("device signing and fountain pagination follow their respective merchant protocol versions", () => { + for (const [version, signing, paging] of [ + [undefined, false, false], + ["42:0:30", false, false], + ["43:0:31", true, false], + ["44:0:32", true, true], + ["45:0:33", true, true], ] as const) { const features = getMerchantBackendFeatures(version); assert.equal(features.challengeSignatures, signing); + assert.equal(features.fountainPagination, paging); } }); diff --git a/packages/taler-merchant-webui/src/api/merchantBackendFeatures.ts b/packages/taler-merchant-webui/src/api/merchantBackendFeatures.ts @@ -11,6 +11,8 @@ import { LibtoolVersion } from "@gnu-taler/taler-util"; export interface MerchantBackendFeatures { reportDeliveries: boolean; + fountainPagination: boolean; + fountainDisplayName: boolean; challengeSignatures: boolean; salesFunnel: boolean; } @@ -24,6 +26,14 @@ export function getMerchantBackendFeatures( // supported merchant API. Replace this constant with a version comparison // once the endpoint is assigned a released protocol version. salesFunnel: false, + fountainPagination: LibtoolVersion.isCompatible( + "44:0:0", + protocolVersion ?? "", + ), + fountainDisplayName: LibtoolVersion.isCompatible( + "46:0:0", + protocolVersion ?? "", + ), challengeSignatures: LibtoolVersion.isCompatible( "43:0:0", protocolVersion ?? "", diff --git a/packages/taler-merchant-webui/src/routes/fountains.test.tsx b/packages/taler-merchant-webui/src/routes/fountains.test.tsx @@ -25,6 +25,7 @@ import { TalerUriAction, TalerUris, } from "@gnu-taler/taler-util"; +import { FountainsScreen } from "../screens/FountainsScreen.js"; import { FountainFormScreen } from "../screens/FountainFormScreen.js"; import { FountainCreatedScreen } from "../screens/FountainCreatedScreen.js"; import { @@ -104,6 +105,40 @@ function assertSecretNotPersisted() { assert.ok(!values.join(" ").includes(secret)); } +test("fountain lists distinguish loading, failure and empty data", () => { + for (const state of [ + { ...resource(undefined), isLoading: true }, + { + ...resource(undefined), + error: normalizeApiFailure(new Error("unavailable")), + }, + resource([]), + ]) { + const view = mount( + <FountainsScreen + resource={state} + onCreate={() => {}} + onDelete={async () => {}} + />, + ); + try { + assert.equal( + view.container.textContent?.includes("No fountains yet"), + state.data !== undefined, + ); + if (state.isLoading) + assert.match(view.container.textContent ?? "", /Loading/); + if (state.error) + assert.match( + view.container.textContent ?? "", + /Could not load fountains/, + ); + } finally { + view.close(); + } + } +}); + test("fountain grant validation permits empty grants and enforces protocol bounds", () => { assert.equal(fountainValidationError(defaultFountain, translate), undefined); const valid: FountainCreateRequest = { diff --git a/packages/taler-merchant-webui/src/screens/FountainDetailsScreen.tsx b/packages/taler-merchant-webui/src/screens/FountainDetailsScreen.tsx @@ -0,0 +1,100 @@ +/* + 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 { Duration, MerchantFountainDetails } from "@gnu-taler/taler-util"; +import type { RemoteResource } from "../api/contracts.js"; +import { Header } from "../ui/Header.js"; +import { ReadErrorBanner } from "../ui/ReadErrorBanner.js"; +import { InitialLoadingState } from "../ui/InitialLoadingState.js"; +import { useTranslation } from "../context/translation.js"; + +export function FountainDetailsScreen({ + id, + resource, + onBack, + onEdit, +}: { + id: string; + resource: RemoteResource<MerchantFountainDetails>; + onBack: () => void; + onEdit: () => void; +}): VNode { + const { t } = useTranslation(); + const details = resource.data; + return ( + <div class="space-y-6"> + <Header + title={details?.description || t`Fountain details`} + subtitle={id} + onBack={onBack} + backLabel={t`Fountains`} + primaryActionText={details ? t`Edit fountain` : undefined} + onPrimaryAction={onEdit} + /> + <ReadErrorBanner + resource={resource} + title={t`Could not load fountain details`} + /> + {!details ? ( + resource.isLoading ? ( + <InitialLoadingState>{t`Loading…`}</InitialLoadingState> + ) : null + ) : ( + <> + <p class="rounded-lg bg-blue-50 p-4 text-sm text-blue-900">{t`The wallet import code is shown only when the fountain is created. It cannot be retrieved later.`}</p> + <div class="rounded-xl border bg-white p-5 space-y-3"> + <h2 class="font-bold">{t`Wallet polling interval`}</h2> + <p> + {details.poll_freq.d_us === "forever" + ? t`Forever` + : Duration.formatPretty(details.poll_freq)} + </p> + <p class="text-sm text-gray-600">{t`Wallets learn about changed grants the next time they poll.`}</p> + </div> + <section class="space-y-3"> + <h2 class="font-bold">{t`Grants`}</h2> + {details.grants.length === 0 && ( + <p class="text-sm text-gray-600">{t`No grants. Wallets can import this fountain and wait for grants to be added.`}</p> + )} + {details.grants.map((g) => ( + <article + key={g.token_family_slug} + class="rounded-xl border bg-white p-5" + > + <h3 class="font-bold break-all">{g.token_family_slug}</h3> + <dl class="mt-3 grid gap-3 sm:grid-cols-3"> + <div> + <dt class="text-xs text-gray-500">{t`Per-period limit`}</dt> + <dd>{g.tokens_per_period_limit}</dd> + </div> + <div> + <dt class="text-xs text-gray-500">{t`Stocking target`}</dt> + <dd>{g.tokens_per_period_stash}</dd> + </div> + <div> + <dt class="text-xs text-gray-500">{t`Future periods`}</dt> + <dd>{g.key_window_size}</dd> + </div> + </dl> + </article> + ))} + </section> + </> + )} + </div> + ); +} diff --git a/packages/taler-merchant-webui/src/screens/FountainsScreen.tsx b/packages/taler-merchant-webui/src/screens/FountainsScreen.tsx @@ -0,0 +1,171 @@ +/* + 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 { useState } from "preact/hooks"; +import type { VNode } from "preact"; +import type { FountainEntry } from "@gnu-taler/taler-util"; +import type { RemoteResource } from "../api/contracts.js"; +import { Header } from "../ui/Header.js"; +import { Button } from "../ui/Button.js"; +import { ReadErrorBanner } from "../ui/ReadErrorBanner.js"; +import { InitialLoadingState } from "../ui/InitialLoadingState.js"; +import { ConfirmDeleteModal } from "../ui/ConfirmDeleteModal.js"; +import { useDeleteConfirm } from "../ui/useDeleteConfirm.js"; +import { useTranslation } from "../context/translation.js"; +import { resourcePath } from "../routing/resourcePath.js"; + +export interface FountainsScreenProps { + resource: RemoteResource<FountainEntry[]>; + pagination?: { + page: number; + hasNext: boolean; + pending: boolean; + next: () => void; + previous: () => void; + }; + onCreate: () => void; + onDelete: (id: string) => Promise<void>; +} +export function FountainsScreen({ + resource, + pagination, + onCreate, + onDelete, +}: FountainsScreenProps): VNode { + const { t } = useTranslation(); + const deletion = useDeleteConfirm<{ id: string; description: string }>( + onDelete, + ); + const [typedId, setTypedId] = useState(""); + return ( + <div class="space-y-6"> + <Header + title={t`Fountains`} + subtitle={t`Distribute discounts and passes directly to wallets.`} + primaryActionText={t`Create fountain`} + onPrimaryAction={onCreate} + /> + <ReadErrorBanner + resource={resource} + title={t`Could not load fountains`} + /> + {resource.data === undefined ? ( + resource.isLoading ? ( + <InitialLoadingState>{t`Loading…`}</InitialLoadingState> + ) : null + ) : resource.data.length === 0 && (pagination?.page ?? 1) === 1 ? ( + <p class="rounded-xl border bg-white p-6 text-gray-600">{t`No fountains yet. Create one to distribute discounts or passes.`}</p> + ) : ( + <ul + class="space-y-3" + aria-busy={pagination?.pending && resource.isRefreshing} + > + {resource.data.map((f) => ( + <li + key={f.fountain_id} + class="flex flex-col gap-4 rounded-xl border border-gray-200 bg-white p-5 sm:flex-row sm:items-center sm:justify-between" + > + <div class="min-w-0"> + <a + class="font-bold text-blue-700 hover:underline break-words" + href={`#${resourcePath("/fountains", f.fountain_id)}`} + > + {f.description || f.fountain_id} + </a> + <p class="text-xs font-mono text-gray-500 break-all"> + {f.fountain_id} + </p> + </div> + <div class="flex items-center gap-3 shrink-0"> + <a + class="text-sm font-semibold text-blue-700 hover:underline" + href={`#${resourcePath("/fountains", f.fountain_id, "edit")}`} + >{t`Edit`}</a> + <Button + variant="danger" + disabled={pagination?.pending} + onClick={() => { + setTypedId(""); + deletion.setDeletingItem({ + id: f.fountain_id, + description: f.description, + }); + }} + >{t`Delete`}</Button> + </div> + </li> + ))} + </ul> + )} + {pagination && (pagination.page > 1 || pagination.hasNext) && ( + <nav + aria-label={t`Fountain pages`} + class="flex flex-wrap items-center justify-center gap-4" + > + <Button + variant="secondary" + disabled={pagination.pending || pagination.page === 1} + onClick={pagination.previous} + >{t`Previous`}</Button> + <span aria-live="polite">{t`Page ${pagination.page}`}</span> + <Button + variant="secondary" + disabled={pagination.pending || !pagination.hasNext} + onClick={pagination.next} + >{t`Next`}</Button> + </nav> + )} + <ConfirmDeleteModal + isOpen={!!deletion.deletingItem} + onClose={deletion.cancelDelete} + title={t`Delete fountain?`} + description={t`Deleting this fountain stops future withdrawals. Discounts and passes already issued remain valid until they expire.`} + confirmLabel={t`Delete fountain`} + confirmDisabled={ + !deletion.deletingItem || typedId.trim() !== deletion.deletingItem.id + } + onConfirm={deletion.confirmDelete} + isPending={deletion.isDeleting} + error={deletion.deleteError} + > + {deletion.deletingItem && ( + <div class="space-y-2"> + <p class="break-words font-semibold"> + {deletion.deletingItem.description} + </p> + <p class="break-all font-mono select-all"> + {deletion.deletingItem.id} + </p> + <label + for="revoke-fountain-id" + class="block text-sm" + >{t`Enter the fountain ID to confirm deletion.`}</label> + <input + id="revoke-fountain-id" + class="w-full rounded border p-2 font-mono" + value={typedId} + disabled={deletion.isDeleting} + autoCapitalize="none" + autoComplete="off" + spellcheck={false} + onInput={(e) => setTypedId(e.currentTarget.value)} + /> + </div> + )} + </ConfirmDeleteModal> + </div> + ); +} diff --git a/packages/taler-merchant-webui/src/screens/screens.test.tsx b/packages/taler-merchant-webui/src/screens/screens.test.tsx @@ -8339,6 +8339,10 @@ test("a migrated screen does not fetch its own data", async () => { "SelfProvisionScreen", "DevicesScreen", "SubscriptionsScreen", + "FountainsScreen", + "FountainDetailsScreen", + "FountainFormScreen", + "FountainCreatedScreen", "ScheduleReportScreen", "ServerInfoScreen", "InventoryScreen", @@ -8647,6 +8651,7 @@ test("a screen that is not in the menu offers a way back", async () => { "GuidedSetupScreen", "BusinessSettingsScreen", "SubscriptionsScreen", + "FountainsScreen", "WebhooksScreen", "DevicesScreen", "AccessScreen", diff --git a/packages/taler-merchant-webui/src/stories/story-data.tsx b/packages/taler-merchant-webui/src/stories/story-data.tsx @@ -44,6 +44,11 @@ import { AccessScreen } from "../screens/AccessScreen.js"; import { StatisticsScreen } from "../screens/StatisticsScreen.js"; import { ReportsScreen } from "../screens/ReportsScreen.js"; import { WebhooksScreen } from "../screens/WebhooksScreen.js"; +import { FountainsScreen } from "../screens/FountainsScreen.js"; +import { FountainFormScreen } from "../screens/FountainFormScreen.js"; +import { FountainDetailsScreen } from "../screens/FountainDetailsScreen.js"; +import { FountainCreatedScreen } from "../screens/FountainCreatedScreen.js"; +import { fountainImportUri } from "../utils/fountains.js"; import { SubscriptionsScreen } from "../screens/SubscriptionsScreen.js"; import { PaymentServicesScreen } from "../screens/PaymentServicesScreen.js"; import { CreateOrderScreen } from "../screens/CreateOrderScreen.js"; @@ -727,6 +732,19 @@ function TokenSetupWizardStory() { ); } +const FOUNTAIN = { + description: "Coffee Club", + poll_freq: { d_us: 3600_000_000 }, + grants: [ + { + token_family_slug: "coffee-club", + tokens_per_period_limit: 3, + tokens_per_period_stash: 2, + key_window_size: 1, + }, + ], +}; + export const STORIES: Story[] = [ { id: "ui-token-selector", @@ -748,6 +766,73 @@ export const STORIES: Story[] = [ ), }, { + id: "integration-fountains", + category: "Integration & Advanced", + name: "Fountains", + description: "Distribute discounts and passes directly to wallets.", + render: () => ( + <FountainsScreen + resource={storyResource([ + { fountain_id: "coffee-club", description: FOUNTAIN.description }, + ])} + onCreate={() => undefined} + onDelete={async () => undefined} + /> + ), + }, + { + id: "integration-fountain-form", + category: "Integration & Advanced", + name: "Create fountain", + description: + "Choose which discounts or passes wallets can collect and how many they may receive.", + render: () => ( + <FountainFormScreen + initial={FOUNTAIN} + families={storyResource([ + { slug: "coffee-club", name: "Coffee Club" }, + { slug: "annual-vip", name: "Annual VIP" }, + ])} + onCancel={() => undefined} + onSave={async () => ({ type: "success", value: undefined })} + /> + ), + }, + { + id: "integration-fountain-detail", + category: "Integration & Advanced", + name: "Fountain details", + description: "Wallets learn about changed grants the next time they poll.", + render: () => ( + <FountainDetailsScreen + id="coffee-club" + resource={storyResource(FOUNTAIN)} + onBack={() => undefined} + onEdit={() => undefined} + /> + ), + }, + { + id: "integration-fountain-created", + category: "Integration & Advanced", + name: "Fountain created", + description: "Scan with a Taler wallet to import this fountain.", + render: () => ( + <FountainCreatedScreen + fountain={{ + id: "coffee-club", + description: FOUNTAIN.description, + uri: fountainImportUri( + "https://merchant.example/instances/coffee/", + "coffee-club", + "0".repeat(52), + ), + }} + onDone={() => undefined} + /> + ), + }, + { id: "administration-accounts", category: "Administration", name: "Merchant Account Administration", diff --git a/packages/taler-merchant-webui/src/stories/story-messages.ts b/packages/taler-merchant-webui/src/stories/story-messages.ts @@ -32,6 +32,22 @@ export function translateStoryMetadata(source: string, t: TranslateFn): string { return t`Search products and categories, select multiple items, and remove selected chips.`; case "Product and category multi-select": return t`Product and category multi-select`; + case "Fountains": + return t`Fountains`; + case "Distribute discounts and passes directly to wallets.": + return t`Distribute discounts and passes directly to wallets.`; + case "Create fountain": + return t`Create fountain`; + case "Choose which discounts or passes wallets can collect and how many they may receive.": + return t`Choose which discounts or passes wallets can collect and how many they may receive.`; + case "Fountain details": + return t`Fountain details`; + case "Wallets learn about changed grants the next time they poll.": + return t`Wallets learn about changed grants the next time they poll.`; + case "Fountain created": + return t`Fountain created`; + case "Scan with a Taler wallet to import this fountain.": + return t`Scan with a Taler wallet to import this fountain.`; case "3x4 touch numeric numpad for ad-hoc quick charge payments.": return t`3x4 touch numeric numpad for ad-hoc quick charge payments.`; case "4-step setup status guide summarizing business info, payout accounts, verification, and selling options.": diff --git a/packages/taler-merchant-webui/src/ui/ConfirmDeleteModal.tsx b/packages/taler-merchant-webui/src/ui/ConfirmDeleteModal.tsx @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import type { VNode } from "preact"; +import type { ComponentChildren, VNode } from "preact"; import { Modal } from "./Modal.js"; import { Button } from "./Button.js"; import { useTranslation } from "../context/translation.js"; @@ -28,6 +28,8 @@ export interface ConfirmDeleteModalProps { onConfirm: () => Promise<void> | void; isPending?: boolean; error?: unknown; + children?: ComponentChildren; + confirmDisabled?: boolean; confirmLabel?: string; cancelLabel?: string; } @@ -38,6 +40,8 @@ export function ConfirmDeleteModal({ title, description, onConfirm, + children, + confirmDisabled, confirmLabel, cancelLabel, isPending = false, @@ -54,6 +58,7 @@ export function ConfirmDeleteModal({ title={title} > <p class="text-xs text-gray-700 leading-relaxed">{description}</p> + {children} <ApiErrorBanner compact error={error} @@ -70,9 +75,11 @@ export function ConfirmDeleteModal({ </Button> <Button variant="danger" - onClick={() => void onConfirm()} + onClick={() => { + if (!confirmDisabled && !isPending) void onConfirm(); + }} isLoading={isPending} - disabled={isPending} + disabled={confirmDisabled || isPending} > {confirmLabel || t`Delete`} </Button>