= ({
setValues={props.setValues}
allowUnspecifiedAll={formJson.allowUnspecifiedAll}
defaultPage={formJson.defaultPage}
+ hideFormCollapseToggle={hideFormCollapseToggle}
/>
)}
@@ -316,6 +319,7 @@ const FormEngine: React.FC = ({
onClick={() => {
onCancel && onCancel();
handleClose && handleClose();
+ hideFormCollapseToggle();
}}>
{mode === 'view' ? t('close', 'Close') : t('cancel', 'Cancel')}
diff --git a/src/hooks/useFormCollapse.tsx b/src/hooks/useFormCollapse.tsx
new file mode 100644
index 000000000..d528a5e0a
--- /dev/null
+++ b/src/hooks/useFormCollapse.tsx
@@ -0,0 +1,36 @@
+import { SessionMode } from '../types';
+import { useCallback, useEffect, useState } from 'react';
+
+export function useFormCollapse(sessionMode: SessionMode) {
+ const [isFormExpanded, setIsFormExpanded] = useState(true);
+
+ const hideFormCollapseToggle = useCallback(() => {
+ const HideFormCollapseToggle = new CustomEvent('openmrs:form-view-embedded', { detail: { value: false } });
+ window.dispatchEvent(HideFormCollapseToggle);
+ }, []);
+
+ const handleFormCollapseToggle = useCallback((event) => {
+ setIsFormExpanded(event.detail.value);
+ }, []);
+
+ useEffect(() => {
+ const FormCollapseToggleVisibleEvent = new CustomEvent('openmrs:form-view-embedded', {
+ detail: { value: sessionMode != 'embedded-view' },
+ });
+
+ window.dispatchEvent(FormCollapseToggleVisibleEvent);
+ }, [sessionMode]);
+
+ useEffect(() => {
+ window.addEventListener('openmrs:form-collapse-toggle', handleFormCollapseToggle);
+
+ return () => {
+ window.removeEventListener('openmrs:form-collapse-toggle', handleFormCollapseToggle);
+ };
+ }, []);
+
+ return {
+ isFormExpanded,
+ hideFormCollapseToggle,
+ };
+}
diff --git a/src/hooks/useFormJson.tsx b/src/hooks/useFormJson.tsx
index 327e41358..332e5a14b 100644
--- a/src/hooks/useFormJson.tsx
+++ b/src/hooks/useFormJson.tsx
@@ -33,6 +33,7 @@ export function useFormJson(formUuid: string, rawFormJson: any, encounterUuid: s
formError: error,
};
}
+
/**
* Fetches a form JSON from OpenMRS and recursively fetches its subforms if they available.
*
@@ -95,6 +96,7 @@ function validateFormsArgs(formUuid: string, rawFormJson: any): Error {
return new Error('InvalidArgumentsErr: Both formUuid and formJson cannot be provided at the same time.');
}
}
+
/**
* Refines the input form JSON object by parsing it, removing inline subforms, applying form schema transformers, setting the encounter type, and applying form intents if provided.
* @param {any} formJson - The input form JSON object or string.