From 70862499e505b691ec23e5e8a623b4830f11cc9d Mon Sep 17 00:00:00 2001 From: Tore Brede <Tore.Brede@uib.no> Date: Mon, 6 Dec 2021 12:42:42 +0100 Subject: [PATCH] GREG-136: Adding today as default date --- frontend/src/routes/sponsor/register/formData.ts | 4 ++-- frontend/src/routes/sponsor/register/stepPersonForm.tsx | 3 +++ frontend/src/routes/sponsor/register/stepRegistration.tsx | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/routes/sponsor/register/formData.ts b/frontend/src/routes/sponsor/register/formData.ts index 8e96d7a6..6700f957 100644 --- a/frontend/src/routes/sponsor/register/formData.ts +++ b/frontend/src/routes/sponsor/register/formData.ts @@ -2,8 +2,8 @@ export type RegisterFormData = { first_name?: string last_name?: string role_type?: string - role_start?: Date - role_end?: Date + role_start: Date + role_end: Date contact_person_unit?: string comment?: string ou_id?: number diff --git a/frontend/src/routes/sponsor/register/stepPersonForm.tsx b/frontend/src/routes/sponsor/register/stepPersonForm.tsx index c4427e9d..e796fa33 100644 --- a/frontend/src/routes/sponsor/register/stepPersonForm.tsx +++ b/frontend/src/routes/sponsor/register/stepPersonForm.tsx @@ -46,6 +46,7 @@ const StepPersonForm = forwardRef( ) const roleTypes = useRoleTypes() const { displayContactAtUnit, displayComment } = useContext(FeatureContext) + const today: Date = new Date() const roleTypeSort = () => (a: RoleTypeData, b: RoleTypeData) => { if (i18n.language === 'en') { @@ -204,6 +205,7 @@ const StepPersonForm = forwardRef( name="role_start" control={control} rules={{ validate: validateStartDateBeforeEndDate }} + defaultValue={today} render={({ field }) => ( <DatePicker mask="____-__-__" @@ -225,6 +227,7 @@ const StepPersonForm = forwardRef( <Controller name="role_end" control={control} + defaultValue={today} render={({ field }) => ( <DatePicker mask="____-__-__" diff --git a/frontend/src/routes/sponsor/register/stepRegistration.tsx b/frontend/src/routes/sponsor/register/stepRegistration.tsx index 3d274b46..e7592ede 100644 --- a/frontend/src/routes/sponsor/register/stepRegistration.tsx +++ b/frontend/src/routes/sponsor/register/stepRegistration.tsx @@ -33,8 +33,9 @@ export default function StepRegistration() { first_name: undefined, last_name: undefined, role_type: undefined, - role_start: undefined, - role_end: undefined, + // Having role_start and role_end to be nullable caused problems when specifying a default value, so instead having them as non-null and use today as the default date here + role_start: new Date(), + role_end: new Date(), comment: undefined, ou_id: undefined, email: undefined, -- GitLab