diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx index 36139c32e23..c7117373da0 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx @@ -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'; @@ -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 })); }; @@ -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, @@ -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, @@ -177,6 +166,10 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { destinationAddress, diversion, divertedFromShipmentId, + hasSecondaryPickupAddress, + hasSecondaryDestinationAddress, + hasTertiaryPickupAddress, + hasTertiaryDestinationAddress, boatShipment: { year, make, @@ -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); @@ -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 { @@ -229,6 +240,10 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { destinationAddress, diversion, divertedFromShipmentId, + hasSecondaryPickupAddress, + hasSecondaryDestinationAddress, + hasTertiaryPickupAddress, + hasTertiaryDestinationAddress, mobileHomeShipment: { year, make, @@ -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); @@ -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 { @@ -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, @@ -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), }; } @@ -606,7 +625,7 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { {({ isValid, isSubmitting, handleSubmit }) => { return (
- +
({ const moveDetailsURL = generatePath(primeSimulatorRoutes.VIEW_MOVE_PATH, { moveCodeOrID: moveId }); +const initialValues = { + shipmentType: '', + + // PPM + counselorRemarks: '', + ppmShipment: { + expectedDepartureDate: '', + sitExpected: false, + sitLocation: '', + sitEstimatedWeight: '', + sitEstimatedEntryDate: '', + sitEstimatedDepartureDate: '', + estimatedWeight: '', + hasProGear: false, + proGearWeight: '', + spouseProGearWeight: '', + pickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + destinationAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + secondaryDeliveryAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + secondaryPickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + tertiaryDeliveryAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + tertiaryPickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + hasSecondaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasTertiaryDestinationAddress: 'false', + }, + + // Boat Shipment + boatShipment: { + make: 'make', + model: 'model', + year: 1999, + hasTrailer: true, + isRoadworthy: true, + lengthInFeet: 16, + lengthInInches: 0, + widthInFeet: 1, + widthInInches: 1, + heightInFeet: 1, + heightInInches: 1, + }, + + // Mobile Home Shipment + mobileHomeShipment: { + make: 'mobile make', + model: 'mobile model', + year: 1999, + lengthInFeet: 16, + lengthInInches: 0, + widthInFeet: 1, + widthInInches: 1, + heightInFeet: 1, + heightInInches: 1, + }, + + // Other shipment types + requestedPickupDate: '', + estimatedWeight: '', + pickupAddress: {}, + destinationAddress: {}, + secondaryDeliveryAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + secondaryPickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + tertiaryDeliveryAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + tertiaryPickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + hasSecondaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasTertiaryDestinationAddress: 'false', + diversion: '', + divertedFromShipmentId: '', +}; + const mockedComponent = ( - + + + + + ); @@ -145,7 +274,7 @@ describe('Create PPM', () => { await userEvent.selectOptions(screen.getByLabelText('Shipment type'), 'PPM'); // Start controlled test case to verify everything is working. - let input = await document.querySelector('input[name="ppmShipment.pickupAddress.streetAddress1"]'); + let input = await document.querySelector('input[name=ppmShipment.pickupAddress.streetAddress1]'); expect(input).toBeInTheDocument(); // enter required street 1 for pickup await userEvent.type(input, '123 Street'); @@ -159,7 +288,7 @@ describe('Create PPM', () => { await userEvent.type(input, '123 Street'); // Verify destination address street 1 is OPTIONAL. - input = await document.querySelector('input[name="ppmShipment.destinationAddress.streetAddress1"]'); + input = await document.querySelector('input[name=ppmShipment.destinationAddress.streetAddress1]'); expect(input).toBeInTheDocument(); // enter something await userEvent.type(input, '123 Street'); @@ -171,3 +300,189 @@ describe('Create PPM', () => { }); }); }); + +describe('Create PPM Home', () => { + it('test with 2nd and 3rd addresses', async () => { + createPrimeMTOShipmentV3.mockReturnValue({}); + + render(mockedComponent); + + waitFor(async () => { + await userEvent.selectOptions(screen.getByLabelText('Shipment type'), 'PPM'); + + // Start controlled test case to verify everything is working. + let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup + await userEvent.type(input, '123 Street'); + + const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); + expect(secondAddressToggle).toBeInTheDocument(); + await userEvent.click(secondAddressToggle); + + input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street 2'); + + const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); + expect(thirdAddressToggle).toBeInTheDocument(); + await userEvent.click(thirdAddressToggle); + + input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street 3'); + + input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter something + await userEvent.type(input, '123 Street'); + + const saveButton = await screen.getByRole('button', { name: 'Save' }); + + expect(saveButton).not.toBeDisabled(); + await userEvent.click(saveButton); + + await waitFor(() => { + expect(mockNavigate).toHaveBeenCalledWith(moveDetailsURL); + }); + }); + }); +}); + +describe('Create Mobile Home and Boat', () => { + it.each(['MOBILE_HOME', 'BOAT_TOW_AWAY', 'BOAT_HAUL_AWAY'])( + 'resets secondary and tertiary addresses when flags are not true for shipment type %s', + async (shipmentType) => { + isBooleanFlagEnabled.mockImplementation(() => Promise.resolve(true)); + createPrimeMTOShipmentV3.mockReturnValue({}); + + // Render the component + render(mockedComponent); + + // Wait for the component to load + waitFor(async () => { + expect(screen.getByLabelText('Shipment type')).toBeInTheDocument(); + + // Select shipment type + await userEvent.selectOptions(screen.getByLabelText('Shipment type'), shipmentType); + + await userEvent.type(screen.getByLabelText('Requested pickup'), '01 Nov 2020'); + + // Fill in required pickup and destination addresses + let input = document.querySelector('input[name=pickupAddress.streetAddress1]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '123 Street'); + input = document.querySelector('input[name=pickupAddress.city]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'Folsom'); + input = document.querySelector('input[name=pickupAddress.state]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'CA'); + input = document.querySelector('input[name=pickupAddress.postalCode]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '95630'); + + input = document.querySelector('input[name=destinationAddress.streetAddress1]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '456 Destination St'); + input = document.querySelector('input[name=destinationAddress.city]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'Bevy Hills'); + input = document.querySelector('input[name=destinationAddress.state]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'CA'); + input = document.querySelector('input[name=destinationAddress.postalCode]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '90210'); + + // Enable and disable secondary and tertiary toggles + const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); + expect(secondAddressToggle).toBeInTheDocument(); + await userEvent.click(secondAddressToggle); + + input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Pickup Street 2'); + + const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); + expect(thirdAddressToggle).toBeInTheDocument(); + await userEvent.click(thirdAddressToggle); + + input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Pickup Street 3'); + + const disable2ndAddressToggle = document.querySelector('[data-testid="no-secondary-pickup"]'); + expect(disable2ndAddressToggle).toBeInTheDocument(); + await userEvent.click(disable2ndAddressToggle); + + // input boat/mobile home model info + input = document.createElement('input[label="Year"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '2023'); + + input = document.createElement('input[label="Make"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'Genesis'); + + input = document.createElement('input[label="Model"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'G70'); + + // input boat/mobile home dimensions + input = document.createElement('input[label="Length (Feet)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Length (Inches)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Width (Feet)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Width (Inches)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Height (Feet)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Height (Inches)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + // Submit the form + const saveButton = screen.getByRole('button', { name: 'Save' }); + expect(saveButton).not.toBeDisabled(); + await userEvent.click(saveButton); + }); + + expect(createPrimeMTOShipmentV3).toHaveBeenCalledWith({ + body: expect.objectContaining({ + destinationAddress: null, + diversion: null, + divertedFromShipmentId: null, + hasSecondaryDestinationAddress: false, + hasSecondaryPickupAddress: false, + hasTertiaryDestinationAddress: false, + hasTertiaryPickupAddress: false, + secondaryDestinationAddress: null, + secondaryPickupAddress: null, + tertiaryDestinationAddress: null, + tertiaryPickupAddress: null, + moveTaskOrderID: '9c7b255c-2981-4bf8-839f-61c7458e2b4d', + pickupAddress: null, + primeEstimatedWeight: null, + requestedPickupDate: null, + }), + }); + }, + ); +}); diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx index 534dc315b2a..3a3ae6b215a 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx @@ -1,10 +1,8 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState } from 'react'; import { Radio, FormGroup, Label, Textarea } from '@trussworks/react-uswds'; import { Field, useField, useFormikContext } from 'formik'; -import { isBooleanFlagEnabled } from '../../../utils/featureFlags'; - -import { SHIPMENT_OPTIONS, SHIPMENT_TYPES, FEATURE_FLAG_KEYS } from 'shared/constants'; +import { SHIPMENT_OPTIONS, SHIPMENT_TYPES } from 'shared/constants'; import { CheckboxField, DatePickerInput, DropdownInput } from 'components/form/fields'; import MaskedTextField from 'components/form/fields/MaskedTextField/MaskedTextField'; import styles from 'components/Office/CustomerContactInfoForm/CustomerContactInfoForm.module.scss'; @@ -17,7 +15,7 @@ import { LOCATION_TYPES } from 'types/sitStatusShape'; const sitLocationOptions = dropdownInputOptions(LOCATION_TYPES); -const PrimeUIShipmentCreateForm = () => { +const PrimeUIShipmentCreateForm = ({ enableBoat, enableMobileHome }) => { const { values, setFieldTouched, setFieldValue } = useFormikContext(); const { shipmentType } = values; const { sitExpected, hasProGear } = values.ppmShipment; @@ -25,8 +23,6 @@ const PrimeUIShipmentCreateForm = () => { const [, , checkBoxHelperProps] = useField('diversion'); const [, , divertedFromIdHelperProps] = useField('divertedFromShipmentId'); const [isChecked, setIsChecked] = useState(false); - const [enableBoat, setEnableBoat] = useState(false); - const [enableMobileHome, setEnableMobileHome] = useState(false); const hasShipmentType = !!shipmentType; const isPPM = shipmentType === SHIPMENT_OPTIONS.PPM; @@ -80,14 +76,6 @@ const PrimeUIShipmentCreateForm = () => { return undefined; }; - useEffect(() => { - const fetchData = async () => { - setEnableBoat(await isBooleanFlagEnabled(FEATURE_FLAG_KEYS.BOAT)); - setEnableMobileHome(await isBooleanFlagEnabled(FEATURE_FLAG_KEYS.MOBILE_HOME)); - }; - fetchData(); - }, []); - let shipmentTypeOptions = Object.values(SHIPMENT_TYPES).map((value) => ({ key: value, value })); if (!enableBoat) { // Disallow the Prime from choosing Boat shipments if the feature flag is not enabled @@ -463,7 +451,7 @@ const PrimeUIShipmentCreateForm = () => { name="hasSecondaryPickupAddress" value="false" title="No, there is not a second pickup address" - checked={hasSecondaryPickupAddress !== 'true'} + checked={hasSecondaryPickupAddress !== 'true' && hasTertiaryPickupAddress !== 'true'} />
@@ -565,7 +553,7 @@ const PrimeUIShipmentCreateForm = () => { name="hasSecondaryDestinationAddress" value="false" title="No, there is not a second delivery address" - checked={hasSecondaryDestinationAddress !== 'true'} + checked={hasSecondaryDestinationAddress !== 'true' && hasTertiaryDestinationAddress !== 'true'} /> diff --git a/src/shared/utils.js b/src/shared/utils.js index ac6baa1307b..12ccf91c7a8 100644 --- a/src/shared/utils.js +++ b/src/shared/utils.js @@ -171,3 +171,41 @@ export function isEmpty(obj) { export function isNullUndefinedOrWhitespace(value) { return value == null || value === undefined || value.trim() === ''; } + +export function checkAddressTogglesToClearAddresses(body) { + let values = body; + + if (values.shipmentType === 'PPM') { + if (values.ppmShipment.hasSecondaryPickupAddress !== 'true') { + values.ppmShipment.secondaryPickupAddress = {}; + values.ppmShipment.tertiaryPickupAddress = {}; + } + if (values.ppmShipment.hasTertiaryPickupAddress !== 'true') { + values.ppmShipment.tertiaryPickupAddress = {}; + } + if (values.ppmShipment.hasSecondaryDestinationAddress !== 'true') { + values.ppmShipment.secondaryDestinationAddress = {}; + values.ppmShipment.tertiaryDestinationAddress = {}; + } + if (values.ppmShipment.hasTertiaryDestinationAddress !== 'true') { + values.ppmShipment.tertiaryDestinationAddress = {}; + } + } else { + if (values.hasSecondaryPickupAddress !== 'true') { + values.secondaryPickupAddress = {}; + values.tertiaryPickupAddress = {}; + } + if (values.hasTertiaryPickupAddress !== 'true') { + values.tertiaryPickupAddress = {}; + } + if (values.hasSecondaryDestinationAddress !== 'true') { + values.secondaryDestinationAddress = {}; + values.tertiaryDestinationAddress = {}; + } + if (values.hasTertiaryDestinationAddress !== 'true') { + values.tertiaryDestinationAddress = {}; + } + } + + return values; +} diff --git a/src/shared/utils.test.js b/src/shared/utils.test.js index eb5ea3e0160..dfc7cfcd956 100644 --- a/src/shared/utils.test.js +++ b/src/shared/utils.test.js @@ -86,4 +86,59 @@ describe('utils', () => { }); }); }); + + it('check if 2nd and 3rd addresses should be cleared from prime shipment create payload', () => { + const ppmValues = { + shipmentType: 'PPM', + ppmShipment: { + hasSecondaryPickupAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryDestinationAddress: 'false', + secondaryPickupAddress: '', + tertiaryPickupAddress: '', + secondaryDestinationAddress: '', + tertiaryDestinationAddress: '', + }, + }; + const hhgValues = { + shipmentType: 'HHG', + hasSecondaryPickupAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryDestinationAddress: 'false', + secondaryPickupAddress: '', + tertiaryPickupAddress: '', + secondaryDestinationAddress: '', + tertiaryDestinationAddress: '', + }; + + const updatedPPMValues = utils.checkAddressTogglesToClearAddresses(ppmValues); + expect(updatedPPMValues).toEqual({ + shipmentType: 'PPM', + ppmShipment: { + hasSecondaryPickupAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryDestinationAddress: 'false', + secondaryPickupAddress: {}, + tertiaryPickupAddress: {}, + secondaryDestinationAddress: {}, + tertiaryDestinationAddress: {}, + }, + }); + + const updatedHHGValues = utils.checkAddressTogglesToClearAddresses(hhgValues); + expect(updatedHHGValues).toEqual({ + shipmentType: 'HHG', + hasSecondaryPickupAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryDestinationAddress: 'false', + secondaryPickupAddress: {}, + tertiaryPickupAddress: {}, + secondaryDestinationAddress: {}, + tertiaryDestinationAddress: {}, + }); + }); });