aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/UpdatePage.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/UpdatePage.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/UpdatePage.tsx25
1 files changed, 12 insertions, 13 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/UpdatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/UpdatePage.tsx
index bcd53ffd0..1c1d0da79 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/UpdatePage.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/UpdatePage.tsx
@@ -19,6 +19,7 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
+import { TalerMerchantApi } from "@gnu-taler/taler-util";
import { useTranslationContext } from "@gnu-taler/web-util/browser";
import { h, VNode } from "preact";
import { useState } from "preact/hooks";
@@ -28,8 +29,8 @@ import {
FormProvider,
} from "../../../../components/form/FormProvider.js";
import { Input } from "../../../../components/form/Input.js";
-import { TalerMerchantApi } from "@gnu-taler/taler-util";
import { WithId } from "../../../../declaration.js";
+import { undefinedIfEmpty } from "../../../../utils/table.js";
type Entity = TalerMerchantApi.WebhookPatchDetails & WithId;
@@ -45,23 +46,21 @@ export function UpdatePage({ webhook, onUpdate, onBack }: Props): VNode {
const [state, setState] = useState<Partial<Entity>>(webhook);
- const errors: FormErrors<Entity> = {
- event_type: !state.event_type ? i18n.str`required` : undefined,
+ const errors = undefinedIfEmpty<FormErrors<Entity>>({
+ event_type: !state.event_type ? i18n.str`Required` : undefined,
http_method: !state.http_method
- ? i18n.str`required`
+ ? i18n.str`Required`
: !validMethod.includes(state.http_method)
- ? i18n.str`should be one of '${validMethod.join(", ")}'`
- : undefined,
- url: !state.url ? i18n.str`required` : undefined,
- };
+ ? i18n.str`Must be one of '${validMethod.join(", ")}'`
+ : undefined,
+ url: !state.url ? i18n.str`Required` : undefined,
+ });
- const hasErrors = Object.keys(errors).some(
- (k) => (errors as any)[k] !== undefined,
- );
+ const hasErrors = errors !== undefined;
const submitForm = () => {
if (hasErrors) return Promise.reject();
- return onUpdate(state as any);
+ return onUpdate(state as Entity);
};
return (
@@ -130,7 +129,7 @@ export function UpdatePage({ webhook, onUpdate, onBack }: Props): VNode {
data-tooltip={
hasErrors
? i18n.str`Need to complete marked fields`
- : "confirm operation"
+ : i18n.str`Confirm operation`
}
onClick={submitForm}
>