From e60e80b294e20197205ac3bdb24503d3233a38e8 Mon Sep 17 00:00:00 2001 From: Twiine Enock Date: Tue, 3 Jun 2025 17:40:58 +0300 Subject: [PATCH 1/2] (feat): Enable external form Submission --- src/components/sidebar/sidebar.component.tsx | 52 +++++++------- src/form-engine.component.tsx | 12 +++- src/hooks/useExternalSubmitListener.ts | 34 +++++++++ src/hooks/usePostSubmissionCallback.ts | 74 ++++++++++++++++++++ src/provider/form-factory-provider.tsx | 4 ++ 5 files changed, 149 insertions(+), 27 deletions(-) create mode 100644 src/hooks/useExternalSubmitListener.ts create mode 100644 src/hooks/usePostSubmissionCallback.ts diff --git a/src/components/sidebar/sidebar.component.tsx b/src/components/sidebar/sidebar.component.tsx index 43452e8e..203dc9be 100644 --- a/src/components/sidebar/sidebar.component.tsx +++ b/src/components/sidebar/sidebar.component.tsx @@ -16,6 +16,7 @@ interface SidebarProps { onCancel: () => void; handleClose: () => void; hideFormCollapseToggle: () => void; + isSubmissionTriggeredExternally?: boolean; } const Sidebar: React.FC = ({ @@ -25,6 +26,7 @@ const Sidebar: React.FC = ({ onCancel, handleClose, hideFormCollapseToggle, + isSubmissionTriggeredExternally, }) => { const { t } = useTranslation(); const { pages, pagesWithErrors, activePages, evaluatedPagesVisibility } = usePageObserver(); @@ -53,32 +55,34 @@ const Sidebar: React.FC = ({ requestPage={requestPage} /> ))} - {sessionMode !== 'view' &&
} + {sessionMode !== 'view' && !isSubmissionTriggeredExternally &&
} -
- {sessionMode !== 'view' && ( - + )} + - )} - -
+ + )} ); }; diff --git a/src/form-engine.component.tsx b/src/form-engine.component.tsx index 3fbf0a1c..9079bdcf 100644 --- a/src/form-engine.component.tsx +++ b/src/form-engine.component.tsx @@ -19,6 +19,7 @@ import MarkdownWrapper from './components/inputs/markdown/markdown-wrapper.compo import PatientBanner from './components/patient-banner/patient-banner.component'; import Sidebar from './components/sidebar/sidebar.component'; import styles from './form-engine.scss'; +import { useExternalSubmitListener } from './hooks/useExternalSubmitListener'; interface FormEngineProps { patientUUID: string; @@ -33,6 +34,7 @@ interface FormEngineProps { handleClose?: () => void; handleConfirmQuestionDeletion?: (question: Readonly) => Promise; markFormAsDirty?: (isDirty: boolean) => void; + isSubmissionTriggeredExternally?: boolean; } const FormEngine = ({ @@ -48,6 +50,7 @@ const FormEngine = ({ handleClose, handleConfirmQuestionDeletion, markFormAsDirty, + isSubmissionTriggeredExternally = false, }: FormEngineProps) => { const { t } = useTranslation(); const session = useSession(); @@ -107,11 +110,13 @@ const FormEngine = ({ markFormAsDirty?.(isFormDirty); }, [isFormDirty]); - const handleSubmit = useCallback((e: React.FormEvent) => { - e.preventDefault(); + const handleSubmit = useCallback((e?: React.FormEvent) => { + e?.preventDefault(); setIsSubmitting(true); }, []); + useExternalSubmitListener(handleSubmit); + return (
{isLoadingPatient || isLoadingFormJson ? ( @@ -152,6 +157,7 @@ const FormEngine = ({ onCancel={onCancel} handleClose={handleClose} hideFormCollapseToggle={hideFormCollapseToggle} + isSubmissionTriggeredExternally={isSubmissionTriggeredExternally} /> )}
@@ -167,7 +173,7 @@ const FormEngine = ({ setIsLoadingFormDependencies={setIsLoadingDependencies} />
- {showBottomButtonSet && ( + {showBottomButtonSet && !isSubmissionTriggeredExternally && (