Skip to content

Commit

Permalink
Merge pull request #14405 from transcom/B-21460-Fix-Prime-Sim-Shipmen…
Browse files Browse the repository at this point in the history
…t-Create

B-21460 Mobile Home and Boat shipments now have 2nd/3rd Address
  • Loading branch information
pambecker authored Jan 13, 2025
2 parents 49931ba + 92f4d28 commit d4f56b3
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 80 deletions.
139 changes: 79 additions & 60 deletions src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { Formik } from 'formik';
import * as Yup from 'yup';
import { useNavigate, useParams, generatePath } from 'react-router-dom';
Expand All @@ -15,19 +15,29 @@ import styles from 'components/Office/CustomerContactInfoForm/CustomerContactInf
import { Form } from 'components/form/Form';
import formStyles from 'styles/form.module.scss';
import WizardNavigation from 'components/Customer/WizardNavigation/WizardNavigation';
import { isEmpty, isValidWeight } from 'shared/utils';
import { checkAddressTogglesToClearAddresses, isEmpty, isValidWeight } from 'shared/utils';
import { formatAddressForPrimeAPI, formatSwaggerDate } from 'utils/formatters';
import { setFlashMessage as setFlashMessageAction } from 'store/flash/actions';
import { requiredAddressSchema, partialRequiredAddressSchema } from 'utils/validation';
import PrimeUIShipmentCreateForm from 'pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm';
import { OptionalAddressSchema } from 'components/Customer/MtoShipmentForm/validationSchemas';
import { SHIPMENT_OPTIONS, SHIPMENT_TYPES } from 'shared/constants';
import { FEATURE_FLAG_KEYS, SHIPMENT_OPTIONS, SHIPMENT_TYPES } from 'shared/constants';
import { isBooleanFlagEnabled } from 'utils/featureFlags';

const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
const [errorMessage, setErrorMessage] = useState();
const { moveCodeOrID } = useParams();
const navigate = useNavigate();

const [enableBoat, setEnableBoat] = useState(false);
const [enableMobileHome, setEnableMobileHome] = useState(false);

useEffect(() => {
const fetchData = async () => {
setEnableBoat(await isBooleanFlagEnabled(FEATURE_FLAG_KEYS.BOAT));
setEnableMobileHome(await isBooleanFlagEnabled(FEATURE_FLAG_KEYS.MOBILE_HOME));
};
fetchData();
}, []);
const handleClose = () => {
navigate(generatePath(primeSimulatorRoutes.VIEW_MOVE_PATH, { moveCodeOrID }));
};
Expand Down Expand Up @@ -105,29 +115,8 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
hasTertiaryDestinationAddress,
},
} = values;
let {
ppmShipment: {
tertiaryPickupAddress,
tertiaryDestinationAddress,
secondaryPickupAddress,
secondaryDestinationAddress,
},
} = values;

if (hasSecondaryPickupAddress !== 'true') {
secondaryPickupAddress = {};
tertiaryPickupAddress = {};
}
if (hasTertiaryPickupAddress !== 'true') {
tertiaryPickupAddress = {};
}
if (hasSecondaryDestinationAddress !== 'true') {
secondaryDestinationAddress = {};
tertiaryDestinationAddress = {};
}
if (hasTertiaryDestinationAddress !== 'true') {
tertiaryDestinationAddress = {};
}
const updatedValues = checkAddressTogglesToClearAddresses(values);

