Skip to content

Commit

Permalink
(refactor) Refactor registration form cancel modal to match conventio…
Browse files Browse the repository at this point in the history
…ns (#1294)

This PR refactors the registration form's cancel modal to match new modal naming and registration conventions. Modals
are now registered in the routes registry file under the `modals`. The naming convention has also changed - modals now use the `*.modal.tsx` suffix.
I've also amended the modal to use Carbon's ModalBody, ModalHeader, and ModalFooter components instead of using divs with
custom classes. Finally, I've amended the modal title and content to align with other confirmation modals in O3.
  • Loading branch information
denniskigen authored Aug 28, 2024
1 parent 0d8c01e commit f21abc4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 52 deletions.
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 f21abc4

Please sign in to comment.