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

B-21460 Mobile Home and Boat shipments now have 2nd/3rd Address #14405

Merged
merged 23 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0b862c8
mobile home and boat shipments now have 2nd and 3rd address on create…
loganwc Dec 16, 2024
6fd4cf0
added 3rd address and fixed 2nd address test
loganwc Dec 18, 2024
1c384d6
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
loganwc Dec 18, 2024
224795c
Merge remote-tracking branch 'refs/remotes/origin/B-21460-Fix-Prime-S…
loganwc Dec 18, 2024
0c3f4ff
change typo
loganwc Dec 18, 2024
10824da
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
loganwc Dec 18, 2024
ae862c0
added more test coverage to prime ui shipment create
loganwc Dec 18, 2024
e98c6dc
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
loganwc Dec 18, 2024
7acc613
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
loganwc Dec 18, 2024
26ba792
moved test from create to form
loganwc Dec 23, 2024
2bd0fd2
removed comment
loganwc Dec 23, 2024
5f5c6fb
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
loganwc Dec 26, 2024
ad255d9
do the create tests for mobile home and boats
loganwc Dec 26, 2024
67500e1
moved ff check out of form
loganwc Dec 26, 2024
27b76a6
big test
loganwc Dec 27, 2024
6b58ef9
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
loganwc Dec 27, 2024
5df2014
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
loganwc Jan 6, 2025
15e1fd6
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
loganwc Jan 6, 2025
d456a0a
just redid everything because stupid test coverage
loganwc Jan 7, 2025
e585b23
just redid everything because stupid test coverage
loganwc Jan 7, 2025
b5fb680
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
loganwc Jan 13, 2025
0628a59
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
pambecker Jan 13, 2025
92f4d28
Merge branch 'main' into B-21460-Fix-Prime-Sim-Shipment-Create
pambecker Jan 13, 2025
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
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
Loading