-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) O3-3112: Re-instate the Form collapse (#244)
* feat: improve scroll to view when the form is in validation state * feat: form collapse * fix: fix hide toggle when form is canceld or closed * Revert "feat: improve scroll to view when the form is in validation state" This reverts commit c49e099. * fix: hide the toggle after saving * refactor: remove redundant add lister * refactor: use usecallback for handleFormCollapsetoggle
- Loading branch information
1 parent
8e5b45a
commit 13c1c62
Showing
6 changed files
with
46 additions
and
39 deletions.
There are no files selected for viewing
31 changes: 0 additions & 31 deletions
31
src/components/section-collapsible-toggle/section-collapsible-toggle.component.tsx
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
src/components/section-collapsible-toggle/section-collapsible-toggle.scss
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters