src/applications/vaos/components/layouts/VideoLayoutVA.jsx
import React from 'react';
import PropTypes from 'prop-types';
import { shallowEqual } from 'recompose';
import { useSelector } from 'react-redux';
import { getRealFacilityId } from '../../utils/appointment';
import DetailPageLayout, {
What,
When,
Who,
ClinicOrFacilityPhone,
Prepare,
} from './DetailPageLayout';
import Section from '../Section';
import { APPOINTMENT_STATUS } from '../../utils/constants';
import { selectConfirmedAppointmentData } from '../../appointment-list/redux/selectors';
import {
AppointmentDate,
AppointmentTime,
} from '../../appointment-list/components/AppointmentDateTime';
import AddToCalendarButton from '../AddToCalendarButton';
import NewTabAnchor from '../NewTabAnchor';
import Address from '../Address';
import FacilityDirectionsLink from '../FacilityDirectionsLink';
import {
NULL_STATE_FIELD,
recordAppointmentDetailsNullStates,
} from '../../utils/events';
export default function VideoLayoutVA({ data: appointment }) {
const {
clinicName,
clinicPhysicalLocation,
clinicPhone,
clinicPhoneExtension,
facility,
facilityPhone,
locationId,
isPastAppointment,
startDate,
status,
typeOfCareName,
videoProviderName,
} = useSelector(
state => selectConfirmedAppointmentData(state, appointment),
shallowEqual,
);
let heading = 'Video appointment at a VA location';
const facilityId = locationId;
if (isPastAppointment) heading = 'Past video appointment at VA location';
else if (APPOINTMENT_STATUS.cancelled === status)
heading = 'Canceled video appointment at VA location';
recordAppointmentDetailsNullStates({
[NULL_STATE_FIELD.TYPE_OF_CARE]: !typeOfCareName,
});
return (
<DetailPageLayout heading={heading} data={appointment}>
{APPOINTMENT_STATUS.booked === status &&
!isPastAppointment && (
<Section heading="How to join">
Join this video appointment at a VA facility.
<br />
</Section>
)}
<When>
<AppointmentDate date={startDate} />
<br />
<AppointmentTime appointment={appointment} />
<br />
{APPOINTMENT_STATUS.cancelled !== status &&
!isPastAppointment && (
<div className="vads-u-margin-top--2 vaos-hide-for-print">
<AddToCalendarButton
appointment={appointment}
facility={facility}
/>
</div>
)}
</When>
<What>{typeOfCareName}</What>
<Who>{videoProviderName}</Who>
<Section heading="Where to attend">
{/* When the services return a null value for the facility (no facility ID) for all appointment types */}
{!facility &&
!facilityId && (
<>
<span>Facility details not available</span>
<br />
<NewTabAnchor href="/find-locations">
Find facility information
</NewTabAnchor>
<br />
<br />
</>
)}
{/* When the services return a null value for the facility (but receive the facility ID) */}
{!facility &&
!!facilityId && (
<>
<span>Facility details not available</span>
<br />
<NewTabAnchor
href={`/find-locations/facility/vha_${getRealFacilityId(
facilityId,
)}`}
>
View facility information
</NewTabAnchor>
<br />
</>
)}
{!!facility && (
<>
<a href={facility.website}>{facility.name}</a>
<br />
<Address address={facility?.address} />
<div className="vads-u-margin-top--1 vads-u-color--link-default">
<FacilityDirectionsLink location={facility} icon />
</div>
<br />
<span>Clinic: {clinicName || 'Not available'}</span> <br />
<span>Location: {clinicPhysicalLocation || 'Not available'}</span>
<br />
</>
)}
<ClinicOrFacilityPhone
clinicPhone={clinicPhone}
clinicPhoneExtension={clinicPhoneExtension}
facilityPhone={facilityPhone}
/>
</Section>
{!isPastAppointment &&
(APPOINTMENT_STATUS.booked === status ||
APPOINTMENT_STATUS.cancelled === status) && (
<Prepare>
<p className="vads-u-margin-top--0 vads-u-margin-bottom--0">
Bring your insurance cards. And bring a list of your medications
and other information to share with your provider.
</p>
<p className="vads-u-margin-top--0 vads-u-margin-bottom--0">
<va-link
text="Find a full list of things to bring to your appointment"
href="https://www.va.gov/resources/what-should-i-bring-to-my-health-care-appointments/"
/>
</p>
</Prepare>
)}
{APPOINTMENT_STATUS.booked === status &&
!isPastAppointment && (
<Section heading="Need to make changes?">
Contact this facility if you need to reschedule or cancel your
appointment.
</Section>
)}
</DetailPageLayout>
);
}
VideoLayoutVA.propTypes = {
data: PropTypes.object,
};