From eba140150aa6cf1e4382102650bd1caf33eaba79 Mon Sep 17 00:00:00 2001 From: JustinMacaulay Date: Wed, 29 Nov 2023 11:20:33 -0800 Subject: [PATCH 1/4] various bug fixes --- backups/print_layout copy.json | 2 +- .../middleware/event_middleware.py | 4 +-- .../src/components/CommonForm/driverInfo.js | 20 +++++++++------ .../src/components/Event/initialValues.js | 2 +- .../src/components/Event/validationSchema.js | 2 +- .../components/Forms/Print/print_layout.json | 4 +-- .../frontend_web_app/src/utils/constants.js | 18 +++++++++++++ .../frontend_web_app/src/utils/formatBCDL.js | 8 +++--- .../frontend_web_app/src/utils/helpers.js | 25 +++++++++++++------ 9 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 roadside-forms-frontend/frontend_web_app/src/utils/constants.js diff --git a/backups/print_layout copy.json b/backups/print_layout copy.json index da5fc5af4..b50d0539b 100644 --- a/backups/print_layout copy.json +++ b/backups/print_layout copy.json @@ -160,7 +160,7 @@ "ECOS_OFFICER_NAME", "ECOS_OFFICER_BADGE_NUMBER", "ECOS_AGENCY_NAME", - "ECOS_DATE_CERTIFIED", + "ECOS_DATE_CERTIFIED", "REQUESTED_PRESCRIBED_TEST_YES", "REQUESTED_PRESCRIBED_TEST_NO", "REQUESTED_PRESCRIBED_TEST_USED_ALCOHOL_INSTRUMENT", diff --git a/python/prohibition_web_svc/middleware/event_middleware.py b/python/prohibition_web_svc/middleware/event_middleware.py index 1aab09100..670ab9fc0 100644 --- a/python/prohibition_web_svc/middleware/event_middleware.py +++ b/python/prohibition_web_svc/middleware/event_middleware.py @@ -78,7 +78,7 @@ def save_event_data(**kwargs) -> tuple: 'value': None, 'label': None}).get('value'), date_of_driving=data.get('date_of_driving'), time_of_driving=data.get('time_of_driving'), - nsc_no=data.get('nsc_no'), + nsc_no=data.get('nsc_no', None), nsc_prov_state=data.get('nsc_prov_state', { 'value': None, 'label': None}).get('value'), owned_by_corp=data.get('owned_by_corp'), @@ -111,7 +111,7 @@ def save_event_data(**kwargs) -> tuple: ) if data.get('VI'): vi_form = VIForm( - gender=data.get('gender'), + gender=(lambda x: x.get('value') if x else None)(data.get('gender', None)), driver_is_regist_owner=data.get('driver_is_regist_owner'), driver_licence_expiry=datetime.strptime( data.get('driver_licence_expiry'), "%Y-%m-%dT%H:%M:%S.%f%z") if data.get('driver_licence_expiry') else None, diff --git a/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/driverInfo.js b/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/driverInfo.js index f8f5b85fd..d77aa84d5 100644 --- a/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/driverInfo.js +++ b/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/driverInfo.js @@ -1,13 +1,14 @@ import React, { useState, useEffect } from "react"; import PropTypes from "prop-types"; import _ from "lodash"; +import { useFormikContext } from "formik"; +import Modal from "react-bootstrap/Modal"; import Button from "react-bootstrap/Button"; import Row from "react-bootstrap/Row"; import Col from "react-bootstrap/Col"; -import Modal from "react-bootstrap/Modal"; import moment from "moment-timezone"; import { toast } from "react-toastify"; -import { useFormikContext } from "formik"; + import { Input } from "../common/Input/Input"; import { SearchableSelect } from "../common/Select/SearchableSelect"; import { DateOfBirthField } from "../common/DateField/dateOfBirthField"; @@ -16,6 +17,7 @@ import { PhoneField } from "../common/Input/phoneField"; import { dlScanner } from "../../utils/dlScanner"; import { ICBCDriverDataApi } from "../../api/icbcDriverDataAPI"; import { formatBCDL } from "../../utils/formatBCDL"; +import { genderDropdown } from "../../utils/constants"; import "./commonForm.scss"; export const DriverInfo = (props) => { @@ -53,7 +55,7 @@ export const DriverInfo = (props) => { const dob_month = dl_data["dob"].slice(4, 6); const dob_day = dl_data["dob"].slice(6, 8); - values["driver_licence_no"] = dl_data["number"]; + values["driver_licence_no"] = formatBCDL(dl_data["number"], values); values["driver_last_name"] = dl_data["name"]["surname"]; values["driver_given_name"] = dl_data["name"]["given"]; values["driver_dob"] = new Date(dob_year, dob_month - 1, dob_day); @@ -86,6 +88,10 @@ export const DriverInfo = (props) => { }; const fetchICBCDriverInfo = () => { + values["driver_licence_no"] = formatBCDL( + values["driver_licence_no"], + values + ); if (values["driver_licence_no"]) { ICBCDriverDataApi.get(values["driver_licence_no"]).then((resp) => { if (!_.isEmpty(resp.data) && resp.status === "success") { @@ -140,7 +146,7 @@ export const DriverInfo = (props) => { label="Driver's Licence Number" name="driver_licence_no" onBlur={(event) => { - event.target.value = formatBCDL(event, values); + event.target.value = formatBCDL(event.target.value, values); values["driver_licence_no"] = event.target.value; }} type="text" @@ -248,11 +254,11 @@ export const DriverInfo = (props) => { {values["VI"] && ( - diff --git a/roadside-forms-frontend/frontend_web_app/src/components/Event/initialValues.js b/roadside-forms-frontend/frontend_web_app/src/components/Event/initialValues.js index 699070dc7..4b89b8106 100644 --- a/roadside-forms-frontend/frontend_web_app/src/components/Event/initialValues.js +++ b/roadside-forms-frontend/frontend_web_app/src/components/Event/initialValues.js @@ -22,7 +22,7 @@ export const InitialValues = () => { driver_city: "", driver_prov_state: { value: "BC", label: "BRITISH COLUMBIA" }, driver_postal: "", - gender: "", + gender: {}, driver_licence_expiry: null, driver_licence_class: "", 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 8881d4dce..0138cf1b2 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 @@ -136,7 +136,7 @@ export const validationSchema = Yup.object().shape( driver_city: Yup.string(), driver_prov_state: Yup.object(), driver_postal: Yup.string(), - gender: Yup.string(), // Only for VI + // gender: Yup.string(), // Only for VI driver_licence_expiry: Yup.date() .nullable() .when("VI", { diff --git a/roadside-forms-frontend/frontend_web_app/src/components/Forms/Print/print_layout.json b/roadside-forms-frontend/frontend_web_app/src/components/Forms/Print/print_layout.json index dd34e1cb2..6df5b7d92 100644 --- a/roadside-forms-frontend/frontend_web_app/src/components/Forms/Print/print_layout.json +++ b/roadside-forms-frontend/frontend_web_app/src/components/Forms/Print/print_layout.json @@ -1159,8 +1159,8 @@ "field_name": "gender", "classNames": "fontSmall", "start": { - "x": 165, - "y": 30 + "x": 169.5, + "y": 29.5 } }, "DRIVER_DL_NUMBER": { diff --git a/roadside-forms-frontend/frontend_web_app/src/utils/constants.js b/roadside-forms-frontend/frontend_web_app/src/utils/constants.js new file mode 100644 index 000000000..524ddb75c --- /dev/null +++ b/roadside-forms-frontend/frontend_web_app/src/utils/constants.js @@ -0,0 +1,18 @@ +export const genderDropdown = [ + { + label: "MALE", + value: "M", + }, + { + label: "FEMALE", + value: "F", + }, + { + label: "GENDER DIVERSE", + value: "X", + }, + { + label: "UNKNOWN", + value: "U", + }, +]; diff --git a/roadside-forms-frontend/frontend_web_app/src/utils/formatBCDL.js b/roadside-forms-frontend/frontend_web_app/src/utils/formatBCDL.js index 7773e5e8f..e3a98c828 100644 --- a/roadside-forms-frontend/frontend_web_app/src/utils/formatBCDL.js +++ b/roadside-forms-frontend/frontend_web_app/src/utils/formatBCDL.js @@ -1,12 +1,12 @@ -export const formatBCDL = (event, values) => { +export const formatBCDL = (dlNumber, values) => { if ( values["TwelveHour"] || (values["drivers_licence_jurisdiction"] && values["drivers_licence_jurisdiction"].label === "BRITISH COLUMBIA") ) { - if (event.target.value.length === 7) { - return "0" + event.target.value.toUpperCase(); + if (dlNumber.length === 7) { + return "0" + dlNumber.toUpperCase(); } } - return event.target.value.toUpperCase(); + return dlNumber.toUpperCase(); }; 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 137ca1267..3521e827e 100644 --- a/roadside-forms-frontend/frontend_web_app/src/utils/helpers.js +++ b/roadside-forms-frontend/frontend_web_app/src/utils/helpers.js @@ -3,6 +3,7 @@ import moment from "moment-timezone"; import * as staticData from "../atoms/staticData"; import { pstDate } from "./dateTime"; +import { genderDropdown } from "./constants"; import twentyFourHourDriverform from "../assets/MV2634E_082023_driver.png"; import twentyFourHourILOform from "../assets/MV2634E_082023_ilo.png"; import twentyFourHourPoliceform from "../assets/MV2634E_082023_icbc.png"; @@ -127,13 +128,15 @@ export const getTwentyFourHourDataToSave = (formValues, event_id) => { return twentyFourHourFormValues; }; -export const formTypes = (data) => { - const forms = - (data["VI"] ? "VI, " : " ") + - (data["IRP"] || data["IRP_number"] ? "IRP, " : " ") + - (data["TwentyFourHour"] ? "TwentyFourHour, " : " ") + - (data["TwelveHour"] ? "TwelveHour" : " "); - return forms; +export const formTypes = (form) => { + const formTypeList = [ + ...(form["IRP"] ? ["IRP"] : []), + ...(form["VI"] ? ["VI"] : []), + ...(form["TwentyFourHour"] ? ["24H"] : []), + ...(form["TwelveHour"] ? ["12H"] : []), + ]; + + return formTypeList.join(", "); }; export const formNumbers = (data) => { @@ -535,6 +538,14 @@ export const eventDataFormatter = ( event["nsc_no"] === "" ? (event["is_nsc"] = false) : (event["is_nsc"] = true); + + const gender = genderDropdown.filter( + (x) => x["value"] === event["gender"] + )[0]; + event["gender"] = { + value: gender?.value, + label: gender?.label, + }; } const vehicleStyl = vehicleStyles.filter( From ec33a2321545e0351125226959b8a3f784cd4085 Mon Sep 17 00:00:00 2001 From: JustinMacaulay Date: Wed, 29 Nov 2023 12:47:49 -0800 Subject: [PATCH 2/4] dob fixes for icbc dl --- .../src/components/CommonForm/driverInfo.js | 6 +++++- .../src/components/Event/validationSchema.js | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/driverInfo.js b/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/driverInfo.js index d77aa84d5..35ca7a3f8 100644 --- a/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/driverInfo.js +++ b/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/driverInfo.js @@ -94,12 +94,16 @@ export const DriverInfo = (props) => { ); if (values["driver_licence_no"]) { ICBCDriverDataApi.get(values["driver_licence_no"]).then((resp) => { + console.log(resp); if (!_.isEmpty(resp.data) && resp.status === "success") { const party = resp.data.party; const address = party.addresses[0]; setFieldValue("driver_last_name", party.lastName); setFieldValue("driver_given_name", party.firstName); - setFieldValue("driver_dob", moment(party.birthDate)); + setFieldValue( + "driver_dob", + moment(party.birthDate).tz("America/Vancouver").toDate() + ); setFieldValue("driver_address", address.addressLine1); setFieldValue("driver_city", address.city); setFieldValue("driver_postal", address.postalCode); 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 0138cf1b2..a56edbd3d 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 @@ -80,10 +80,10 @@ export const validationSchema = Yup.object().shape( // Return true if the field is empty return true; } - + console.log(dob); const currentDate = moment(); - const inputDate = moment(dob).utcOffset("+07:00"); - + const inputDate = moment(dob); + console.log(currentDate, inputDate); const currentYear = currentDate.year(); const inputYear = inputDate.year(); From 858c8d80b037405e861596f86cd83fb521b36dc3 Mon Sep 17 00:00:00 2001 From: JustinMacaulay Date: Wed, 29 Nov 2023 13:28:52 -0800 Subject: [PATCH 3/4] vehicle year fix --- .../frontend_web_app/src/components/Event/createEvent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4fa03bd66..823ecd9e2 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 @@ -232,7 +232,7 @@ export const CreateEvent = () => { }; const generateYearOptions = () => { - const currentYear = new Date().getFullYear(); + const currentYear = new Date().getFullYear() + 1; const startYear = 1900; const years = []; From 33e240df3e5497a810cf6e3f992c9875d9561311 Mon Sep 17 00:00:00 2001 From: JustinMacaulay Date: Thu, 30 Nov 2023 10:20:57 -0800 Subject: [PATCH 4/4] missed console logs --- .../frontend_web_app/src/components/Event/validationSchema.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 a56edbd3d..4f68bbd1e 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 @@ -80,10 +80,10 @@ export const validationSchema = Yup.object().shape( // Return true if the field is empty return true; } - console.log(dob); + const currentDate = moment(); const inputDate = moment(dob); - console.log(currentDate, inputDate); + const currentYear = currentDate.year(); const inputYear = inputDate.year();