Skip to content

Commit

Permalink
Add constant for address type codes and & update strings with constan…
Browse files Browse the repository at this point in the history
…ts (#1160)
  • Loading branch information
daniellemaxwell authored Feb 21, 2024
1 parent 7bc6fda commit 51cc7db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions web/gds-user-ui/src/components/AddressForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -28,7 +28,7 @@ const AddressForm: React.FC<AddressFormProps> = ({ 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]);
Expand Down Expand Up @@ -109,7 +109,7 @@ const AddressForm: React.FC<AddressFormProps> = ({ name, rowIndex }) => {
<SelectFormControl
name={field.name}
ref={field.ref}
defaultValue="ADDRESS_TYPE_CODE_BIZZ"
defaultValue={addressTypeEnum.ADDRESS_TYPE_BIZZ}
isInvalid={!!getValueByPathname(errors, `${name}[${rowIndex}].address_type`)}
value={addressTypes.find((option) => option.value === field.value)}
onChange={(newValue: any) => field.onChange(newValue.value)}
Expand Down
8 changes: 4 additions & 4 deletions web/gds-user-ui/src/components/Addresses/AddressList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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: ''
});
Expand Down
10 changes: 10 additions & 0 deletions web/gds-user-ui/src/constants/address.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
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`,
ADDRESS_TYPE_CODE_BIZZ: t`Business`,
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 }));
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { addressTypeEnum } from "constants/address";

export const getRegistrationDefaultValues = () => {
return {
entity: {
Expand All @@ -14,7 +16,7 @@ export const getRegistrationDefaultValues = () => {
},
geographic_addresses: [
{
address_type: 'ADDRESS_TYPE_CODE_BIZZ',
address_type: addressTypeEnum.ADDRESS_TYPE_BIZZ,
address_line: [],
country: ''
}
Expand Down

0 comments on commit 51cc7db

Please sign in to comment.