Skip to content

Commit

Permalink
(feat) O3-3866: Allow customized message/dialog for warning when clos… (
Browse files Browse the repository at this point in the history
  • Loading branch information
mogoodrich authored Sep 5, 2024
1 parent 2f0fffe commit 795ee01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@openmrs/esm-patient-common-lib';
import HtmlFormEntryWrapper from './html-form-entry-wrapper.component';
import { usePatient } from '@openmrs/esm-framework';
import { useTranslation } from 'react-i18next';

interface HtmlFormEntryComponentProps extends DefaultPatientWorkspaceProps {
formInfo: FormEntryProps;
Expand All @@ -15,15 +16,24 @@ const HtmlFormEntry: React.FC<HtmlFormEntryComponentProps> = ({
patientUuid,
closeWorkspaceWithSavedChanges,
promptBeforeClosing,
setCancelTitle,
setCancelMessage,
setCancelConfirmText,
formInfo,
}) => {
const { t } = useTranslation();
const { patient } = usePatient(patientUuid);
const { currentVisit } = useVisitOrOfflineVisit(patientUuid);
const { encounterUuid, visitUuid, htmlForm } = formInfo || {};

// we always want to prompt the user before closing/hiding the workspace because we can't guarantee maintaining the state of the form
promptBeforeClosing(() => true);

// custom messaging to display to a user when closing the workspace without using the buttons within the form
setCancelTitle(t('warning', 'Warning'));
setCancelMessage(t('closeHtmlFormWarning', 'Please use the Save or Cancel button on the form to close the form.'));
setCancelConfirmText(t('ignoreWarning', 'Ignore Warning'));

// urls for entering a new form and editing an existing form; note that we specify the returnUrl as post-message:close-workspace,
// which tells HFE-UI to send a message to the parent window to close the workspace when the form is saved or cancelled
const url = `${window.openmrsBase}/htmlformentryui/htmlform/${
Expand Down
5 changes: 4 additions & 1 deletion packages/esm-patient-forms-app/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"clinicalForm": "Clinical Form",
"clinicalForms": "Clinical forms",
"closeHtmlFormWarning": "Please use the Save or Cancel button on the {{title}} form to close the form.",
"editForm": "Edit form",
"formName": "Form Name (A-Z)",
"forms": "Forms",
"formSearchHint": "Try searching for the form using an alternative name or keyword",
"homeOverviewCardView": "View",
"ignoreWarning": "Ignore Warning",
"lastCompleted": "Last completed",
"never": "Never",
"noFormsToDisplay": "There are no forms to display.",
Expand All @@ -21,5 +23,6 @@
"offlinePatientsTableSearchPlaceholder": "Search this list",
"offlineToggle": "Offline toggle",
"searchForAForm": "Search for a form",
"searchThisList": "Search this list"
"searchThisList": "Search this list",
"warning": "Warning"
}

0 comments on commit 795ee01

Please sign in to comment.