body = {
moveTaskOrderID: moveCodeOrID,
Expand All @@ -136,19 +125,19 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
ppmShipment: {
expectedDepartureDate: expectedDepartureDate ? formatSwaggerDate(expectedDepartureDate) : null,
pickupAddress: isEmpty(pickupAddress) ? null : formatAddressForPrimeAPI(pickupAddress),
secondaryPickupAddress: isEmpty(secondaryPickupAddress)
? null
: formatAddressForPrimeAPI(secondaryPickupAddress),
destinationAddress: isEmpty(destinationAddress) ? null : formatAddressForPrimeAPI(destinationAddress),
secondaryDestinationAddress: isEmpty(secondaryDestinationAddress)
secondaryPickupAddress: isEmpty(updatedValues.secondaryPickupAddress)
? null
: formatAddressForPrimeAPI(secondaryDestinationAddress),
tertiaryPickupAddress: isEmpty(tertiaryPickupAddress)
: formatAddressForPrimeAPI(updatedValues.secondaryPickupAddress),
secondaryDestinationAddress: isEmpty(updatedValues.secondaryDestinationAddress)
? null
: formatAddressForPrimeAPI(tertiaryPickupAddress),
tertiaryDestinationAddress: isEmpty(tertiaryDestinationAddress)
: formatAddressForPrimeAPI(updatedValues.secondaryDestinationAddress),
tertiaryPickupAddress: isEmpty(updatedValues.tertiaryPickupAddress)
? null
: formatAddressForPrimeAPI(tertiaryDestinationAddress),
: formatAddressForPrimeAPI(updatedValues.tertiaryPickupAddress),
tertiaryDestinationAddress: isEmpty(updatedValues.tertiaryDestinationAddress)
? null
: formatAddressForPrimeAPI(updatedValues.tertiaryDestinationAddress),
sitExpected,
...(sitExpected && {
sitLocation: sitLocation || null,
Expand Down Expand Up @@ -177,6 +166,10 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
destinationAddress,
diversion,
divertedFromShipmentId,
hasSecondaryPickupAddress,
hasSecondaryDestinationAddress,
hasTertiaryPickupAddress,
hasTertiaryDestinationAddress,
boatShipment: {
year,
make,
Expand All @@ -192,6 +185,8 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
},
} = values;

const updatedValues = checkAddressTogglesToClearAddresses(values);

// Sum the feet and inches fields into only inches for backend/db
const totalLengthInInches = parseInt(lengthInFeet, 10) * 12 + parseInt(lengthInInches, 10);
const totalWidthInInches = parseInt(widthInFeet, 10) * 12 + parseInt(widthInInches, 10);
Expand Down Expand Up @@ -219,6 +214,22 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
destinationAddress: isEmpty(destinationAddress) ? null : formatAddressForPrimeAPI(destinationAddress),
diversion: diversion || null,
divertedFromShipmentId: divertedFromShipmentId || null,
hasSecondaryPickupAddress: hasSecondaryPickupAddress === 'true',
hasSecondaryDestinationAddress: hasSecondaryDestinationAddress === 'true',
hasTertiaryPickupAddress: hasTertiaryPickupAddress === 'true',
hasTertiaryDestinationAddress: hasTertiaryDestinationAddress === 'true',
secondaryPickupAddress: isEmpty(updatedValues.secondaryPickupAddress)
? null
: formatAddressForPrimeAPI(updatedValues.secondaryPickupAddress),
secondaryDestinationAddress: isEmpty(updatedValues.secondaryDestinationAddress)
? null
: formatAddressForPrimeAPI(updatedValues.secondaryDestinationAddress),
tertiaryPickupAddress: isEmpty(updatedValues.tertiaryPickupAddress)
? null
: formatAddressForPrimeAPI(updatedValues.tertiaryPickupAddress),
tertiaryDestinationAddress: isEmpty(updatedValues.tertiaryDestinationAddress)
? null
: formatAddressForPrimeAPI(updatedValues.tertiaryDestinationAddress),
};
} else if (isMobileHome) {
const {
Expand All @@ -229,6 +240,10 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
destinationAddress,
diversion,
divertedFromShipmentId,
hasSecondaryPickupAddress,
hasSecondaryDestinationAddress,
hasTertiaryPickupAddress,
hasTertiaryDestinationAddress,
mobileHomeShipment: {
year,
make,
Expand All @@ -242,6 +257,8 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
},
} = values;

const updatedValues = checkAddressTogglesToClearAddresses(values);

// Sum the feet and inches fields into only inches for backend/db
const totalLengthInInches = parseInt(lengthInFeet, 10) * 12 + parseInt(lengthInInches, 10);
const totalWidthInInches = parseInt(widthInFeet, 10) * 12 + parseInt(widthInInches, 10);
Expand All @@ -265,6 +282,22 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
destinationAddress: isEmpty(destinationAddress) ? null : formatAddressForPrimeAPI(destinationAddress),
diversion: diversion || null,
divertedFromShipmentId: divertedFromShipmentId || null,
hasSecondaryPickupAddress: hasSecondaryPickupAddress === 'true',
hasSecondaryDestinationAddress: hasSecondaryDestinationAddress === 'true',
hasTertiaryPickupAddress: hasTertiaryPickupAddress === 'true',
hasTertiaryDestinationAddress: hasTertiaryDestinationAddress === 'true',
secondaryPickupAddress: isEmpty(updatedValues.secondaryPickupAddress)
? null
: formatAddressForPrimeAPI(updatedValues.secondaryPickupAddress),
secondaryDestinationAddress: isEmpty(updatedValues.secondaryDestinationAddress)
? null
: formatAddressForPrimeAPI(updatedValues.secondaryDestinationAddress),
tertiaryPickupAddress: isEmpty(updatedValues.tertiaryPickupAddress)
? null
: formatAddressForPrimeAPI(updatedValues.tertiaryPickupAddress),
tertiaryDestinationAddress: isEmpty(updatedValues.tertiaryDestinationAddress)
? null
: formatAddressForPrimeAPI(updatedValues.tertiaryDestinationAddress),
};
} else {
const {
Expand All @@ -280,23 +313,7 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
hasTertiaryDestinationAddress,
} = values;

let { tertiaryPickupAddress, tertiaryDestinationAddress, secondaryPickupAddress, secondaryDestinationAddress } =
values;

if (hasSecondaryPickupAddress !== 'true') {
secondaryPickupAddress = {};
tertiaryPickupAddress = {};
}
if (hasTertiaryPickupAddress !== 'true') {
tertiaryPickupAddress = {};
}
if (hasSecondaryDestinationAddress !== 'true') {
secondaryDestinationAddress = {};
tertiaryDestinationAddress = {};
}
if (hasTertiaryDestinationAddress !== 'true') {
tertiaryDestinationAddress = {};
}
const updatedValues = checkAddressTogglesToClearAddresses(values);

body = {
moveTaskOrderID: moveCodeOrID,
Expand All @@ -311,16 +328,18 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
hasSecondaryDestinationAddress: hasSecondaryDestinationAddress === 'true',
hasTertiaryPickupAddress: hasTertiaryPickupAddress === 'true',
hasTertiaryDestinationAddress: hasTertiaryDestinationAddress === 'true',
secondaryPickupAddress: isEmpty(secondaryPickupAddress)
secondaryPickupAddress: isEmpty(updatedValues.secondaryPickupAddress)
? null
: formatAddressForPrimeAPI(updatedValues.secondaryPickupAddress),
secondaryDestinationAddress: isEmpty(updatedValues.secondaryDestinationAddress)
? null
: formatAddressForPrimeAPI(secondaryPickupAddress),
secondaryDestinationAddress: isEmpty(secondaryDestinationAddress)
: formatAddressForPrimeAPI(updatedValues.secondaryDestinationAddress),
tertiaryPickupAddress: isEmpty(updatedValues.tertiaryPickupAddress)
? null
: formatAddressForPrimeAPI(secondaryDestinationAddress),
tertiaryPickupAddress: isEmpty(tertiaryPickupAddress) ? null : formatAddressForPrimeAPI(tertiaryPickupAddress),
tertiaryDestinationAddress: isEmpty(tertiaryDestinationAddress)
: formatAddressForPrimeAPI(updatedValues.tertiaryPickupAddress),
tertiaryDestinationAddress: isEmpty(updatedValues.tertiaryDestinationAddress)
? null
: formatAddressForPrimeAPI(tertiaryDestinationAddress),
: formatAddressForPrimeAPI(updatedValues.tertiaryDestinationAddress),
};
}

Expand Down Expand Up @@ -606,7 +625,7 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => {
{({ isValid, isSubmitting, handleSubmit }) => {
return (
<Form className={formStyles.form}>
<PrimeUIShipmentCreateForm />
<PrimeUIShipmentCreateForm enableBoat={enableBoat} enableMobileHome={enableMobileHome} />
<div className={formStyles.formActions}>
<WizardNavigation
editMode
Expand Down
Loading

0 comments on commit d4f56b3

Please sign in to comment.