Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-management into feat/metrics
  • Loading branch information
kb019 committed Aug 29, 2024
2 parents dd661e0 + f99530d commit c870aba
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,22 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
)
.refine(
(formValues) => {
const appointmentDate = formValues.appointmentDateTime?.startDate;
const dateAppointmentScheduled = formValues.dateAppointmentScheduled;
const { appointmentDateTime, dateAppointmentScheduled } = formValues;

if (!appointmentDate || !dateAppointmentScheduled) return true;
return dateAppointmentScheduled < appointmentDate;
const startDate = appointmentDateTime?.startDate;

if (!startDate || !dateAppointmentScheduled) return true;

const normalizeDate = (date: Date) => {
const normalizedDate = new Date(date);
normalizedDate.setHours(0, 0, 0, 0);
return normalizedDate;
};

const startDateObj = normalizeDate(startDate);
const scheduledDateObj = normalizeDate(dateAppointmentScheduled);

return scheduledDateObj <= startDateObj;
},
{
path: ['dateAppointmentScheduled'],
Expand All @@ -195,6 +206,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
),
},
);

type AppointmentFormData = z.infer<typeof appointmentsFormSchema>;

const defaultDateAppointmentScheduled = appointment?.dateAppointmentScheduled
Expand Down
2 changes: 2 additions & 0 deletions packages/esm-appointments-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"createNewAppointment": "Create new appointment",
"date": "Date",
"date&Time": "Date & time",
"dateAppointmentIssuedCannotBeAfterAppointmentDate": "Date appointment issued cannot be after the appointment date",
"dateOfBirth": "Date of birth",
"dateScheduled": "Date appointment issued",
"dateScheduledDetail": "Date appointment issued",
Expand Down Expand Up @@ -124,6 +125,7 @@
"providers": "Providers",
"providersBooked": "Providers booked: {{time}}",
"recurringAppointment": "Recurring Appointment",
"recurringAppointmentShouldHaveEndDate": "A recurring appointment should have an end date",
"repeatEvery": "Repeat every",
"save": "Save",
"saveAndClose": "Save and close",
Expand Down
5 changes: 1 addition & 4 deletions packages/esm-patient-registration-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ export const editPatient = getSyncLifecycle(rootComponent, {

export const addPatientLink = getSyncLifecycle(addPatientLinkComponent, options);

export const cancelPatientEditModal = getAsyncLifecycle(
() => import('./widgets/cancel-patient-edit.component'),
options,
);
export const cancelPatientEditModal = getAsyncLifecycle(() => import('./widgets/cancel-patient-edit.modal'), options);

export const patientPhotoExtension = getSyncLifecycle(PatientPhotoExtension, options);

Expand Down
12 changes: 6 additions & 6 deletions packages/esm-patient-registration-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
"online": true,
"offline": true
},
{
"component": "cancelPatientEditModal",
"name": "cancel-patient-edit-modal",
"online": true,
"offline": true
},
{
"component": "patientPhotoExtension",
"name": "patient-photo-widget",
Expand Down Expand Up @@ -58,5 +52,11 @@
"online": true,
"offline": true
}
],
"modals": [
{
"name": "cancel-patient-edit-modal",
"component": "cancelPatientEditModal"
}
]
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Button, ModalBody, ModalFooter, ModalHeader } from '@carbon/react';

interface CancelPatientEditPropsModal {
close(): void;
onConfirm(): void;
}

const CancelPatientEditModal: React.FC<CancelPatientEditPropsModal> = ({ close, onConfirm }) => {
const { t } = useTranslation();
return (
<>
<ModalHeader
closeModal={close}
title={t('confirmDiscardChangesTitle', 'Are you sure you want to discard these changes?')}
/>
<ModalBody>
<p>{t('confirmDiscardChangesBody', 'Your unsaved changes will be lost if you proceed to discard the form')}.</p>
</ModalBody>
<ModalFooter>
<Button kind="secondary" onClick={close}>
{t('cancel', 'Cancel')}
</Button>
<Button kind="danger" onClick={onConfirm}>
{t('discard', 'Discard')}
</Button>
</ModalFooter>
</>
);
};

export default CancelPatientEditModal;
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from 'react';
import userEvent from '@testing-library/user-event';
import { screen, render } from '@testing-library/react';
import CancelPatientEdit from './cancel-patient-edit.component';
import CancelPatientEdit from './cancel-patient-edit.modal';

describe('CancelPatientEdit component', () => {
describe('CancelPatientEdit modal', () => {
const mockClose = jest.fn();
const mockOnConfirm = jest.fn();

it('renders the modal and triggers close and onConfirm functions', async () => {
const user = userEvent.setup();

render(<CancelPatientEdit close={mockClose} onConfirm={mockOnConfirm} />);

const cancelButton = screen.getByRole('button', { name: /Cancel/i });
Expand Down
4 changes: 2 additions & 2 deletions packages/esm-patient-registration-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"codedPersonAttributeNoAnswerSet": "The person attribute field '{{codedPersonAttributeFieldId}}' is of type 'coded' but has been defined without an answer concept set UUID. The 'answerConceptSetUuid' key is required.",
"configure": "Configure",
"configureIdentifiers": "Configure identifiers",
"confirmDiscardChangesBody": "Your unsaved changes will be lost if you proceed to discard the form",
"confirmDiscardChangesTitle": "Are you sure you want to discard these changes?",
"confirmIdentifierDeletionText": "Are you sure you want to remove this identifier?",
"contactSection": "Contact Details",
"createNewPatient": "Create new patient",
Expand All @@ -27,8 +29,6 @@
"deleteRelationshipTooltipText": "Delete",
"demographicsSection": "Basic Info",
"discard": "Discard",
"discardModalBody": "The changes you made to this patient's details have not been saved. Discard changes?",
"discardModalHeader": "Confirm Discard Changes",
"dobToggleLabelText": "Date of Birth Known?",
"editIdentifierTooltip": "Edit",
"editPatientDetails": "Edit patient details",
Expand Down

0 comments on commit c870aba

Please sign in to comment.