Skip to content

Commit

Permalink
move quicker sign buttons to SignBtn folder
Browse files Browse the repository at this point in the history
add manifest service module for business logic related to the uniform hazardous waste manifest
move api related web service modules to a subdirectory called APIs
  • Loading branch information
dpgraham4401 committed Nov 29, 2023
1 parent ac73212 commit 2fe6776
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 125 deletions.
23 changes: 8 additions & 15 deletions client/src/components/Manifest/ManifestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { Alert, Button, Col, Form, Row } from 'react-bootstrap';
import { FormProvider, SubmitHandler, useFieldArray, useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
import { toast } from 'react-toastify';
import { manifestApi } from 'services/manifestApi';
import { manifest, manifestApi } from 'services';
import { ContactForm, PhoneForm } from './Contact';
import { AddHandler, GeneratorForm, Handler } from './Handler';
import { Manifest, manifestSchema, ManifestStatus } from './manifestSchema';
import { QuickerSignData, QuickerSignModal, QuickerSignModalBtn } from './QuickerSign';
import { HandlerSignBtn, QuickerSignData, QuickerSignModal } from './QuickerSign';
import { Transporter, TransporterTable } from './Transporter';
import { EditWasteModal, WasteLineTable } from './WasteLine';

Expand All @@ -34,6 +34,7 @@ export interface ManifestContextType {
setTsdfStateCode: React.Dispatch<React.SetStateAction<string | undefined>>;
editWasteLineIndex?: number;
setEditWasteLineIndex: React.Dispatch<React.SetStateAction<number | undefined>>;
signingSite?: string | undefined;
}

interface ManifestFormProps {
Expand All @@ -51,6 +52,7 @@ export const ManifestContext = createContext<ManifestContextType>({
setTsdfStateCode: () => {},
editWasteLineIndex: undefined,
setEditWasteLineIndex: () => {},
signingSite: undefined,
});

/**
Expand Down Expand Up @@ -138,7 +140,7 @@ export function ManifestForm({
const [showSignForm, setShowSignForm] = useState<boolean>(false);
const [quickerSignHandler, setQuickerSignHandler] = useState<QuickerSignData>({
handler: undefined,
siteType: 'Generator', // ToDo initialize to undefined
siteType: 'Generator',
});
const toggleQuickerSignShow = () => setShowSignForm(!showSignForm);
const setupSign = (signContext: QuickerSignData) => {
Expand Down Expand Up @@ -178,6 +180,7 @@ export function ManifestForm({
setTsdfStateCode: setTsdfStateCode,
editWasteLineIndex: editWasteLine,
setEditWasteLineIndex: setEditWasteLine,
signingSite: manifest.getNextSigner(manifestData),
}}
>
<FormProvider {...manifestForm}>
Expand Down Expand Up @@ -389,7 +392,7 @@ export function ManifestForm({
<ContactForm handlerType="generator" readOnly={readOnly} />
<div className="d-flex justify-content-between">
<Col className="text-end">
<QuickerSignModalBtn
<HandlerSignBtn
siteType={'Generator'}
mtnHandler={generator}
handleClick={setupSign}
Expand All @@ -399,8 +402,6 @@ export function ManifestForm({
</div>
</>
) : generator && !showGeneratorForm ? (
// If the form holds a value for generator, but they don't need to edit the
// generators values (allowed) then display the site details in a nice read only way
<>
<RcraSiteDetails handler={generator} />
<PhoneForm handlerType={'generator'} />
Expand All @@ -409,16 +410,12 @@ export function ManifestForm({
</div>
</>
) : showGeneratorForm ? (
// Show the Handler form with current value for the generator
// The HandlerForm allows for fine-grained control over the handler inputs
<>
<GeneratorForm readOnly={readOnly} />
<h4>Emergency Contact Information</h4>
<ContactForm handlerType="generator" readOnly={readOnly} />
</>
) : (
// default on a blank manifest, ask if they'd like to search for a generator to
// add, or if the user would like to manually enter the generator's info.
<>
<Row className="mb-2">
<HtButton
Expand Down Expand Up @@ -453,7 +450,6 @@ export function ManifestForm({
<HtCard id="transporter-form-card">
<HtCard.Header title="Transporters" />
<HtCard.Body className="pb-4">
{/* List transporters */}
<TransporterTable
transporters={transporters}
arrayFieldMethods={transporterForm}
Expand Down Expand Up @@ -483,7 +479,6 @@ export function ManifestForm({
<HtCard id="waste-form-card">
<HtCard.Header title="Waste" />
<HtCard.Body className="pb-4">
{/* Table Showing current Waste Lines included on the manifest */}
<WasteLineTable
wastes={allWastes}
toggleWLModal={toggleWlFormShow}
Expand All @@ -506,7 +501,6 @@ export function ManifestForm({
/>
</HtCard.Body>
</HtCard>
{/* Where The Tsdf information is added and displayed */}
<HtCard id="tsdf-form-card">
<HtCard.Header title="Designated Facility" />
<HtCard.Body className="pb-4">
Expand All @@ -517,7 +511,7 @@ export function ManifestForm({
<div className="d-flex justify-content-between">
{/* Button to bring up the Quicker Sign modal*/}
<Col className="text-end">
<QuickerSignModalBtn
<HandlerSignBtn
siteType={'Tsdf'}
mtnHandler={tsdf}
handleClick={setupSign}
Expand Down Expand Up @@ -549,7 +543,6 @@ export function ManifestForm({
</HtCard.Body>
</HtCard>
<HtCard id="manifest-additional-info-card">
{/* Additional information for the manifest, such as reference information*/}
<HtCard.Header title={'Additional info'} />
<HtCard.Body className="px-3">
<AdditionalInfoForm readOnly={readOnly} />
Expand Down
25 changes: 23 additions & 2 deletions client/src/components/Manifest/QuickerSign/QuickerSignForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,37 @@ import { faFileSignature } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { AxiosError } from 'axios';
import { Handler, RcraSiteType } from 'components/Manifest/manifestSchema';
import { QuickerSignature } from 'components/Manifest/QuickerSign/quickerSignSchema';
import { Transporter } from 'components/Manifest/Transporter';
import { HtForm } from 'components/UI';
import React from 'react';
import { Button, Col, Container, Form, ListGroup, Row } from 'react-bootstrap';
import { SubmitHandler, useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
import { toast } from 'react-toastify';
import { manifestApi } from 'services/manifestApi';
import { manifestApi } from 'services';
import { selectUserName, useAppSelector } from 'store';
import { z } from 'zod';

const siteType = z.enum(['Transporter', 'Generator', 'Tsdf', 'Broker']);
/**
* The EPA Quicker Sign schema
*/
const quickerSignatureSchema = z.object({
siteId: z.string(),
siteType: siteType,
transporterOrder: z.number().optional(),
printedSignatureName: z.string(),
printedSignatureDate: z.string(),
manifestTrackingNumbers: z.string().array(),
});

const quickerSignDataSchema = z.object({
handler: z.any(),
siteType: z.enum(['Generator', 'Transporter', 'Tsdf']),
});

export type QuickerSignData = z.infer<typeof quickerSignDataSchema>;
export type QuickerSignature = z.infer<typeof quickerSignatureSchema>;

interface QuickerSignProps {
mtn: Array<string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '@testing-library/jest-dom';
import { QuickerSignModalBtn } from 'components/Manifest/QuickerSign/index';
import { HandlerSignBtn } from 'components/Manifest/QuickerSign/index';
import React from 'react';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { createMockMTNHandler } from 'test-utils/fixtures';
Expand All @@ -13,11 +13,7 @@ describe('QuickerSignModalBtn', () => {
test('renders', () => {
const handler = createMockMTNHandler();
renderWithProviders(
<QuickerSignModalBtn
siteType={'Generator'}
mtnHandler={handler}
handleClick={() => undefined}
/>
<HandlerSignBtn siteType={'Generator'} mtnHandler={handler} handleClick={() => undefined} />
);
expect(screen.getByRole('button')).toBeInTheDocument();
});
Expand All @@ -26,7 +22,7 @@ describe('QuickerSignModalBtn', () => {
signed: true,
});
renderWithProviders(
<QuickerSignModalBtn
<HandlerSignBtn
siteType={'Generator'}
mtnHandler={signed_handler}
handleClick={() => undefined}
Expand All @@ -41,7 +37,7 @@ describe('QuickerSignModalBtn', () => {
electronicSignaturesInfo: undefined,
});
renderWithProviders(
<QuickerSignModalBtn
<HandlerSignBtn
siteType={'Generator'}
mtnHandler={unsigned_handler}
handleClick={() => undefined}
Expand Down Expand Up @@ -73,7 +69,7 @@ describe('QuickerSignModalBtn', () => {
signed: true,
});
renderWithProviders(
<QuickerSignModalBtn
<HandlerSignBtn
siteType={'Generator'}
mtnHandler={unsigned_handler}
handleClick={() => undefined}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { faFeather } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { ManifestContext } from 'components/Manifest/ManifestForm';
import { Handler, RcraSiteType } from 'components/Manifest/manifestSchema';
import { RcraApiUserBtn } from 'components/Rcrainfo';
import React from 'react';
import React, { useContext } from 'react';
import { ButtonProps } from 'react-bootstrap';
import { siteByEpaIdSelector, useAppSelector } from 'store';

Expand All @@ -23,24 +24,26 @@ interface QuickerSignModalBtnProps extends ButtonProps {
* The button will be disabled if siteId (the EPA ID number) is not provided
* @constructor
*/
export function QuickerSignModalBtn({
export function HandlerSignBtn({
siteType,
mtnHandler,
handleClick,
disabled,
iconOnly = false,
}: QuickerSignModalBtnProps) {
if (!useAppSelector(siteByEpaIdSelector(mtnHandler?.epaSiteId))) {
return <></>;
}
const { signingSite } = useContext(ManifestContext);
if (!useAppSelector(siteByEpaIdSelector(mtnHandler?.epaSiteId))) return <></>;

if (mtnHandler?.epaSiteId !== signingSite) return <></>;

return (
<RcraApiUserBtn
onClick={() => {
handleClick({ handler: mtnHandler, siteType: siteType });
}}
disabled={disabled}
>
{iconOnly ? '' : 'Quicker Sign '}
{iconOnly ? '' : 'Sign '}
<FontAwesomeIcon icon={faFeather} />
</RcraApiUserBtn>
);
Expand Down
7 changes: 3 additions & 4 deletions client/src/components/Manifest/QuickerSign/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { QuickerSignForm } from './QuickerSignForm';
import { HandlerSignBtn } from 'components/Manifest/QuickerSign/SignBtn/HandlerSignBtn';
import { QuickerSignature, QuickerSignData, QuickerSignForm } from './QuickerSignForm';
import { QuickerSignModal } from './QuickerSignModal';
import { QuickerSignModalBtn } from './QuickerSignModalBtn';
import { QuickerSignature, QuickerSignData } from './quickerSignSchema';

export { QuickerSignForm, QuickerSignModal, QuickerSignModalBtn };
export { QuickerSignForm, QuickerSignModal, HandlerSignBtn };
export type { QuickerSignature, QuickerSignData };
22 changes: 0 additions & 22 deletions client/src/components/Manifest/QuickerSign/quickerSignSchema.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { faAngleRight, faCheck, faSignature } from '@fortawesome/free-solid-svg-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Transporter } from 'components/Manifest';
import { Manifest } from 'components/Manifest/manifestSchema';
import { QuickerSignData, QuickerSignModalBtn } from 'components/Manifest/QuickerSign';
import { HandlerSignBtn, QuickerSignData } from 'components/Manifest/QuickerSign';
import React, { useState } from 'react';
import { Accordion, Button, Card, Col, Row, Table, useAccordionButton } from 'react-bootstrap';
import { UseFieldArrayReturn } from 'react-hook-form';
Expand Down Expand Up @@ -67,7 +67,7 @@ function TransporterTable({
</Col>
<Col xs={1}>
{readOnly ? (
<QuickerSignModalBtn
<HandlerSignBtn
siteType={'Transporter'}
mtnHandler={transporter}
handleClick={setupSign}
Expand Down
Loading

0 comments on commit 2fe6776

Please sign in to comment.