summaryrefslogtreecommitdiff
path: root/packages/web-util/src/components/Button.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/web-util/src/components/Button.tsx')
-rw-r--r--packages/web-util/src/components/Button.tsx36
1 files changed, 27 insertions, 9 deletions
diff --git a/packages/web-util/src/components/Button.tsx b/packages/web-util/src/components/Button.tsx
index 26b778eec..ea0ea2f38 100644
--- a/packages/web-util/src/components/Button.tsx
+++ b/packages/web-util/src/components/Button.tsx
@@ -1,8 +1,24 @@
-import { OperationFail, OperationOk, OperationResult, TalerError, TranslatedString } from "@gnu-taler/taler-util";
+/*
+ This file is part of GNU Taler
+ (C) 2022-2024 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 { AbsoluteTime, OperationFail, OperationOk, OperationResult, TalerError, TranslatedString } from "@gnu-taler/taler-util";
// import { NotificationMessage, notifyInfo } from "@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
import { HTMLAttributes, useEffect, useState, useTransition } from "preact/compat";
-import { NotificationMessage, buildRequestErrorMessage, notifyInfo, useTranslationContext } from "../index.browser.js";
+import { NotificationMessage, buildUnifiedRequestErrorMessage, notifyInfo, useTranslationContext } from "../index.browser.js";
// import { useBankCoreApiContext } from "../context/config.js";
// function errorMap<T extends OperationFail<unknown>>(resp: T, map: (d: T["case"]) => TranslatedString): void {
@@ -10,7 +26,7 @@ import { NotificationMessage, buildRequestErrorMessage, notifyInfo, useTranslati
export interface ButtonHandler<T extends OperationResult<A, B>, A, B> {
onClick: () => Promise<T | undefined>,
onNotification: (n: NotificationMessage) => void;
- onOperationSuccess: ((result:T extends OperationOk<any> ? T :never) => void) | ((result:T extends OperationOk<any> ? T :never) => TranslatedString | undefined),
+ onOperationSuccess: ((result: T extends OperationOk<any> ? T : never) => void) | ((result: T extends OperationOk<any> ? T : never) => TranslatedString | undefined),
onOperationFail: (d: T extends OperationFail<any> ? T : never) => TranslatedString;
onOperationComplete?: () => void;
}
@@ -33,10 +49,10 @@ export function Button<T extends OperationResult<A, B>, A, B>({
handler,
children,
disabled,
- onClick:clickEvent,
+ onClick: clickEvent,
...rest
}: Props<T, A, B>): VNode {
- const {i18n} = useTranslationContext();
+ const { i18n } = useTranslationContext();
const [running, setRunning] = useState(false)
return <button {...rest} disabled={disabled || running} onClick={(e) => {
e.preventDefault();
@@ -62,6 +78,7 @@ export function Button<T extends OperationResult<A, B>, A, B>({
type: "error",
description: error.detail.hint as TranslatedString,
debug: error.detail,
+ when: AbsoluteTime.now(),
})
}
}
@@ -71,17 +88,18 @@ export function Button<T extends OperationResult<A, B>, A, B>({
setRunning(false)
}).catch(error => {
console.error(error)
-
+
if (error instanceof TalerError) {
- handler.onNotification(buildRequestErrorMessage(i18n, error))
+ handler.onNotification(buildUnifiedRequestErrorMessage(i18n, error))
} else {
const description = (error instanceof Error ?
error.message : String(error)) as TranslatedString
-
+
handler.onNotification({
title: i18n.str`Operation failed`,
type: "error",
description,
+ when: AbsoluteTime.now(),
})
}
@@ -95,7 +113,7 @@ export function Button<T extends OperationResult<A, B>, A, B>({
</button>
}
-function Wait():VNode {
+function Wait(): VNode {
return <Fragment>
<style>{`
#l1 { width: 120px;