Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation and date issue fixes #302

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -422,21 +422,24 @@ export const validationSchema = Yup.object().shape(
"vehicle_impounded",
"reason_for_not_impounding",
"vehicle_location",
"form_printed_successfully",
],
{
is: (
TwentyFourHour,
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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Loading