Skip to content

Commit

Permalink
Iir 727 facility locator migration (#30199)
Browse files Browse the repository at this point in the history
  • Loading branch information
khenson-oddball authored Jun 11, 2024
1 parent e7804c5 commit 4c9d6c6
Show file tree
Hide file tree
Showing 21 changed files with 302 additions and 675 deletions.
66 changes: 48 additions & 18 deletions src/applications/facility-locator/api/LocatorApi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getAPI, resolveParamsWithUrl } from '../config';
import { fetchAndUpdateSessionExpiration as fetch } from 'platform/utilities/api';
import { getAPI, resolveParamsWithUrl } from '../config';
import manifest from '../manifest.json';

class LocatorApi {
/**
Expand All @@ -26,7 +27,7 @@ class LocatorApi {
allUrgentCare,
) {
const reduxStore = require('../facility-locator-entry');
const { params, url } = resolveParamsWithUrl({
const { params, url, postParams } = resolveParamsWithUrl({
address,
locationType,
serviceType,
Expand All @@ -41,23 +42,52 @@ class LocatorApi {
const api = getAPI();
const startTime = new Date().getTime();
return new Promise((resolve, reject) => {
fetch(`${url}?${params}`, api.settings)
.then(response => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.json();
if (url.slice(-3) === '/va') {
fetch(`${url}`, {
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'X-Key-Inflection': 'camel',
'Source-App-Name': manifest.entryName,
},
method: 'POST',
body: JSON.stringify(postParams),
})
.then(res => {
const endTime = new Date().getTime();
const resultTime = endTime - startTime;
res.meta = {
...res.meta,
resultTime,
};
return res;
})
.then(data => resolve(data), error => reject(error));
.then(response => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.json();
})
.then(res => {
const endTime = new Date().getTime();
const resultTime = endTime - startTime;
res.meta = {
...res.meta,
resultTime,
};
return res;
})
.then(data => resolve(data), error => reject(error));
} else {
fetch(`${url}?${params}`, api.settings)
.then(response => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.json();
})
.then(res => {
const endTime = new Date().getTime();
const resultTime = endTime - startTime;
res.meta = {
...res.meta,
resultTime,
};
return res;
})
.then(data => resolve(data), error => reject(error));
}
});
}

Expand Down
14 changes: 1 addition & 13 deletions src/applications/facility-locator/components/ResultsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ export const ResultsList = ({
const renderResultItems = (searchQuery, apiResults) => {
return apiResults.map((result, index) => {
let item;
const services = result?.attributes?.detailedServices;
const walkInsAccepted = Array.isArray(services)
? services[0]?.walkInsAccepted
: 'false';

const showHealthConnectNumber = isHealthAndHealthConnect(result, query);

switch (searchQuery.facilityType) {
Expand All @@ -83,14 +78,7 @@ export const ResultsList = ({
case 'vet_center':
item =
searchQuery.serviceType === Covid19Vaccine ? (
<Covid19Result
location={result}
key={result.id}
index={index}
showCovidVaccineWalkInAvailabilityText={
(walkInsAccepted || '').toLowerCase() === 'true'
}
/>
<Covid19Result location={result} key={result.id} index={index} />
) : (
<VaFacilityResult
location={result}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,9 @@ class ServicesAtFacility extends Component {
return null;
}

/**
* Since moving to v1 the services object changed. For now,
* supporting v0 as the implementation is still on flipper.
*
* v0 - services.benefits.standard
* v1 - services.benefits
*/
return (
<div className="vads-u-margin-bottom--4">
<ul>
{(services.benefits.standard &&
services.benefits.standard.map(s => this.renderService(s))) ||
services.benefits.map(s => this.renderService(s))}
</ul>
<ul>{services.benefits.map(s => this.renderService(s.name))}</ul>
</div>
);
}
Expand Down Expand Up @@ -116,7 +105,9 @@ class ServicesAtFacility extends Component {
<ul>
{services.health.map(
s =>
s.sl1 ? this.renderService(s.sl1[0]) : this.renderService(s),
s.sl1
? this.renderService(s.sl1[0])
: this.renderService(s.name),
)}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import LocationOperationStatus from './common/LocationOperationStatus';
import LocationDistance from './common/LocationDistance';
import CovidPhoneLink from './common/Covid19PhoneLink';

const Covid19Result = ({
location,
index,
showCovidVaccineWalkInAvailabilityText,
}) => {
const Covid19Result = ({ location, index }) => {
const {
name,
website,
Expand Down Expand Up @@ -60,17 +56,9 @@ const Covid19Result = ({
)}
<LocationAddress location={location} />
<LocationDirectionsLink location={location} from="SearchResult" />
{showCovidVaccineWalkInAvailabilityText && (
<strong className="vads-u-margin-bottom--2 vads-u-display--block">
Walk-ins accepted
</strong>
)}
{appointmentPhone ? (
<CovidPhoneLink
phone={appointmentPhone}
showCovidVaccineWalkInAvailabilityText={
showCovidVaccineWalkInAvailabilityText
}
labelId={`${location.id}-phoneLabel`}
/>
) : (
Expand Down Expand Up @@ -104,7 +92,6 @@ Covid19Result.propTypes = {
location: PropTypes.object,
query: PropTypes.object,
index: PropTypes.number,
showCovidVaccineWalkInAvailabilityText: PropTypes.bool,
};

export default Covid19Result;
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const VaFacilityResult = ({
},
[index, location],
);

return (
<div className="facility-result" id={location.id} key={location.id}>
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import React from 'react';
import { parsePhoneNumber } from '../../../utils/phoneNumbers';

const Covid19PhoneLink = ({
phone,
showCovidVaccineWalkInAvailabilityText,
labelId,
}) => {
const Covid19PhoneLink = ({ phone, labelId }) => {
if (!phone) {
return null;
}
Expand All @@ -18,11 +14,7 @@ const Covid19PhoneLink = ({

const { extension: parsedExtension, contact } = parsePhoneNumber(number);

let labelText = 'Call to schedule';

if (showCovidVaccineWalkInAvailabilityText) {
labelText = 'Or make an appointment';
}
const labelText = 'Call to schedule';

return (
<div>
Expand Down
39 changes: 36 additions & 3 deletions src/applications/facility-locator/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const apiSettings = {
};

const railsEngineApi = {
baseUrl: `${environment.API_URL}/facilities_api/v1`,
url: `${environment.API_URL}/facilities_api/v1/va`,
ccUrl: `${environment.API_URL}/facilities_api/v1/ccp`,
baseUrl: `${environment.API_URL}/facilities_api/v2`,
url: `${environment.API_URL}/facilities_api/v2/va`,
ccUrl: `${environment.API_URL}/facilities_api/v2/ccp`,
settings: apiSettings,
};

Expand Down Expand Up @@ -134,6 +134,36 @@ export const resolveParamsWithUrl = ({
];
}

const postLocationParams = {};
locationParams.forEach(param => {
if (param === null) return;
const arr = param.split('=');

if (arr[0] === 'bbox[]') {
if (!('bbox' in postLocationParams)) {
postLocationParams.bbox = [];
}
postLocationParams.bbox.push(param.split('=')[1]);
} else {
postLocationParams[arr[0]] = arr[1];
}
});

const postParamsObj = {
type: facility && !communityServiceType ? facility : null,
services:
filterableLocations.includes(facility) && service ? [service] : null,
page,
// eslint-disable-next-line camelcase
per_page: perPage,
mobile:
facility === LocationType.VET_CENTER || facility === LocationType.HEALTH
? false
: null,
radius: roundRadius || null,
...postLocationParams,
};

return {
url,
params: compact([
Expand All @@ -148,6 +178,9 @@ export const resolveParamsWithUrl = ({
roundRadius ? `radius=${roundRadius}` : null,
...locationParams,
]).join('&'),
postParams: Object.fromEntries(
Object.entries(postParamsObj).filter(([_, v]) => v != null),
),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import LocationHours from '../components/LocationHours';
import LocationMap from '../components/LocationMap';
import LocationPhoneLink from '../components/search-results-items/common/LocationPhoneLink';
import ServicesAtFacility from '../components/ServicesAtFacility';
import AppointmentInfo from '../components/AppointmentInfo';
import { FacilityType } from '../constants';
import VABenefitsCall from '../components/VABenefitsCall';
import { facilityLocatorShowOperationalHoursSpecialInstructions } from '../utils/featureFlagSelectors';
Expand Down Expand Up @@ -120,7 +119,6 @@ class FacilityDetail extends Component {
<ServicesAtFacility facility={facility} />
</div>
<div>
<AppointmentInfo location={facility} />
<AccessToCare location={facility} />
</div>
</div>
Expand Down
Loading

0 comments on commit 4c9d6c6

Please sign in to comment.