diff --git a/roadside-forms-frontend/frontend_web_app/src/components/Event/createEvent.js b/roadside-forms-frontend/frontend_web_app/src/components/Event/createEvent.js index be89bb6e..bde3327b 100644 --- a/roadside-forms-frontend/frontend_web_app/src/components/Event/createEvent.js +++ b/roadside-forms-frontend/frontend_web_app/src/components/Event/createEvent.js @@ -499,6 +499,7 @@ export const CreateEvent = () => { const handlePrintForms = async (values) => { await handleModalClose(); if (!incompleteEventID) { + values["form_printed_successfully"] = true; try { await db.incompleteEvent .put({ diff --git a/roadside-forms-frontend/frontend_web_app/src/components/Event/validationSchema.js b/roadside-forms-frontend/frontend_web_app/src/components/Event/validationSchema.js index 72cfa014..558396d3 100644 --- a/roadside-forms-frontend/frontend_web_app/src/components/Event/validationSchema.js +++ b/roadside-forms-frontend/frontend_web_app/src/components/Event/validationSchema.js @@ -341,8 +341,8 @@ export const validationSchema = Yup.object().shape( date_of_impound: Yup.date() .nullable() .max(new Date(), "Date of impound cannot be a future date") - .when("VI", { - is: true, + .when(["VI", "form_printed_successfully"], { + is: (VI, form_printed_successfully) => VI && !form_printed_successfully, then: () => Yup.date() .max(new Date(), "Date of impound cannot be a future date") @@ -422,6 +422,7 @@ export const validationSchema = Yup.object().shape( "vehicle_impounded", "reason_for_not_impounding", "vehicle_location", + "form_printed_successfully", ], { is: ( @@ -429,14 +430,16 @@ export const validationSchema = Yup.object().shape( TwelveHour, vehicle_impounded, reason_for_not_impounding, - vehicle_location + vehicle_location, + form_printed_successfully ) => - (TwentyFourHour && + ((TwentyFourHour && vehicle_impounded === "NO" && reason_for_not_impounding === "released") || - (TwelveHour && - (vehicle_location === "released" || - vehicle_location === "private")), + (TwelveHour && + (vehicle_location === "released" || + vehicle_location === "private"))) && + !form_printed_successfully, then: () => Yup.date() .nullable() @@ -1301,6 +1304,40 @@ export const validationSchema = Yup.object().shape( /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/, "Time of requested test must match 24h format HH:MM" ), + // .test( + // "time_of_requested_test valdation", + // "Time of Requested test must be after time of driving.", + // function (time_of_requested_test) { + // if (time_of_requested_test && this.parent.time_of_driving) { + // const test_date = moment(this.parent.date_of_driving) + // .set("hour", time_of_requested_test.slice(0, 2)) + // .set("minute", time_of_requested_test.slice(3)); + // const driving_date = moment(this.parent.date_of_driving) + // .set("hour", this.parent.time_of_driving.slice(0, 2)) + // .set("minute", this.parent.time_of_driving.slice(3)); + + // return test_date > driving_date; + // } + // return true; + // } + // ) + // .test( + // "time_of_requested_test valdation", + // "Time of Requested test cannot be in the future.", + // function (time_of_requested_test) { + // if (time_of_requested_test && this.parent.time_of_driving) { + // const test_date = moment(this.parent.date_of_driving) + // .set("hour", time_of_requested_test.slice(0, 2)) + // .set("minute", time_of_requested_test.slice(3)); + // const driving_date = moment(this.parent.date_of_driving) + // .set("hour", this.parent.time_of_driving.slice(0, 2)) + // .set("minute", this.parent.time_of_driving.slice(3)); + + // return test_date > driving_date; + // } + // return true; + // } + // ), } ), requested_ASD_expiry_date: Yup.date() diff --git a/roadside-forms-frontend/frontend_web_app/src/utils/helpers.js b/roadside-forms-frontend/frontend_web_app/src/utils/helpers.js index 77424995..c8b12b61 100644 --- a/roadside-forms-frontend/frontend_web_app/src/utils/helpers.js +++ b/roadside-forms-frontend/frontend_web_app/src/utils/helpers.js @@ -526,6 +526,7 @@ export const eventDataFormatter = ( "created_dt", "updated_dt", "date_released", + "requested_ASD_expiry_date", ]; for (const item in data) { const event = data[item];