Skip to content

Commit

Permalink
Assorted bug fixes (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinMacaulay authored Nov 30, 2023
1 parent 94f73a1 commit 4585ae1
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 28 deletions.
2 changes: 1 addition & 1 deletion backups/print_layout copy.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions python/prohibition_web_svc/middleware/event_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -86,14 +88,22 @@ 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) => {
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);
Expand Down Expand Up @@ -140,7 +150,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"
Expand Down Expand Up @@ -248,11 +258,11 @@ export const DriverInfo = (props) => {
{values["VI"] && (
<Row style={{ minHeight: "85px" }}>
<Col sm={4}>
<Input
<SearchableSelect
className="field-height field-width"
label="Gender"
name="gender"
className="field-height field-width"
type="text"
options={genderDropdown}
/>
</Col>
<Col sm={4}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const validationSchema = Yup.object().shape(
}

const currentDate = moment();
const inputDate = moment(dob).utcOffset("+07:00");
const inputDate = moment(dob);

const currentYear = currentDate.year();
const inputYear = inputDate.year();
Expand Down Expand Up @@ -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", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,8 @@
"field_name": "gender",
"classNames": "fontSmall",
"start": {
"x": 165,
"y": 30
"x": 169.5,
"y": 29.5
}
},
"DRIVER_DL_NUMBER": {
Expand Down
18 changes: 18 additions & 0 deletions roadside-forms-frontend/frontend_web_app/src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const genderDropdown = [
{
label: "MALE",
value: "M",
},
{
label: "FEMALE",
value: "F",
},
{
label: "GENDER DIVERSE",
value: "X",
},
{
label: "UNKNOWN",
value: "U",
},
];
Original file line number Diff line number Diff line change
@@ -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();
};
25 changes: 18 additions & 7 deletions roadside-forms-frontend/frontend_web_app/src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4585ae1

Please sign in to comment.