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

Federal waste codes required if epaWaste is true #584

Merged
merged 2 commits into from
Aug 31, 2023
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
@@ -1,12 +1,13 @@
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 { Code, HazardousWaste, WasteLine } 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 { ErrorMessage } from '@hookform/error-message';

interface HazardousWasteFormProps {
epaWaste: boolean;
Expand All @@ -18,7 +19,10 @@ interface HazardousWasteFormProps {
* @constructor
*/
export function HazardousWasteForm({ epaWaste }: HazardousWasteFormProps) {
const { control } = useFormContext();
const {
control,
formState: { errors },
} = useFormContext<WasteLine>();
const { generatorStateCode, tsdfStateCode } = useContext<ManifestContextType>(ManifestContext);
// Retrieve federal waste codes from the server
const {
Expand Down Expand Up @@ -78,6 +82,7 @@ export function HazardousWasteForm({ epaWaste }: HazardousWasteFormProps) {
options={federalWasteCodes}
isLoading={federalLoading}
getOptionLabel={(option) =>
// @ts-ignore
`${option.code}: ${option.description.toLowerCase()}`
}
getOptionValue={(option) => option.code}
Expand All @@ -87,10 +92,21 @@ export function HazardousWasteForm({ epaWaste }: HazardousWasteFormProps) {
isMulti
isClearable
hideSelectedOptions
classNames={{
control: () =>
`form-control p-0 rounded-2 ${
errors.hazardousWaste?.federalWasteCodes && 'border-danger'
} `,
}}
/>
);
}}
></Controller>
/>
<ErrorMessage
errors={errors}
name={'hazardousWaste.federalWasteCodes'}
render={({ message }) => <span className="text-danger">{message}</span>}
/>
{federalError ? (
<i className="text-danger">
We experienced an error retrieving the federal waste codes
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/Manifest/WasteLine/WasteLineForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export function WasteLineForm({
* @param wasteLine the data submitted from the form
*/
const onSubmit = (wasteLine: WasteLine) => {
console.log('epaWaste', wasteLine.epaWaste);
console.log('waste codes', wasteLine.hazardousWaste?.federalWasteCodes);
if (waste) {
wasteArrayMethods.update(lineNumber, wasteLine); // append the new waste line to the manifest
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface WasteRowActionProps {
}

/**
* WasteRowActions - actions for controlling waste lines on a manifest
* WasteRowActions - actions for controlling wast lines on a manifest
* @constructor
*/
function WasteRowActions({
Expand Down
36 changes: 15 additions & 21 deletions client/src/components/Manifest/WasteLine/wasteLineSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const hazardousWasteSchema = z.object({
generatorStateWasteCodes: z.array(codeSchema).optional(),
});

export type HazardousWaste = z.infer<typeof hazardousWasteSchema>;

const dotInformationSchema = z.object({
idNumber: codeSchema,
printedDotInformation: z.string(),
Expand Down Expand Up @@ -100,6 +102,16 @@ export const wasteLineSchema = z
message: 'DOT ID number is required',
}
)
.refine(
(wasteLine) => {
// If stream is federally hazardous waste, a federal waste code is required
return wasteLine.epaWaste && wasteLine.hazardousWaste?.federalWasteCodes;
},
{
path: ['hazardousWaste.federalWasteCodes'],
message: 'Federal waste code is required if the waste is EPA Waste',
}
)
.refine(
(wasteLine) => {
// If material is DOT hazardous, then dotInformation.idNumber.code is required
Expand All @@ -111,26 +123,8 @@ export const wasteLineSchema = z
}
);

/**
* WasteLine is the interface for the waste line object in the manifest
*/
export type WasteLine = z.infer<typeof wasteLineSchema>;

// /**
// * Represents waste information captures on EPA's hazardous waste manifest
// */
// interface WasteLine {
// dotHazardous: boolean;
// epaWaste: boolean;
// pcb: boolean;
// lineNumber: number;
// dotInformation?: DotInformation;
// wasteDescription?: string;
// quantity?: Quantity;
// brInfo?: BrInfo;
// br: boolean;
// hazardousWaste?: HazardousWaste;
// pcbInfos?: PcbInfo[];
// discrepancyResidueInfo?: DiscrepancyResidueInfo;
// managementMethod?: Code;
// additionalInfo?: AdditionalInfo;
// }

export type { ContainerDescription };
Loading