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

MB-13125 - handle state for weightTickets #8873

Merged
merged 19 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Expand Up @@ -30,7 +30,7 @@ const validationSchema = Yup.object().shape({
vehicleDescription: Yup.string().required('Required'),
emptyWeight: Yup.number().min(0, 'Enter a weight 0 lbs or greater').required('Required'),
missingEmptyWeightTicket: Yup.boolean(),
emptyWeightTickets: Yup.array().of(uploadShape).min(1, 'At least one upload is required'),
emptyDocument: Yup.array().of(uploadShape).min(1, 'At least one upload is required'),
fullWeight: Yup.number()
.min(0, 'Enter a weight 0 lbs or greater')
.required('Required')
Expand All @@ -40,10 +40,10 @@ const validationSchema = Yup.object().shape({
: schema;
}),
missingFullWeightTicket: Yup.boolean(),
fullWeightTickets: Yup.array().of(uploadShape).min(1, 'At least one upload is required'),
fullDocument: Yup.array().of(uploadShape).min(1, 'At least one upload is required'),
hasOwnTrailer: Yup.boolean().required('Required'),
trailerMeetsCriteria: Yup.boolean(),
trailerOwnershipDocs: Yup.array()
proofOfTrailerOwnershipDocument: Yup.array()
.of(uploadShape)
.when('trailerMeetsCriteria', (trailerMeetsCriteria, schema) => {
return trailerMeetsCriteria ? schema.min(1, 'At least one upload is required') : schema;
Expand Down Expand Up @@ -88,7 +88,7 @@ const WeightTicketUpload = ({
formikProps: { touched, errors, setFieldTouched, setFieldValue },
}) => {
const weightTicketUploadLabel = (name, showConstructedWeight) => {
if (name === 'emptyWeightTickets') {
if (name === 'emptyDocument') {
return showConstructedWeight ? 'Upload constructed weight spreadsheet' : 'Upload empty weight ticket';
}

Expand Down Expand Up @@ -173,31 +173,31 @@ const WeightTicketForm = ({
vehicleDescription,
missingEmptyWeightTicket,
emptyWeight,
emptyWeightTickets,
emptyDocument,
fullWeight,
missingFullWeightTicket,
fullWeightTickets,
fullDocument,
hasOwnTrailer,
trailerMeetsCriteria,
trailerOwnershipDocs,
proofOfTrailerOwnershipDocument,
} = weightTicket || {};

const initialValues = {
vehicleDescription: vehicleDescription || '',
missingEmptyWeightTicket: !!missingEmptyWeightTicket,
emptyWeight: emptyWeight ? `${emptyWeight}` : '',
emptyWeightTickets: emptyWeightTickets || [],
emptyDocument: emptyDocument || [],
fullWeight: fullWeight ? `${fullWeight}` : '',
missingFullWeightTicket: !!missingFullWeightTicket,
fullWeightTickets: fullWeightTickets || [],
fullDocument: fullDocument || [],
hasOwnTrailer: hasOwnTrailer ? 'true' : 'false',
trailerMeetsCriteria: trailerMeetsCriteria ? 'true' : 'false',
trailerOwnershipDocs: trailerOwnershipDocs || [],
proofOfTrailerOwnershipDocument: proofOfTrailerOwnershipDocument || [],
};

const emptyWeightTicketsRef = createRef();
const fullWeightTicketsRef = createRef();
const trailerOwnershipDocsRef = createRef();
const emptyDocumentRef = createRef();
const fullDocumentRef = createRef();
const proofOfTrailerOwnershipDocumentRef = createRef();

return (
<Formik initialValues={initialValues} validationSchema={validationSchema} onSubmit={onSubmit}>
Expand Down Expand Up @@ -230,12 +230,12 @@ const WeightTicketForm = ({
/>
<div>
<WeightTicketUpload
fieldName="emptyWeightTickets"
fieldName="emptyDocument"
missingWeightTicket={values.missingEmptyWeightTicket}
onCreateUpload={onCreateUpload}
onUploadComplete={onUploadComplete}
onUploadDelete={onUploadDelete}
fileUploadRef={emptyWeightTicketsRef}
fileUploadRef={emptyDocumentRef}
values={values}
formikProps={formikProps}
/>
Expand All @@ -260,12 +260,12 @@ const WeightTicketForm = ({
/>
<div>
<WeightTicketUpload
fieldName="fullWeightTickets"
fieldName="fullDocument"
missingWeightTicket={values.missingFullWeightTicket}
onCreateUpload={onCreateUpload}
onUploadComplete={onUploadComplete}
onUploadDelete={onUploadDelete}
fileUploadRef={fullWeightTicketsRef}
fileUploadRef={fullDocumentRef}
values={values}
formikProps={formikProps}
/>
Expand Down Expand Up @@ -331,11 +331,11 @@ const WeightTicketForm = ({
<div>
<UploadsTable
className={styles.uploadsTable}
uploads={values.trailerOwnershipDocs}
uploads={values.proofOfTrailerOwnershipDocument}
onDelete={(uploadId) =>
onUploadDelete(
uploadId,
'trailerOwnershipDocs',
'proofOfTrailerOwnershipDocument',
values,
formikProps.setFieldTouched,
formikProps.setFieldValue,
Expand All @@ -344,23 +344,24 @@ const WeightTicketForm = ({
/>
<FormGroup
error={
formikProps.touched?.trailerOwnershipDocs && formikProps.errors?.trailerOwnershipDocs
formikProps.touched?.proofOfTrailerOwnershipDocument &&
formikProps.errors?.proofOfTrailerOwnershipDocument
}
>
<div className="labelWrapper">
<Label
error={
formikProps.touched?.trailerOwnershipDocs &&
formikProps.errors?.trailerOwnershipDocs
formikProps.touched?.proofOfTrailerOwnershipDocument &&
formikProps.errors?.proofOfTrailerOwnershipDocument
}
htmlFor="trailerOwnershipDocs"
htmlFor="proofOfTrailerOwnershipDocument"
>
Upload proof of ownership
</Label>
</div>
{formikProps.touched?.trailerOwnershipDocs &&
formikProps.errors?.trailerOwnershipDocs && (
<ErrorMessage>{formikProps.errors?.trailerOwnershipDocs}</ErrorMessage>
{formikProps.touched?.proofOfTrailerOwnershipDocument &&
formikProps.errors?.proofOfTrailerOwnershipDocument && (
<ErrorMessage>{formikProps.errors?.proofOfTrailerOwnershipDocument}</ErrorMessage>
)}
<Hint>
<p>Examples include a registration or bill of sale.</p>
Expand All @@ -371,23 +372,23 @@ const WeightTicketForm = ({
<p className={styles.uploadTypeHint}>{DocumentAndImageUploadInstructions}</p>
</Hint>
<FileUpload
name="trailerOwnershipDocs"
createUpload={(file) => onCreateUpload('trailerOwnershipDocs', file)}
name="proofOfTrailerOwnershipDocument"
createUpload={(file) => onCreateUpload('proofOfTrailerOwnershipDocument', file)}
labelIdle={UploadDropZoneLabel}
labelIdleMobile={UploadDropZoneLabelMobile}
onChange={(err, upload) => {
formikProps.setFieldTouched('trailerOwnershipDocs', true);
formikProps.setFieldTouched('proofOfTrailerOwnershipDocument', true);
onUploadComplete(
upload,
err,
'trailerOwnershipDocs',
'proofOfTrailerOwnershipDocument',
values,
formikProps.setFieldValue,
);
trailerOwnershipDocsRef.current.removeFile(upload.id);
proofOfTrailerOwnershipDocumentRef.current.removeFile(upload.id);
}}
acceptedFileTypes={acceptableFileTypes}
ref={trailerOwnershipDocsRef}
ref={proofOfTrailerOwnershipDocumentRef}
/>
</FormGroup>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ExistingWeightTickets.args = {
vehicleDescription: 'DMC Delorean',
missingEmptyWeightTicket: false,
emptyWeight: 3456,
emptyWeightTickets: [
emptyDocument: [
{
id: 'db4713ae-6087-4330-8b0d-926b3d65c454',
created_at: '2022-06-10T12:59:30.000Z',
Expand All @@ -98,7 +98,7 @@ ExistingWeightTickets.args = {
],
fullWeight: 6789,
missingFullWeightTicket: false,
fullWeightTickets: [
fullDocument: [
{
id: '28e6e387-7b2d-441b-b96f-f9ba7ed6e794',
created_at: '2022-06-09T06:30:59.000Z',
Expand Down Expand Up @@ -141,7 +141,7 @@ MissingWeightTickets.args = {
vehicleDescription: 'DMC Delorean',
missingEmptyWeightTicket: true,
emptyWeight: 3456,
emptyWeightTickets: [
emptyDocument: [
{
id: 'db4713ae-6087-4330-8b0d-926b3d65c454',
created_at: '2022-06-10T12:59:30.000Z',
Expand All @@ -153,7 +153,7 @@ MissingWeightTickets.args = {
],
fullWeight: 6789,
missingFullWeightTicket: true,
fullWeightTickets: [
fullDocument: [
{
id: '28e6e387-7b2d-441b-b96f-f9ba7ed6e794',
created_at: '2022-06-09T06:30:59.000Z',
Expand Down Expand Up @@ -186,7 +186,7 @@ TrailerOwnership.args = {
vehicleDescription: 'DMC Delorean',
missingEmptyWeightTicket: false,
emptyWeight: 3456,
emptyWeightTickets: [
emptyDocument: [
{
id: 'db4713ae-6087-4330-8b0d-926b3d65c454',
created_at: '2022-06-10T12:59:30.000Z',
Expand All @@ -198,7 +198,7 @@ TrailerOwnership.args = {
],
fullWeight: 6789,
missingFullWeightTicket: false,
fullWeightTickets: [
fullDocument: [
{
id: '28e6e387-7b2d-441b-b96f-f9ba7ed6e794',
created_at: '2022-06-09T06:30:59.000Z',
Expand All @@ -218,7 +218,7 @@ TrailerOwnership.args = {
],
hasOwnTrailer: true,
trailerMeetsCriteria: true,
trailerOwnershipDocs: [
proofOfTrailerOwnershipDocument: [
{
id: '8477cc1f-29da-4e3c-a1ce-34db433cf926',
created_at: '2022-06-11T12:59:30.000Z',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const weightTicketRequiredProps = {
vehicleDescription: 'DMC Delorean',
emptyWeight: 3999,
emptyWeightDocumentId: '27d70a0d-7f20-42af-ab79-f74350412823',
emptyWeightTickets: [
emptyDocument: [
{
id: '299e2fb4-432d-4261-bbed-d8280c6090af',
created_at: '2022-06-22T23:25:50.490Z',
Expand All @@ -44,7 +44,7 @@ const weightTicketRequiredProps = {
],
fullWeight: 7111,
fullWeightDocumentId: '1ec00b40-447d-4c22-ac73-708b98b8bc20',
fullWeightTickets: [
fullDocument: [
{
id: 'f70af8a1-38e9-4ae2-a837-3c0c61069a0d',
created_at: '2022-06-23T23:25:50.490Z',
Expand All @@ -64,7 +64,7 @@ const weightTicketUploadsOnlyProps = {
id: '58350bae-8e87-4e83-bd75-74027fb4853f',
shipmentId: '8be77cb9-e8af-4ff0-b0a2-ade17cf6653c',
emptyWeightDocumentId: '27d70a0d-7f20-42af-ab79-f74350412823',
emptyWeightTickets: [
emptyDocument: [
{
id: '299e2fb4-432d-4261-bbed-d8280c6090af',
created_at: '2022-06-22T23:25:50.490Z',
Expand All @@ -75,7 +75,7 @@ const weightTicketUploadsOnlyProps = {
},
],
fullWeightDocumentId: '1ec00b40-447d-4c22-ac73-708b98b8bc20',
fullWeightTickets: [
fullDocument: [
{
id: 'f70af8a1-38e9-4ae2-a837-3c0c61069a0d',
created_at: '2022-06-23T23:25:50.490Z',
Expand All @@ -96,7 +96,7 @@ const constructedWeightTrailerProps = {
emptyWeight: 3999,
missingEmptyWeightTicket: true,
emptyWeightDocumentId: '27d70a0d-7f20-42af-ab79-f74350412823',
emptyWeightTickets: [
emptyDocument: [
{
id: '299e2fb4-432d-4261-bbed-d8280c6090af',
created_at: '2022-06-22T23:25:50.490Z',
Expand All @@ -109,7 +109,7 @@ const constructedWeightTrailerProps = {
fullWeight: 7111,
missingFullWeightTicket: true,
fullWeightDocumentId: '1ec00b40-447d-4c22-ac73-708b98b8bc20',
fullWeightTickets: [
fullDocument: [
{
id: 'f70af8a1-38e9-4ae2-a837-3c0c61069a0d',
created_at: '2022-06-23T23:25:50.490Z',
Expand All @@ -122,7 +122,7 @@ const constructedWeightTrailerProps = {
hasOwnTrailer: true,
trailerMeetsCriteria: true,
trailerOwnershipDocumentId: '5bf3ed20-08dd-4d8e-92ad-7603bb6377a5',
trailerOwnershipDocs: [
proofOfTrailerOwnershipDocument: [
{
id: 'fd4e80f8-d025-44b2-8c33-15240fac51ab',
created_at: '2022-06-24T23:25:50.490Z',
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('WeightTicketForm component', () => {
vehicleDescription: 'DMC Delorean',
emptyWeight: '4999',
missingEmptyWeightTicket: false,
emptyWeightTickets: [
emptyDocument: [
{
id: '299e2fb4-432d-4261-bbed-d8280c6090af',
created_at: '2022-06-22T23:25:50.490Z',
Expand All @@ -335,7 +335,7 @@ describe('WeightTicketForm component', () => {
],
fullWeight: '6999',
missingFullWeightTicket: false,
fullWeightTickets: [
fullDocument: [
{
id: 'f70af8a1-38e9-4ae2-a837-3c0c61069a0d',
created_at: '2022-06-23T23:25:50.490Z',
Expand All @@ -347,7 +347,7 @@ describe('WeightTicketForm component', () => {
],
hasOwnTrailer: 'false',
trailerMeetsCriteria: 'false',
trailerOwnershipDocs: [],
proofOfTrailerOwnershipDocument: [],
},
expect.anything(),
);
Expand All @@ -364,7 +364,7 @@ describe('WeightTicketForm component', () => {
vehicleDescription: 'DMC Delorean',
emptyWeight: '3999',
missingEmptyWeightTicket: true,
emptyWeightTickets: [
emptyDocument: [
{
id: '299e2fb4-432d-4261-bbed-d8280c6090af',
created_at: '2022-06-22T23:25:50.490Z',
Expand All @@ -376,7 +376,7 @@ describe('WeightTicketForm component', () => {
],
fullWeight: '7111',
missingFullWeightTicket: true,
fullWeightTickets: [
fullDocument: [
{
id: 'f70af8a1-38e9-4ae2-a837-3c0c61069a0d',
created_at: '2022-06-23T23:25:50.490Z',
Expand All @@ -388,7 +388,7 @@ describe('WeightTicketForm component', () => {
],
hasOwnTrailer: 'true',
trailerMeetsCriteria: 'true',
trailerOwnershipDocs: [
proofOfTrailerOwnershipDocument: [
{
id: 'fd4e80f8-d025-44b2-8c33-15240fac51ab',
created_at: '2022-06-24T23:25:50.490Z',
Expand Down
Loading