Skip to content

Commit

Permalink
update how we format addresses to not include comma on end of state (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
coope93 authored Dec 31, 2024
1 parent 909de0f commit 75a20fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
28 changes: 13 additions & 15 deletions src/applications/caregivers/actions/fetchFacilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@ import environment from 'platform/utilities/environment';
import { apiRequest } from 'platform/utilities/api';
import content from '../locales/en/content.json';

const joinAddressParts = (...parts) => {
return parts.filter(part => part != null).join(', ');
const formatAddress = address => {
const joinAddressParts = (...parts) => {
const [city, state, zip] = parts;
const stateZip = state && zip ? `${state} ${zip}` : state || zip;
return [city, stateZip].filter(Boolean).join(', ');
};

return {
address1: address.address1,
address2: [address?.address2, address?.address3].filter(Boolean).join(', '),
address3: joinAddressParts(address?.city, address?.state, address?.zip),
};
};

const formatQueryParams = ({
Expand Down Expand Up @@ -75,25 +85,13 @@ export const fetchFacilities = async ({
}
const facilities = response.data.map(facility => {
const attributes = facility?.attributes;
const { physical } = attributes?.address;

// Create a new address object without modifying the original facility
const newPhysicalAddress = {
address1: physical.address1,
address2: joinAddressParts(physical?.address2, physical?.address3),
address3: joinAddressParts(
physical.city,
physical.state,
physical.zip,
),
};

// Return a new facility object with the updated address
return {
...attributes,
id: facility.id,
address: {
physical: newPhysicalAddress,
physical: formatAddress(attributes?.address.physical),
},
};
});
Expand Down
6 changes: 3 additions & 3 deletions src/applications/caregivers/tests/mocks/responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ const fetchChildFacilityWithoutCaregiverSupport = {
physical: {
address1: '2720 Airport Drive',
address2: 'Suite 100',
address3: 'Columbus, OH, 43219-2219',
address3: 'Columbus, OH 43219-2219',
},
},
classification: 'Other Outpatient Services (OOS)',
Expand Down Expand Up @@ -514,7 +514,7 @@ const fetchChildFacilityWithCaregiverSupport = {
physical: {
address1: '2720 Airport Drive',
address2: 'Suite 100',
address3: 'Columbus, OH, 43219-2219',
address3: 'Columbus, OH 43219-2219',
},
},
classification: 'Other Outpatient Services (OOS)',
Expand Down Expand Up @@ -580,7 +580,7 @@ const fetchParentFacility = {
physical: {
address1: '420 North James Road',
address2: '33',
address3: 'Columbus, OH, 43219-1834',
address3: 'Columbus, OH 43219-1834',
},
},
classification: 'Health Care Center (HCC)',
Expand Down

0 comments on commit 75a20fa

Please sign in to comment.