diff --git a/web/gds-user-ui/src/components/AddressForm/index.tsx b/web/gds-user-ui/src/components/AddressForm/index.tsx index 5d4525197..5ca57a308 100644 --- a/web/gds-user-ui/src/components/AddressForm/index.tsx +++ b/web/gds-user-ui/src/components/AddressForm/index.tsx @@ -2,7 +2,7 @@ import React, { useEffect } from 'react'; import { Grid, GridItem, VStack } from '@chakra-ui/react'; import InputFormControl from 'components/ui/InputFormControl'; import SelectFormControl from 'components/ui/SelectFormControl'; -import { addressTypeOptions } from 'constants/address'; +import { addressTypeEnum, addressTypeOptions } from 'constants/address'; import { getCountriesOptions } from 'constants/countries'; import { Controller, useFormContext } from 'react-hook-form'; import { getValueByPathname } from 'utils/utils'; @@ -28,7 +28,7 @@ const AddressForm: React.FC = ({ name, rowIndex }) => { useEffect(() => { if (!getFirstAddressType) { - setValue(`entity.geographic_addresses[0].address_type`, 'ADDRESS_TYPE_CODE_BIZZ'); + setValue(`entity.geographic_addresses[0].address_type`, addressTypeEnum.ADDRESS_TYPE_BIZZ); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [getFirstAddressType]); @@ -109,7 +109,7 @@ const AddressForm: React.FC = ({ name, rowIndex }) => { option.value === field.value)} onChange={(newValue: any) => field.onChange(newValue.value)} diff --git a/web/gds-user-ui/src/components/Addresses/AddressList.tsx b/web/gds-user-ui/src/components/Addresses/AddressList.tsx index 5942c6d6a..5af2e8cad 100644 --- a/web/gds-user-ui/src/components/Addresses/AddressList.tsx +++ b/web/gds-user-ui/src/components/Addresses/AddressList.tsx @@ -2,6 +2,7 @@ import { VStack, Box, Button } from '@chakra-ui/react'; import { Trans } from '@lingui/react'; import { useFormContext, useFieldArray } from 'react-hook-form'; import Address from './Address'; +import { addressTypeEnum } from 'constants/address'; function AddressList() { const { control } = useFormContext(); @@ -12,10 +13,9 @@ function AddressList() { const handleAddressClick = () => { append({ - /* Set the default address type value for additional any addresses - to match the default address type provided by backend. */ - /* Add constant for address type that matches the backend. */ - address_type: 'ADDRESS_TYPE_CODE_BIZZ', + /* Set the default address type value for any additional addresses + to match the default address type provided by the backend. */ + address_type: addressTypeEnum.ADDRESS_TYPE_BIZZ, address_line: ['', '', ''], country: '' }); diff --git a/web/gds-user-ui/src/constants/address.ts b/web/gds-user-ui/src/constants/address.ts index ca7ebcd9d..a9db50a81 100644 --- a/web/gds-user-ui/src/constants/address.ts +++ b/web/gds-user-ui/src/constants/address.ts @@ -1,5 +1,6 @@ import { t } from '@lingui/macro'; +// Use address type where users will be instructed to select a type (ie. address form component). export const addressType = { ADDRESS_TYPE_CODE_MISC: t`Unspecified`, ADDRESS_TYPE_CODE_HOME: t`Residential`, @@ -7,6 +8,15 @@ export const addressType = { ADDRESS_TYPE_CODE_GEOG: t`Geographic` }; +// Use addressTypeEnum when the address type code is required when sending data to the backend. +export const addressTypeEnum = { + ADDRESS_TYPE_MISC: 'ADDRESS_TYPE_CODE_MISC', + ADDRESS_TYPE_HOME: 'ADDRESS_TYPE_CODE_HOME', + ADDRESS_TYPE_BIZZ: 'ADDRESS_TYPE_CODE_BIZZ', + ADDRESS_TYPE_GEOG: 'ADDRESS_TYPE_CODE_GEOG' +}; + +// The addressTypeOptions is used to generate the options for the address type select form control. export const addressTypeOptions = () => { return Object.entries(addressType).map(([k, v]) => ({ value: k, label: v })); }; diff --git a/web/gds-user-ui/src/modules/dashboard/certificate/lib/defaultValues.ts b/web/gds-user-ui/src/modules/dashboard/certificate/lib/defaultValues.ts index a93c4a71b..a20af4347 100644 --- a/web/gds-user-ui/src/modules/dashboard/certificate/lib/defaultValues.ts +++ b/web/gds-user-ui/src/modules/dashboard/certificate/lib/defaultValues.ts @@ -1,3 +1,5 @@ +import { addressTypeEnum } from "constants/address"; + export const getRegistrationDefaultValues = () => { return { entity: { @@ -14,7 +16,7 @@ export const getRegistrationDefaultValues = () => { }, geographic_addresses: [ { - address_type: 'ADDRESS_TYPE_CODE_BIZZ', + address_type: addressTypeEnum.ADDRESS_TYPE_BIZZ, address_line: [], country: '' }