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

Remote Signer - quick sign button #648

Merged
merged 4 commits into from
Nov 29, 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
759 changes: 376 additions & 383 deletions client/src/components/Manifest/ManifestForm.tsx

Large diffs are not rendered by default.

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import '@testing-library/jest-dom';
import { ManifestContext } from 'components/Manifest/ManifestForm';
import { Handler, RcraSiteType } from 'components/Manifest/manifestSchema';
import { QuickSignBtn } from 'components/Manifest/QuickerSign/index';
import React from 'react';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { createMockMTNHandler } from 'test-utils/fixtures';
import { afterEach, describe, expect, test } from 'vitest';
import { undefined } from 'zod';

afterEach(() => {
cleanup();
});

function TestComponent({
siteType,
handler,
signingSite,
status = 'NotAssigned',
}: {
siteType?: RcraSiteType;
handler?: Handler;
signingSite?: string;
status?: 'NotAssigned' | 'Pending' | 'Scheduled' | 'InTransit' | 'ReadyForSignature';
}) {
if (!siteType) siteType = 'Generator';

return (
<div>
{/*@ts-ignore*/}
<ManifestContext.Provider value={{ manifestStatus: status, signingSite }}>
<QuickSignBtn siteType={siteType} mtnHandler={handler} handleClick={() => undefined} />
</ManifestContext.Provider>
,
</div>
);
}

describe('QuickSignBtn', () => {
test('renders', () => {
const handlerId = 'TXD987654321';
const handler = createMockMTNHandler({ siteType: 'Generator', epaSiteId: handlerId });
renderWithProviders(
<TestComponent handler={handler} signingSite={handlerId} status={'Scheduled'} />,
{
preloadedState: {
profile: {
user: 'testuser1',
org: {
rcrainfoIntegrated: true,
id: '123',
name: 'Test Org',
},
sites: {
TXD987654321: {
name: 'Test Site',
handler: handler,
permissions: { eManifest: 'signer' },
},
},
},
},
}
);
expect(screen.getByRole('button')).toBeInTheDocument();
});
test('is not disabled when user org is rcrainfo integrated', () => {
const unsigned_handler = createMockMTNHandler({
signed: false,
electronicSignaturesInfo: [],
});
renderWithProviders(<TestComponent siteType={'Generator'} handler={unsigned_handler} />, {
// Redux store state with an API user is required for this button to be active
preloadedState: {
profile: {
org: {
name: 'Test Org',
id: '123',
rcrainfoIntegrated: true,
},
user: 'username',
rcrainfoProfile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: true,
},
},
},
});
expect(screen.queryByRole('button')).not.toBeInTheDocument();
});
test('is disabled when API user but already signed', () => {
const epaSiteId = 'TXD987654321';
const unsigned_handler = createMockMTNHandler({
signed: true,
siteType: 'Generator',
epaSiteId,
});
renderWithProviders(
<TestComponent siteType={'Tsdf'} signingSite={'other_id'} handler={unsigned_handler} />,
{
// Redux store state with an API user is required for this button to be active
preloadedState: {
profile: {
user: 'username',
rcrainfoProfile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: false,
},
},
},
}
);
expect(screen.queryByRole('button')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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';

interface QuickerSignData {
handler: Handler | undefined;
Expand All @@ -22,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 QuickSignBtn({
siteType,
mtnHandler,
handleClick,
disabled,
iconOnly = false,
}: QuickerSignModalBtnProps) {
if (mtnHandler === undefined) {
return null;
}
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 { QuickSignBtn } from 'components/Manifest/QuickerSign/SignBtn/QuickSignBtn';
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, QuickSignBtn };
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 { QuickerSignData, QuickSignBtn } 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
<QuickSignBtn
siteType={'Transporter'}
mtnHandler={transporter}
handleClick={setupSign}
Expand Down
Loading