Skip to content

Commit

Permalink
(fix) O3-3154: Patient Appointments Card does not properly set defaul…
Browse files Browse the repository at this point in the history
…t appointment selection (#1127)
  • Loading branch information
mogoodrich authored May 8, 2024
1 parent b402b04 commit ea6f319
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,18 @@ const PatientUpcomingAppointmentsCard: React.FC<PatientUpcomingAppointmentsProps
.concat(futureAppointments)
.filter((appointment) => appointment.status !== 'CheckedIn');

// If there is only one appointment, select it by default
if (appointments?.length === 1) {
setUpcomingAppointment(appointments[0]);
const defaultAppointment = ((appointments) => {
// if there's only one appointment today, select it by default, otherwise no default
const appts = appointments?.filter((appointment) =>
dayjs(new Date(appointment.startDateTime).toISOString()).isToday(),
);
if (appts?.length === 1) {
return appts[0];
}
})(appointments);

if (defaultAppointment) {
setUpcomingAppointment(defaultAppointment);
}

if (isError) {
Expand All @@ -69,7 +78,7 @@ const PatientUpcomingAppointmentsCard: React.FC<PatientUpcomingAppointmentsProps
className={styles.checkbox}
key={i}
labelText=""
defaultChecked={dayjs(new Date(appointment.startDateTime).toISOString()).isToday()}
defaultChecked={appointment.uuid === defaultAppointment?.uuid}
id={appointment.uuid}
onChange={(e) => (e.target.checked ? setUpcomingAppointment(appointment) : '')}
/>
Expand Down Expand Up @@ -100,6 +109,7 @@ const PatientUpcomingAppointmentsCard: React.FC<PatientUpcomingAppointmentsProps
</div>
);
}

return (
<InlineNotification
kind={'info'}
Expand Down

0 comments on commit ea6f319

Please sign in to comment.