Skip to content

Commit

Permalink
add uuid in transporter section and transporter schema
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham4401 committed May 30, 2024
1 parent 2a27b02 commit eff012b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import { useReadOnly } from 'hooks/manifest';
import { useHandlerSearchConfig } from 'hooks/manifest/useOpenHandlerSearch/useHandlerSearchConfig';
import { Alert } from 'react-bootstrap';
import { useFieldArray, useFormContext } from 'react-hook-form';
import { v4 as uuidv4 } from 'uuid';

interface TransporterSectionProps {
setupSign: () => void;
}

interface TransporterWithKey extends Transporter {
key: string;
}

export function TransporterSection({ setupSign }: TransporterSectionProps) {
const [, setSearchConfigs] = useHandlerSearchConfig();
const [readOnly] = useReadOnly();
Expand All @@ -20,7 +25,14 @@ export function TransporterSection({ setupSign }: TransporterSectionProps) {
control: manifestForm.control,
name: 'transporters',
});
const transporters: Array<Transporter> = manifestForm.getValues('transporters');
const transporters = transporterForm.fields;

transporters.forEach((transporter, index) => {
if (!transporter.clientKey) {
// @ts-ignore
manifestForm.setValue(`transporters[${index}].clientKey`, uuidv4());
}
});

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useReadOnly } from 'hooks/manifest';
import React, { useState } from 'react';
import { Accordion, Button, Card, Col, Row, Table, useAccordionButton } from 'react-bootstrap';
import { UseFieldArrayReturn } from 'react-hook-form';
import { v4 as uuidv4 } from 'uuid';
import { TransporterRowActions } from './TransporterRowActions';

interface TransporterTableProps {
Expand Down Expand Up @@ -52,7 +53,7 @@ function TransporterTable({ transporters, arrayFieldMethods, setupSign }: Transp
<>
<Accordion ref={parent}>
{transporters.map((transporter, index) => {
const transporterKey: string = `${transporter.epaSiteId}-${index.toString()}`;
const transporterKey: string = transporter.clientKey || uuidv4();
return (
<Card key={transporterKey} className="py-2 ps-4 pe-2 my-2">
<Row className="d-flex justify-content-around">
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Manifest/manifestSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const handlerSchema = rcraSite.extend({
export type Handler = z.infer<typeof handlerSchema>;

export const transporterSchema = handlerSchema.extend({
clientKey: z.string().optional(),
order: z.number(),
manifest: z.number().optional(),
});
Expand Down
6 changes: 6 additions & 0 deletions client/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ Object.defineProperty(window, 'matchMedia', {
dispatchEvent: vi.fn(),
})),
});

// Mocking the useAutoAnimate hook which causes error in the test environment
// https://github.com/formkit/auto-animate/issues/149#issuecomment-1782772600
vi.mock('@formkit/auto-animate/react', () => ({
useAutoAnimate: () => [null],
}));

0 comments on commit eff012b

Please sign in to comment.