From ec57d0379195b836a8f33c3dd4c36d4b88c0e226 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 14 Jan 2023 13:44:03 +0100 Subject: [PATCH] refactor(web/input): set date to current if default is set to true --- web/src/features/dialog/InputDialog.tsx | 7 +++++-- web/src/features/dialog/components/fields/date.tsx | 2 +- web/src/interfaces/dialog.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/web/src/features/dialog/InputDialog.tsx b/web/src/features/dialog/InputDialog.tsx index 954e0b5..72ce1bd 100644 --- a/web/src/features/dialog/InputDialog.tsx +++ b/web/src/features/dialog/InputDialog.tsx @@ -59,8 +59,11 @@ const InputDialog: React.FC = () => { { value: row.type !== 'checkbox' - ? row.type === 'date' && row.default - ? new Date(row.default) + ? row.type === 'date' + ? // Set date to current one if default is set to true + row.default === true + ? new Date() + : row.default && new Date(row.default) : row.default : row.checked, } || { value: null } diff --git a/web/src/features/dialog/components/fields/date.tsx b/web/src/features/dialog/components/fields/date.tsx index 62ba06c..968f10a 100644 --- a/web/src/features/dialog/components/fields/date.tsx +++ b/web/src/features/dialog/components/fields/date.tsx @@ -13,7 +13,7 @@ const DateField: React.FC = (props) => { const controller = useController({ name: `test.${props.index}.value`, control: props.control, - defaultValue: props.row.default && new Date(props.row.default), + defaultValue: props.row.default === true ? new Date() : props.row.default ? new Date(props.row.default) : undefined, rules: { required: props.row.required }, }); diff --git a/web/src/interfaces/dialog.ts b/web/src/interfaces/dialog.ts index ba9d973..e1f696e 100644 --- a/web/src/interfaces/dialog.ts +++ b/web/src/interfaces/dialog.ts @@ -71,7 +71,7 @@ export interface IColorInput { export interface IDateInput { type: 'date'; label: string; - default?: string; + default?: string | true; disabled?: boolean; description?: string; required?: boolean;