1- import React , { createContext , useContext , useState } from ' react' ;
1+ import React , { createContext , useContext , useState } from " react" ;
22
33interface GlobalContextType {
4- showSummary : boolean ;
5- setShowSummary : React . Dispatch < React . SetStateAction < boolean > > ;
6- enterNewPatient : boolean ;
7- setEnterNewPatient : React . Dispatch < React . SetStateAction < boolean > > ;
8- resetFormValues : boolean ;
9- triggerFormReset : ( ) => void ;
10- isEditing : boolean ;
11- setIsEditing : React . Dispatch < React . SetStateAction < boolean > > ;
4+ showSummary : boolean ;
5+ setShowSummary : React . Dispatch < React . SetStateAction < boolean > > ;
6+ enterNewPatient : boolean ;
7+ setEnterNewPatient : React . Dispatch < React . SetStateAction < boolean > > ;
8+ resetFormValues : boolean ;
9+ triggerFormReset : ( ) => void ;
10+ isEditing : boolean ;
11+ setIsEditing : React . Dispatch < React . SetStateAction < boolean > > ;
12+ showMetaPanel : boolean ;
13+ setShowMetaPanel : React . Dispatch < React . SetStateAction < boolean > > ;
1214}
1315
14-
15- //redux / context issue need to provide default to avoid undefined
16- //if we don't the login errors out
16+ // Provide default no-op values to prevent errors during initialization
17+ // eslint-disable-next-line @typescript-eslint/no-empty-function
18+ const noop : ( ) => void = ( ) => { } ;
1719const defaultContextValue : GlobalContextType = {
18- enterNewPatient : false ,
19- setEnterNewPatient : ( ) => {
20- } , //no-op default
21- showSummary : false ,
22- setShowSummary : ( ) => {
23- } , //no-op default
24- resetFormValues : false ,
25- triggerFormReset : ( ) => {
26- } , //no-op default
27- isEditing : false ,
28- setIsEditing : ( ) => {
29- } , //no-op default
20+ enterNewPatient : false ,
21+ setEnterNewPatient : noop ,
22+ showSummary : false ,
23+ setShowSummary : noop ,
24+ resetFormValues : false ,
25+ triggerFormReset : noop ,
26+ isEditing : false ,
27+ setIsEditing : noop ,
28+ showMetaPanel : false ,
29+ setShowMetaPanel : noop ,
3030} ;
3131
32-
3332const GlobalContext = createContext < GlobalContextType > ( defaultContextValue ) ;
3433
34+ export const GlobalProvider : React . FC < { children : React . ReactNode } > = ( {
35+ children,
36+ } ) => {
37+ const [ showSummary , setShowSummary ] = useState < boolean > ( false ) ;
38+ const [ enterNewPatient , setEnterNewPatient ] = useState < boolean > ( true ) ;
39+ const [ resetFormValues , setResetFormValues ] = useState < boolean > ( false ) ;
40+ const [ isEditing , setIsEditing ] = useState < boolean > ( false ) ;
41+ const [ showMetaPanel , setShowMetaPanel ] = useState < boolean > ( false ) ;
3542
36- export const GlobalProvider : React . FC < { children : React . ReactNode } > = ( { children} ) => {
37- const [ showSummary , setShowSummary ] = useState < boolean > ( false ) ;
38- const [ enterNewPatient , setEnterNewPatient ] = useState < boolean > ( true ) ;
39- const [ resetFormValues , setResetFormValues ] = useState < boolean > ( false ) ;
40- const [ isEditing , setIsEditing ] = useState < boolean > ( false ) ;
43+ const triggerFormReset = ( ) => {
44+ setResetFormValues ( true ) ;
45+ setTimeout ( ( ) => {
46+ setResetFormValues ( false ) ;
47+ } , 100 ) ;
48+ } ;
4149
42- const triggerFormReset = ( ) => {
43- setResetFormValues ( true ) ;
44- // Reset the flag after a short delay
45- setTimeout ( ( ) => {
46- setResetFormValues ( false ) ;
47- } , 100 ) ;
48- } ;
49-
50- return (
51- < GlobalContext . Provider
52- value = { {
53- showSummary,
54- setShowSummary,
55- enterNewPatient,
56- setEnterNewPatient,
57- resetFormValues,
58- triggerFormReset,
59- isEditing,
60- setIsEditing
61- } }
62- >
63- { children }
64- </ GlobalContext . Provider >
65- ) ;
50+ return (
51+ < GlobalContext . Provider
52+ value = { {
53+ showSummary,
54+ setShowSummary,
55+ enterNewPatient,
56+ setEnterNewPatient,
57+ resetFormValues,
58+ triggerFormReset,
59+ isEditing,
60+ setIsEditing,
61+ showMetaPanel,
62+ setShowMetaPanel,
63+ } }
64+ >
65+ { children }
66+ </ GlobalContext . Provider >
67+ ) ;
6668} ;
6769
6870export const useGlobalContext = ( ) => {
69- const context = useContext ( GlobalContext ) ;
70- if ( context === undefined ) {
71- throw new Error ( ' useGlobalContext must be used within a GlobalProvider' ) ;
72- }
73- return context ;
74- } ;
71+ const context = useContext ( GlobalContext ) ;
72+ if ( context === undefined ) {
73+ throw new Error ( " useGlobalContext must be used within a GlobalProvider" ) ;
74+ }
75+ return context ;
76+ } ;
0 commit comments