taler-typescript-core

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

commit e9ea0e569eda3ba61fd39a1617c7a970967326cd
parent 460b2808ea3a4cd62a07cd9e9cb4ddced399872c
Author: Florian Dold <dold@taler.net>
Date:   Fri, 13 Nov 2026 01:06:16 +0100

merchant web UI: focus creation and refund forms

Choose the first field for products, devices, access, bank accounts,
orders and reports. Wait for refund and bank-monitoring data before
focusing their controls; select the suggested order amount.

Issue: https://bugs.taler.net/n/12006
Issue: https://bugs.taler.net/n/12011
Issue: https://bugs.taler.net/n/12012
Issue: https://bugs.taler.net/n/12013
Issue: https://bugs.taler.net/n/12014
Issue: https://bugs.taler.net/n/12015
Issue: https://bugs.taler.net/n/12016
Issue: https://bugs.taler.net/n/12017
Assisted-by: LLM

Diffstat:
Mpackages/taler-merchant-webui/src/screens/AddPayoutAccountScreen.tsx | 12+++++++++++-
Mpackages/taler-merchant-webui/src/screens/BankMonitoringDialog.tsx | 8++++++++
Mpackages/taler-merchant-webui/src/screens/CreateAccessScreen.tsx | 7++++++-
Mpackages/taler-merchant-webui/src/screens/CreateDeviceScreen.tsx | 6++++++
Mpackages/taler-merchant-webui/src/screens/CreateOrderScreen.tsx | 14++++++++++++--
Mpackages/taler-merchant-webui/src/screens/CreateProductScreen.tsx | 8+++++++-
Mpackages/taler-merchant-webui/src/screens/OrderRefundScreen.tsx | 16+++++++++++++++-
Mpackages/taler-merchant-webui/src/screens/ScheduleReportScreen.tsx | 8+++++++-
8 files changed, 72 insertions(+), 7 deletions(-)

