taler-typescript-core

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

commit 69fb5d6a39f01ffc614b103ac774e70e01ce240a
parent 845b0d790141e93ac7b2a4d6fb6f91e147f20e8b
Author: Sebastian <sebasjm@taler-systems.com>
Date:   Thu,  2 Apr 2026 20:47:48 -0300

fix #11336

Diffstat:
Mpackages/merchant-backoffice-ui/src/components/product/ProductForm.tsx | 15++++-----------
Mpackages/merchant-backoffice-ui/src/hooks/order.ts | 3---
Mpackages/merchant-backoffice-ui/src/paths/instance/products/create/CreatePage.tsx | 41+++++++++++++++++++----------------------
Mpackages/merchant-backoffice-ui/src/paths/instance/products/update/UpdatePage.tsx | 40++++++++++++++++++++--------------------
Mpackages/web-util/src/hooks/useAsync.ts | 57---------------------------------------------------------
5 files changed, 43 insertions(+), 113 deletions(-)

diff --git a/packages/merchant-backoffice-ui/src/components/product/ProductForm.tsx b/packages/merchant-backoffice-ui/src/components/product/ProductForm.tsx @@ -28,7 +28,7 @@ import { TalerMerchantApi, } from "@gnu-taler/taler-util"; import { Loading, useTranslationContext } from "@gnu-taler/web-util/browser"; -import { Fragment, h } from "preact"; +import { ComponentChildren, Fragment, h } from "preact"; import { useCallback, useEffect, useState } from "preact/hooks"; import { useSessionContext } from "../../context/session.js"; import { useInstanceCategories } from "../../hooks/category.js"; @@ -60,6 +60,7 @@ interface Props { categories: TalerMerchantApi.CategoryListEntry[]; groups: TalerMerchantApi.GroupEntry[]; pots: TalerMerchantApi.PotEntry[]; + children?: ComponentChildren, } export function ProductForm({ @@ -69,6 +70,7 @@ export function ProductForm({ categories, groups = [], pots = [], + children, }: Props) { const { i18n } = useTranslationContext(); const { state } = useSessionContext(); @@ -191,16 +193,6 @@ export function ProductForm({ object={value} valueHandler={valueHandler} > - {/** - * If the user press enter on any text field it will the browser will trigger - * the first button that it found. - * - * In this form the InputImage will be triggered and this is unwanted. - * - * As a workaround we have this non-action button which will prevent loading/unloading - * the image when the enter key is pressed accidentally. - */} - <button style={{ visibility: "hidden" }} /> {alreadyExist ? undefined : ( <InputWithAddon<Entity> name="product_id" @@ -293,6 +285,7 @@ export function ProductForm({ readonly={groups.length === 0} /> </FragmentPersonaFlag> + {children} </FormProvider> </div> ); diff --git a/packages/merchant-backoffice-ui/src/hooks/order.ts b/packages/merchant-backoffice-ui/src/hooks/order.ts @@ -32,8 +32,6 @@ import { } from "@gnu-taler/web-util/browser"; import _useSWR, { mutate, SWRHook } from "swr"; import { useSessionContext } from "../context/session.js"; -import { useRef } from "preact/hooks"; -import { useEffect } from "preact/hooks"; const useSWR = _useSWR as unknown as SWRHook; @@ -177,7 +175,6 @@ export function useInstanceOrders( ? latestStatus.body.orders : [...result.body.orders, ...latestStatus.body.orders]; - console.log("u ahora",latestStatus, result, merged) const newResult = opFixedSuccess({ orders: merged }); mutate(newResult, { revalidate: false }); return newResult; diff --git a/packages/merchant-backoffice-ui/src/paths/instance/products/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/products/create/CreatePage.tsx @@ -119,29 +119,26 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { categories={categories} groups={groups} pots={pots} - /> - - <div class="buttons is-right mt-5"> - {onBack && ( - <button class="button" onClick={onBack}> - <i18n.Translate>Cancel</i18n.Translate> - </button> - )} - <Tooltip - text={ - !create.args - ? i18n.str`Please complete the marked fields` - : i18n.str`Confirm operation` - } - > - <ButtonBetterBulma - onClick={create} - type="submit" + > + <div class="buttons is-right mt-5"> + {onBack && ( + <button class="button" onClick={onBack}> + <i18n.Translate>Cancel</i18n.Translate> + </button> + )} + <Tooltip + text={ + !create.args + ? i18n.str`Please complete the marked fields` + : i18n.str`Confirm operation` + } > - <i18n.Translate>Confirm</i18n.Translate> - </ButtonBetterBulma> - </Tooltip> - </div> + <ButtonBetterBulma onClick={create} type="submit"> + <i18n.Translate>Confirm</i18n.Translate> + </ButtonBetterBulma> + </Tooltip> + </div> + </ProductForm> </div> <div class="column" /> </div> diff --git a/packages/merchant-backoffice-ui/src/paths/instance/products/update/UpdatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/products/update/UpdatePage.tsx @@ -135,26 +135,26 @@ export function UpdatePage({ product, onBack, onConfirm }: Props): VNode { groups={groups} pots={pots} categories={categories} - /> - - <div class="buttons is-right mt-5"> - {onBack && ( - <button type="button" class="button" onClick={onBack}> - <i18n.Translate>Cancel</i18n.Translate> - </button> - )} - <Tooltip - text={ - !update.args - ? i18n.str`Please complete the marked fields` - : i18n.str`Confirm operation` - } - > - <ButtonBetterBulma onClick={update} type="submit"> - <i18n.Translate>Confirm</i18n.Translate> - </ButtonBetterBulma> - </Tooltip> - </div> + > + <div class="buttons is-right mt-5"> + {onBack && ( + <button type="button" class="button" onClick={onBack}> + <i18n.Translate>Cancel</i18n.Translate> + </button> + )} + <Tooltip + text={ + !update.args + ? i18n.str`Please complete the marked fields` + : i18n.str`Confirm operation` + } + > + <ButtonBetterBulma onClick={update} type="submit"> + <i18n.Translate>Confirm</i18n.Translate> + </ButtonBetterBulma> + </Tooltip> + </div> + </ProductForm> </div> <div class="column" /> </div> diff --git a/packages/web-util/src/hooks/useAsync.ts b/packages/web-util/src/hooks/useAsync.ts @@ -164,60 +164,3 @@ export async function delayMs(ms: number): Promise<void> { }); } -/** - * If the function `fn` is called faster than `minTime` wait - * before calling again. - * - * Helps to prevent burst calling when the server does not implement - * long polling correctly. - * - * @returns a wrapper of `fn` function - */ -export function preventBurst<type, args>( - fn: (...args: args[]) => Promise<type>, - opts: { - minTimeMs?: number; - errorTimeMs?: number; - } = {}, -): typeof fn { - const mt = opts.minTimeMs ?? 3000; - const et = opts.errorTimeMs ?? mt; - - let nextCallShouldWait = 0; - console.log("nooo"); - return async (...args): Promise<type> => { - const start = new Date().getTime(); - console.log("que onda", nextCallShouldWait); - if (nextCallShouldWait > 0) { - console.log("waiting", nextCallShouldWait); - await delayMs(nextCallShouldWait); - nextCallShouldWait = 0; - } - const r = fn(...args) - .then((result) => { - const diff = new Date().getTime() - start; - nextCallShouldWait = Math.max(0, mt - diff); - console.log( - "next call", - nextCallShouldWait, - diff, - mt, - Math.max(0, mt - diff), - ); - return result; - }) - .catch((error) => { - const diff = new Date().getTime() - start; - console.log( - "error call", - nextCallShouldWait, - diff, - et, - Math.max(0, et - diff), - ); - nextCallShouldWait = Math.max(0, et - diff); - throw error; - }); - return r; - }; -}