From dc7c88d19222b8876a6e4a7afd24cdea8f8e050f Mon Sep 17 00:00:00 2001 From: David Paul Graham <43794491+dpgraham4401@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:18:51 -0400 Subject: [PATCH] WasteLine form conditionals (#582) * adjust rollup chunkSize WarningLimit to 1000 kb * convert dotHazardous field to controlled input * convert epaWaste to controlled field We need to be able to read the state of the field 'epaWaste' in order to conditionally display/disable other fields. * add zod validation schemas for dotInformation field and add as nested field in WasteLine while the dotInformation is optional if the shipement is not dotHazardous, we've also added a refine method to the wasteline schema so if dotHazardous is true, both fields in dotInformation is required * add static dotIdNumbers array temporaryily * add error message when DOT ID number is not provided * simplify wasteline zod refinements, remove old unused wasteline interfaces * add wasteDescription validation * add refinement that waste description is required if the waste is not DOT hazardous material * update logic for dotHazardous and epaWaste switches here's our logic, if dotHazardous then epaWaste can be true or false. However, if epaWaste is True then dotHazardous must be true * add callback function to toggle epaWaste and dotHazardous with unit test epaWaste and dotHazardous field depend on each other if epaWaste is true, then dotHazardous must be true. Converse, if dotHazardous is false, epaWaste must be false * add integration test showing that when epaWaste is false, federal waste code select is disabled * when epaWaste is set to false, all federal waste codes are removed from the wasteline --- .../HazardousWasteForm/HazardousWasteForm.tsx | 14 +- .../StateWasteCodeSelect.tsx | 6 +- .../Manifest/WasteLine/WasteLineForm.spec.tsx | 109 + .../Manifest/WasteLine/WasteLineForm.tsx | 159 +- .../components/Manifest/WasteLine/dotInfo.ts | 2368 +++++++++++++++++ .../Manifest/WasteLine/wasteLineSchema.ts | 174 +- client/vite.config.ts | 5 +- 7 files changed, 2684 insertions(+), 151 deletions(-) create mode 100644 client/src/components/Manifest/WasteLine/WasteLineForm.spec.tsx create mode 100644 client/src/components/Manifest/WasteLine/dotInfo.ts diff --git a/client/src/components/Manifest/WasteLine/HazardousWasteForm/HazardousWasteForm.tsx b/client/src/components/Manifest/WasteLine/HazardousWasteForm/HazardousWasteForm.tsx index 608405b39..2ea5de7ba 100644 --- a/client/src/components/Manifest/WasteLine/HazardousWasteForm/HazardousWasteForm.tsx +++ b/client/src/components/Manifest/WasteLine/HazardousWasteForm/HazardousWasteForm.tsx @@ -1,19 +1,23 @@ import { HtForm } from 'components/Ht'; +import { ManifestContext, ManifestContextType } from 'components/Manifest/ManifestForm'; +import { StateWasteCodeSelect } from 'components/Manifest/WasteLine/HazardousWasteForm/StateWasteCodeSelect'; +import { Code } from 'components/Manifest/WasteLine/wasteLineSchema'; import React, { useContext } from 'react'; import { Col, Row } from 'react-bootstrap'; import { Controller, useFormContext } from 'react-hook-form'; import Select, { components, GroupBase, MultiValueProps, StylesConfig } from 'react-select'; import { useGetFedWasteCodesQuery } from 'store/wasteCode.slice'; -import { Code } from 'components/Manifest/WasteLine/wasteLineSchema'; -import { ManifestContext, ManifestContextType } from 'components/Manifest/ManifestForm'; -import { StateWasteCodeSelect } from 'components/Manifest/WasteLine/HazardousWasteForm/StateWasteCodeSelect'; + +interface HazardousWasteFormProps { + epaWaste: boolean; +} /** * Returns a form for adding waste code(s), to a wasteline, for a given manifest. * It expects to be within the context of a manifest form. * @constructor */ -export function HazardousWasteForm() { +export function HazardousWasteForm({ epaWaste }: HazardousWasteFormProps) { const { control } = useFormContext(); const { generatorStateCode, tsdfStateCode } = useContext(ManifestContext); // Retrieve federal waste codes from the server @@ -69,6 +73,8 @@ export function HazardousWasteForm() {