commit 7bfccf0739dd3b5dbba9ee1b1e6f6a91e2293e10
parent ba65f01b49fed61f919c31fefaccb803e9065afc
Author: Florian Dold <florian@dold.me>
Date: Sat, 22 Mar 2025 22:09:33 +0100
forms: implement default value for iso date input
Diffstat:
5 files changed, 128 insertions(+), 114 deletions(-)
diff --git a/packages/web-util/src/forms/fields/InputIsoDate.tsx b/packages/web-util/src/forms/fields/InputIsoDate.tsx
@@ -1,7 +1,23 @@
+/*
+ This file is part of GNU Taler
+ (C) 2025 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero 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 Affero Public License for more details.
+
+ You should have received a copy of the GNU Affero Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
import { AbsoluteTime } from "@gnu-taler/taler-util";
import { format, parse } from "date-fns";
import { Fragment, VNode, h } from "preact";
-import { useState } from "preact/hooks";
+import { useEffect, useState } from "preact/hooks";
import { Calendar } from "../Calendar.js";
import { Dialog } from "../Dialog.js";
import { UIFormProps } from "../FormProvider.js";
@@ -15,6 +31,8 @@ export interface InputIsoDateProps {
* Defaults to "dd/MM/yyyy".
*/
pattern?: string;
+
+ defaultValue?: string;
}
/**
@@ -32,8 +50,16 @@ export function InputIsoDate(
const { value, onChange } =
properties.handler ?? noHandlerPropsAndNoContextForField(properties.name);
+ useEffect(() => {
+ console.log("in useEffect");
+ console.log("pattern", properties.pattern);
+ console.log("defaultValue", properties.defaultValue);
+ if (!value && !!properties.defaultValue) {
+ onChange(properties.defaultValue);
+ }
+ });
+
const time = parse(value, pattern, Date.now()).getTime();
- // const strTime = format(time, pattern);
return (
<Fragment>
<InputLine
@@ -44,7 +70,6 @@ export function InputIsoDate(
onClick: () => {
setOpen(true);
},
- // icon: <CalendarIcon class="h-6 w-6" />,
children: (
<svg
xmlns="http://www.w3.org/2000/svg"
diff --git a/packages/web-util/src/forms/forms-types.ts b/packages/web-util/src/forms/forms-types.ts
@@ -1,3 +1,19 @@
+/*
+ This file is part of GNU Taler
+ (C) 2025 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero 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 Affero Public License for more details.
+
+ You should have received a copy of the GNU Affero Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
import {
buildCodecForObject,
buildCodecForUnion,
@@ -92,6 +108,7 @@ type UIFormFieldAbsoluteTime = {
type UIFormFieldIsoDate = {
type: "isoDateText";
+ defaultValue?: string;
max?: TalerProtocolTimestamp;
min?: TalerProtocolTimestamp;
pattern: string;
@@ -123,16 +140,19 @@ type UIFormFieldArray = {
} & UIFormFieldBaseConfig;
type UIFormElementCaption = { type: "caption" } & UIFieldElementDescription;
+
type UIFormElementDownloadLink = {
type: "download-link";
url: string;
media?: string;
} & UIFieldElementDescription;
+
type UIFormElementExternalLink = {
type: "external-link";
url: string;
media?: string;
} & UIFieldElementDescription;
+
type UIFormElementHtmlIframe = {
type: "htmlIframe";
url: string;
@@ -198,8 +218,11 @@ type UIFormFieldSelectOne = {
type: "selectOne";
choices: Array<SelectUiChoice>;
} & UIFormFieldBaseConfig;
+
type UIFormFieldText = { type: "text" } & UIFormFieldBaseConfig;
+
type UIFormFieldTextArea = { type: "textArea" } & UIFormFieldBaseConfig;
+
type UIFormFieldToggle = {
type: "toggle";
threeState?: boolean;
diff --git a/packages/web-util/src/forms/forms-utils.ts b/packages/web-util/src/forms/forms-utils.ts
@@ -37,7 +37,7 @@ export function convertFormConfigToUiField(
case "caption": {
const resp: UIFormField = {
type: config.type,
- properties: converBaseFieldsProps(i18n_, config),
+ properties: convertBaseFieldsProps(i18n_, config),
};
return resp;
}
@@ -45,7 +45,7 @@ export function convertFormConfigToUiField(
const resp: UIFormField = {
type: config.type,
properties: {
- ...converBaseFieldsProps(i18n_, config),
+ ...convertBaseFieldsProps(i18n_, config),
label: i18n_.str`${config.label}`,
url: config.url,
media: config.media,
@@ -57,7 +57,7 @@ export function convertFormConfigToUiField(
const resp: UIFormField = {
type: config.type,
properties: {
- ...converBaseFieldsProps(i18n_, config),
+ ...convertBaseFieldsProps(i18n_, config),
label: i18n_.str`${config.label}`,
url: config.url,
media: config.media,
@@ -69,7 +69,7 @@ export function convertFormConfigToUiField(
const resp: UIFormField = {
type: config.type,
properties: {
- ...converBaseFieldsProps(i18n_, config),
+ ...convertBaseFieldsProps(i18n_, config),
url: config.url,
},
};
@@ -79,7 +79,7 @@ export function convertFormConfigToUiField(
const resp: UIFormField = {
type: config.type,
properties: {
- ...converBaseFieldsProps(i18n_, config),
+ ...convertBaseFieldsProps(i18n_, config),
fields: convertFormConfigToUiField(
i18n_,
`${parentKey}.${fieldIndex}`,
@@ -108,8 +108,8 @@ export function convertFormConfigToUiField(
return {
type: "array",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -125,8 +125,8 @@ export function convertFormConfigToUiField(
return {
type: "absoluteTimeText",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -140,13 +140,15 @@ export function convertFormConfigToUiField(
return {
type: "isoDateText",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
getConverterByFieldType(config.type, config),
),
+ pattern: config.pattern,
+ defaultValue: config.defaultValue,
hidden,
},
} as UIFormField;
@@ -155,8 +157,8 @@ export function convertFormConfigToUiField(
return {
type: "amount",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -171,8 +173,8 @@ export function convertFormConfigToUiField(
return {
type: "choiceHorizontal",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -187,8 +189,8 @@ export function convertFormConfigToUiField(
return {
type: "choiceStacked",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -203,8 +205,8 @@ export function convertFormConfigToUiField(
return {
type: "file",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -220,8 +222,8 @@ export function convertFormConfigToUiField(
return {
type: "integer",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -235,8 +237,8 @@ export function convertFormConfigToUiField(
return {
type: "secret",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -250,8 +252,8 @@ export function convertFormConfigToUiField(
return {
type: "selectMultiple",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -267,8 +269,8 @@ export function convertFormConfigToUiField(
return {
type: "selectOne",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -283,8 +285,8 @@ export function convertFormConfigToUiField(
return {
type: "text",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -298,8 +300,8 @@ export function convertFormConfigToUiField(
return {
type: "textArea",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -313,8 +315,8 @@ export function convertFormConfigToUiField(
return {
type: "duration",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -328,8 +330,8 @@ export function convertFormConfigToUiField(
return {
type: "durationText",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -343,8 +345,8 @@ export function convertFormConfigToUiField(
return {
type: "toggle",
properties: {
- ...converBaseFieldsProps(i18n_, config),
- ...converInputFieldsProps(
+ ...convertBaseFieldsProps(i18n_, config),
+ ...convertInputFieldsProps(
name,
handler,
config,
@@ -386,12 +388,13 @@ function getConverterByFieldType(
* Input field take most of the properties from the
* handler, since the input value can change the
* some states like hidden or disabled.
+ *
* @param form
* @param config
* @param converter
* @returns
*/
-function converInputFieldsProps(
+function convertInputFieldsProps(
name: string,
handler: UIFieldHandler,
config: UIFormFieldBaseConfig,
@@ -411,7 +414,7 @@ function converInputFieldsProps(
};
}
-function converBaseFieldsProps(
+function convertBaseFieldsProps(
i18n_: InternationalizationAPI,
p: UIFieldElementDescription,
) {
diff --git a/packages/web-util/src/forms/gana/VQF_902_1_officer.ts b/packages/web-util/src/forms/gana/VQF_902_1_officer.ts
@@ -1,19 +1,34 @@
+/*
+ This file is part of GNU Taler
+ (C) 2025 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero 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 Affero Public License for more details.
+
+ You should have received a copy of the GNU Affero Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+import { format } from "date-fns";
import {
DoubleColumnFormDesign,
InternationalizationAPI,
} from "../../index.browser.js";
-import { languageNameList } from "../../utils/select-ui-lists.js";
import { TalerFormAttributes } from "./taler_form_attributes.js";
/**
- * VQF_902_1 filled by AML officer when the customer
- * as complete VQF 902 1 partially
- *
- * @returns
+ * Design of the vqf_902_1_officer form.
*/
export function VQF_902_1_officer(
i18n: InternationalizationAPI,
): DoubleColumnFormDesign {
+ const today = format(new Date(), "yyyy-MM-dd");
+
return {
type: "double-column",
sections: [
@@ -22,15 +37,16 @@ export function VQF_902_1_officer(
fields: [
{
id: TalerFormAttributes.ACCEPTANCE_DATE,
- label: i18n.str`Date (conclusion of contract)`,
+ label: i18n.str`Date (conclusion of contract):`,
type: "isoDateText",
placeholder: "dd/MM/yyyy",
pattern: "dd/MM/yyyy",
+ defaultValue: today,
required: true,
},
{
id: TalerFormAttributes.ACCEPTANCE_METHOD,
- label: i18n.str`Accepted by`,
+ label: i18n.str`Accepted via:`,
type: "choiceStacked",
choices: [
{
@@ -49,63 +65,28 @@ export function VQF_902_1_officer(
required: true,
},
{
- id: TalerFormAttributes.ACCEPTANCE_CORRESPONDENCE_SERVICE_TYPE,
- label: i18n.str`Type of correspondence service`,
+ id: TalerFormAttributes.CORRESPONDENCE_LANGUAGE,
+ required: true,
+ label: i18n.str`Correspondence language:`,
type: "choiceStacked",
choices: [
{
- value: "HOLD_AT_BANK",
- label: i18n.str`Hold at a bank`,
+ value: "en",
+ label: i18n.str`English`,
},
{
- value: "TO_THE_CUSTOMER",
- label: i18n.str`To the customer`,
+ value: "de",
+ label: i18n.str`German`,
},
{
- value: "TO_THE_MEMBER",
- label: i18n.str`To the member`,
- },
- {
- value: "TO_A_THIRD_PARTY",
- label: i18n.str`To a third party`,
+ value: "fr",
+ label: i18n.str`French`,
},
],
- required: true,
- },
- {
- id: TalerFormAttributes.ACCEPTANCE_CORRESPONDENCE_SERVICE_THIRD_PARTY_FULL_NAME,
- label: i18n.str`Third party full name`,
- type: "text",
- required: true,
- hide(value, root) {
- return (
- root["ACCEPTANCE_CORRESPONDENCE_SERVICE_TYPE"] !==
- "TO_A_THIRD_PARTY"
- );
- },
- },
- {
- id: TalerFormAttributes.ACCEPTANCE_CORRESPONDENCE_SERVICE_THIRD_PARTY_ADDRESS,
- label: i18n.str`Third party address`,
- type: "textArea",
- required: true,
- hide(value, root) {
- return (
- root["ACCEPTANCE_CORRESPONDENCE_SERVICE_TYPE"] !==
- "TO_A_THIRD_PARTY"
- );
- },
- },
- {
- id: TalerFormAttributes.ACCEPTANCE_LANGUAGE,
- label: i18n.str`Language`,
- type: "selectOne",
- choices: languageNameList(i18n),
- required: true,
},
{
id: TalerFormAttributes.ACCEPTANCE_FURTHER_INFO,
- label: i18n.str`Further information`,
+ label: i18n.str`Further information:`,
type: "textArea",
required: false,
},
@@ -117,7 +98,7 @@ export function VQF_902_1_officer(
fields: [
{
id: TalerFormAttributes.EMBARGO_TERRORISM_INFO,
- label: i18n.str`Embargo information`,
+ label: i18n.str`Embargo information:`,
type: "textArea",
required: false,
},
diff --git a/packages/web-util/src/forms/gana/taler_form_attributes.ts b/packages/web-util/src/forms/gana/taler_form_attributes.ts
@@ -210,27 +210,9 @@ export const TalerFormAttributes = {
/**
* Description:
*
- * GANA Type: 'TO_THE_CUSTOMER' | 'HOLD_AT_BANK' | 'TO_THE_MEMBER' | 'TO_A_THIRD_PARTY'
- */
- ACCEPTANCE_CORRESPONDENCE_SERVICE_TYPE: "ACCEPTANCE_CORRESPONDENCE_SERVICE_TYPE" as UIHandlerId,
- /**
- * Description:
- *
- * GANA Type: String
- */
- ACCEPTANCE_CORRESPONDENCE_SERVICE_THIRD_PARTY_FULL_NAME: "ACCEPTANCE_CORRESPONDENCE_SERVICE_THIRD_PARTY_FULL_NAME" as UIHandlerId,
- /**
- * Description:
- *
- * GANA Type: BusinessAddress
- */
- ACCEPTANCE_CORRESPONDENCE_SERVICE_THIRD_PARTY_ADDRESS: "ACCEPTANCE_CORRESPONDENCE_SERVICE_THIRD_PARTY_ADDRESS" as UIHandlerId,
- /**
- * Description:
- *
* GANA Type: LangCode
*/
- ACCEPTANCE_LANGUAGE: "ACCEPTANCE_LANGUAGE" as UIHandlerId,
+ CORRESPONDENCE_LANGUAGE: "CORRESPONDENCE_LANGUAGE" as UIHandlerId,
/**
* Description:
*