diff --git a/packages/taler-merchant-webui/src/screens/AddPayoutAccountScreen.tsx b/packages/taler-merchant-webui/src/screens/AddPayoutAccountScreen.tsx @@ -14,9 +14,10 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { useFocusScope, firstEditableField } from "@gnu-taler/web-util/browser"; import { FormActionFooter, useFormFeedback } from "../ui/FormActionFooter.js"; import type { VNode } from "preact"; -import { useEffect, useMemo, useState } from "preact/hooks"; +import { useEffect, useMemo, useRef, useState } from "preact/hooks"; import { validateIban, Paytos, @@ -87,6 +88,14 @@ export function AddPayoutAccountScreen({ feedbackId, } = useFormFeedback(); + // Start on the account's first field, past the method chooser, which + // already holds the usual choice. + const form = useRef<HTMLFormElement>(null); + useFocusScope({ + root: () => form.current, + initialFocus: () => firstEditableField(form.current, true), + }); + useEffect(() => { if (allowedMethods.length > 0 && !allowedMethods.includes(wireMethod)) { setWireMethod(allowedMethods[0]!); @@ -170,6 +179,7 @@ export function AddPayoutAccountScreen({ /> <form + ref={form} onSubmit={handleSubmit} class="bg-white border border-gray-200 rounded-xl p-6 shadow-sm space-y-5" > diff --git a/packages/taler-merchant-webui/src/screens/BankMonitoringDialog.tsx b/packages/taler-merchant-webui/src/screens/BankMonitoringDialog.tsx @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { useEffect, useRef, useState } from "preact/hooks"; import type { TalerMerchantApi } from "@gnu-taler/taler-util"; import type { PayoutAccount } from "../types/domain.js"; @@ -134,6 +135,11 @@ function BankMonitoringForm({ } = useFormFeedback(); const fieldClass = "mt-1 w-full rounded-md border border-gray-300 px-3 py-2 text-sm"; + // The dialog opened on its close button while the settings loaded; now that + // they are here, start on the first setting: the history URL when + // monitoring is on, the switch that turns it on otherwise. + const firstField = useRef<HTMLInputElement>(null); + useFocusScope({ initialFocus: () => firstField.current }); return ( <form class="space-y-4" @@ -201,6 +207,7 @@ function BankMonitoringForm({ <fieldset disabled={saving} class="space-y-4"> <label class="flex items-center gap-2 text-sm font-medium"> <input + ref={enabled ? undefined : firstField} id="bank-monitoring-enabled" type="checkbox" checked={enabled} @@ -216,6 +223,7 @@ function BankMonitoringForm({ > {t`Bank history URL`} <input + ref={firstField} {...fieldProps("bank-monitoring-url")} id="bank-monitoring-url" type="url" diff --git a/packages/taler-merchant-webui/src/screens/CreateAccessScreen.tsx b/packages/taler-merchant-webui/src/screens/CreateAccessScreen.tsx @@ -14,8 +14,9 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { useFocusScope } from "@gnu-taler/web-util/browser"; import type { VNode } from "preact"; -import { useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; import { useLocation } from "wouter-preact"; import { Header } from "../ui/Header.js"; import { useTranslation, type TranslateFn } from "../context/translation.js"; @@ -119,6 +120,9 @@ export function CreateAccessScreen({ // Form State (Spec 02 § 2.6.1) const [usedFor, setUsedFor] = useState<string>(""); + // New access starts with what it is for. + const usedForInput = useRef<HTMLInputElement>(null); + useFocusScope({ initialFocus: () => usedForInput.current }); const [canDo, setCanDo] = useState<string>("take_payments"); const [expires, setExpires] = useState<string>("30d"); const [password, setPassword] = useState<string>(""); @@ -217,6 +221,7 @@ export function CreateAccessScreen({ {t`Used for`} <span class="text-red-500">*</span> </label> <input + ref={usedForInput} {...fieldProps("acc_used_for")} id="acc_used_for" type="text" diff --git a/packages/taler-merchant-webui/src/screens/CreateDeviceScreen.tsx b/packages/taler-merchant-webui/src/screens/CreateDeviceScreen.tsx @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { useFocusScope } from "@gnu-taler/web-util/browser"; import type { VNode } from "preact"; import { currentBackendUrl, session } from "../stores/session.js"; import { useRef, useState } from "preact/hooks"; @@ -193,6 +194,10 @@ function CreateDeviceForm({ .replace(/^_+|_+$/g, ""); const [name, setName] = useState<string>(existingDevice?.name || ""); + // A new device starts with its name. When editing, no field in particular + // comes first. + const nameInput = useRef<HTMLInputElement>(null); + useFocusScope({ active: !editingId, initialFocus: () => nameInput.current }); const [deviceId, setDeviceId] = useState<string>(existingDevice?.id || ""); const [manualId, setManualId] = useState<boolean>( Boolean(existingDevice?.id), @@ -330,6 +335,7 @@ function CreateDeviceForm({ {t`Name`} <span class="text-red-500">*</span> </label> <input + ref={nameInput} id="auth_name" type="text" required diff --git a/packages/taler-merchant-webui/src/screens/CreateOrderScreen.tsx b/packages/taler-merchant-webui/src/screens/CreateOrderScreen.tsx @@ -14,8 +14,9 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { useFocusScope } from "@gnu-taler/web-util/browser"; import type { VNode } from "preact"; -import { useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; import { useLocation } from "wouter-preact"; import { Header } from "../ui/Header.js"; import { FormActionFooter, useFormFeedback } from "../ui/FormActionFooter.js"; @@ -232,6 +233,15 @@ export function CreateOrderScreen({ "quick", ); const [amountInput, setAmountInput] = useState<string>("10.00"); + // An order starts with its amount. The suggested one is selected so that + // typing replaces it. + const form = useRef<HTMLFormElement>(null); + useFocusScope({ + root: () => form.current, + initialFocus: () => + form.current?.querySelector<HTMLElement>("#order-amount"), + selectText: true, + }); const [itemizedOverrideEnabled, setItemizedOverrideEnabled] = useState<boolean>(false); const [itemizedOverrideAmount, setItemizedOverrideAmount] = @@ -1235,7 +1245,7 @@ export function CreateOrderScreen({ </Header> </div> - <form onSubmit={handleSubmitOrder} class="space-y-6"> + <form ref={form} onSubmit={handleSubmitOrder} class="space-y-6"> <> <div class="flex rounded-xl border border-gray-300 bg-gray-100 p-1" diff --git a/packages/taler-merchant-webui/src/screens/CreateProductScreen.tsx b/packages/taler-merchant-webui/src/screens/CreateProductScreen.tsx @@ -14,12 +14,13 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { ProductLossFields } from "./ProductLossFields.js"; import type { RecordLoss } from "../utils/inventory.js"; import type { VNode } from "preact"; import { session } from "../stores/session.js"; import { Amounts } from "@gnu-taler/taler-util"; -import { useEffect, useState } from "preact/hooks"; +import { useEffect, useRef, useState } from "preact/hooks"; import { useLocation } from "wouter-preact"; import { Header } from "../ui/Header.js"; import { FormActionFooter, useFormFeedback } from "../ui/FormActionFooter.js"; @@ -266,6 +267,10 @@ function CreateProductForm({ // Form State (Spec 07 § 7.2) const [name, setName] = useState<string>(existing?.name || ""); + // A new product starts with its name. When editing, no field in particular + // comes first. + const nameInput = useRef<HTMLInputElement>(null); + useFocusScope({ active: !isEditing, initialFocus: () => nameInput.current }); const [productId, setProductId] = useState<string>(existing?.id || ""); const [manualId, setManualId] = useState<boolean>(!!existing?.id); const [description, setDescription] = useState<string>( @@ -555,6 +560,7 @@ function CreateProductForm({ {t`Product Name`} <span class="text-red-500">*</span> </label> <input + ref={nameInput} {...fieldProps("prod_name_input")} id="prod_name_input" type="text" diff --git a/packages/taler-merchant-webui/src/screens/OrderRefundScreen.tsx b/packages/taler-merchant-webui/src/screens/OrderRefundScreen.tsx @@ -14,11 +14,12 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { Amounts, AbsoluteTime } from "@gnu-taler/taler-util"; import { useLocation } from "wouter-preact"; import { FormActionFooter, useFormFeedback } from "../ui/FormActionFooter.js"; import type { VNode } from "preact"; -import { useState, useEffect } from "preact/hooks"; +import { useState, useEffect, useRef } from "preact/hooks"; import { Header } from "../ui/Header.js"; import { ApiErrorBanner } from "../ui/ApiErrorBanner.js"; import { ReadErrorBanner } from "../ui/ReadErrorBanner.js"; @@ -158,6 +159,18 @@ export function OrderRefundScreen({ // eslint-disable-next-line react-hooks/exhaustive-deps -- only a new order amount should reset the field; re-running when the preset changes would fight the merchant's own choice. }, [remainingAmount]); + // The amount is what this screen exists to ask for. The form only appears + // once the order has loaded, so focus follows the order rather than the + // mount, and a background refresh of the same order leaves focus alone. + const form = useRef<HTMLFormElement>(null); + useFocusScope({ + root: () => form.current, + activationKey: order?.orderId, + ready: !!order, + initialFocus: () => + form.current?.querySelector<HTMLElement>("#refund-amount-input"), + }); + const handleSelectPreset = (percent: number, presetLabel: string) => { setSelectedPreset(presetLabel); if (!remainingAmount) return; @@ -312,6 +325,7 @@ export function OrderRefundScreen({ {/* Refund Form */} <form + ref={form} onSubmit={handleSubmit} class="bg-white border border-gray-200 rounded-lg p-5 space-y-5 text-sm" > diff --git a/packages/taler-merchant-webui/src/screens/ScheduleReportScreen.tsx b/packages/taler-merchant-webui/src/screens/ScheduleReportScreen.tsx @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { useFocusScope } from "@gnu-taler/web-util/browser"; /** * Scheduling a report is creating a domain entity, so it is a Form screen with * its own route and not an overlay — see "Dialogs are reserved strictly for @@ -24,7 +25,7 @@ */ import type { VNode } from "preact"; -import { useEffect, useMemo, useState } from "preact/hooks"; +import { useEffect, useMemo, useRef, useState } from "preact/hooks"; import { useLocation } from "wouter-preact"; import { Header } from "../ui/Header.js"; import { useTranslation } from "../context/translation.js"; @@ -91,6 +92,10 @@ export function ScheduleReportScreen({ } }, [reportSenderProgram, generatorEntries]); + // The description is the first thing this form asks for. + const descInput = useRef<HTMLInputElement>(null); + useFocusScope({ initialFocus: () => descInput.current }); + const done = () => setLocation("/reports/scheduled"); const handleSubmit = async (e: Event) => { @@ -173,6 +178,7 @@ export function ScheduleReportScreen({ </label> <input {...fieldProps("rep_desc_in")} + ref={descInput} id="rep_desc_in" type="text" placeholder={t`e.g. Weekly sales summary`}