Skip to content

Commit

Permalink
(fix): O3-4085 show dialog to user before discarding new appointment …
Browse files Browse the repository at this point in the history
…changes
  • Loading branch information
amosmachora committed Oct 15, 2024
1 parent 210df65 commit 05893ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ moduleName

# vim
.swp

# vscode
.vscode
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import React, { useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import dayjs from 'dayjs';
import {
Button,
ButtonSet,
Expand All @@ -20,9 +17,7 @@ import {
TimePickerSelect,
Toggle,
} from '@carbon/react';
import { Controller, useController, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import {
ExtensionSlot,
ResponsiveWrapper,
Expand All @@ -33,17 +28,14 @@ import {
useLocations,
usePatient,
useSession,
type DefaultWorkspaceProps,
type FetchResponse,
} from '@openmrs/esm-framework';
import {
checkAppointmentConflict,
saveAppointment,
saveRecurringAppointments,
useAppointmentService,
useMutateAppointments,
} from './appointments-form.resource';
import { useProviders } from '../hooks/useProviders';
import type { Appointment, AppointmentPayload, RecurringPattern } from '../types';
import dayjs from 'dayjs';
import React, { useContext, useEffect, useState } from 'react';
import { Controller, useController, useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { z } from 'zod';
import { type ConfigObject } from '../config-schema';
import {
appointmentLocationTagName,
Expand All @@ -54,7 +46,16 @@ import {
weekDays,
} from '../constants';
import SelectedDateContext from '../hooks/selectedDateContext';
import { useProviders } from '../hooks/useProviders';
import type { Appointment, AppointmentPayload, RecurringPattern } from '../types';
import Workload from '../workload/workload.component';
import {
checkAppointmentConflict,
saveAppointment,
saveRecurringAppointments,
useAppointmentService,
useMutateAppointments,
} from './appointments-form.resource';
import styles from './appointments-form.scss';

const time12HourFormatRegexPattern = '^(1[0-2]|0?[1-9]):[0-5][0-9]$';
Expand All @@ -68,15 +69,15 @@ interface AppointmentsFormProps {
recurringPattern?: RecurringPattern;
patientUuid?: string;
context: string;
closeWorkspace: () => void;
}

const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
const AppointmentsForm: React.FC<AppointmentsFormProps & DefaultWorkspaceProps> = ({
appointment,
recurringPattern,
patientUuid,
context,
closeWorkspace,
promptBeforeClosing,
}) => {
const { patient } = usePatient(patientUuid);
const { mutateAppointments } = useMutateAppointments();
Expand Down Expand Up @@ -219,7 +220,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
setValue,
watch,
handleSubmit,
formState: { errors },
formState: { isDirty },
} = useForm<AppointmentFormData>({
mode: 'all',
resolver: zodResolver(appointmentsFormSchema),
Expand Down Expand Up @@ -268,6 +269,10 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
endDateRef(endDateElement);
}, [startDateRef, endDateRef]);

useEffect(() => {
promptBeforeClosing(() => isDirty);
}, [isDirty, promptBeforeClosing]);

const handleWorkloadDateChange = (date: Date) => {
const appointmentDate = getValues('appointmentDateTime');
setValue('appointmentDateTime', { ...appointmentDate, startDate: date });
Expand Down

0 comments on commit 05893ed

Please sign in to comment.