@@ -39,6 +39,7 @@ export default function TabLayout() {
3939 const [ isFirstTime , _setIsFirstTime ] = useIsFirstTime ( ) ;
4040 const [ isOpen , setIsOpen ] = React . useState ( false ) ;
4141 const [ isNotificationsOpen , setIsNotificationsOpen ] = React . useState ( false ) ;
42+ const [ isNotificationSystemReady , setIsNotificationSystemReady ] = React . useState ( false ) ;
4243 const { width, height } = useWindowDimensions ( ) ;
4344 const isLandscape = width > height ;
4445 const { isActive, appState } = useAppLifecycle ( ) ;
@@ -215,6 +216,20 @@ export default function TabLayout() {
215216 const activeUnitId = useCoreStore ( ( state ) => state . activeUnitId ) ;
216217 const rights = securityStore ( ( state ) => state . rights ) ;
217218
219+ // Manage notification system readiness
220+ useEffect ( ( ) => {
221+ const isReady = Boolean ( activeUnitId && config && config . NovuApplicationId && config . NovuBackendApiUrl && config . NovuSocketUrl && rights ?. DepartmentCode ) ;
222+
223+ if ( isReady && ! isNotificationSystemReady ) {
224+ // Add a small delay to ensure the main UI is rendered first
225+ setTimeout ( ( ) => {
226+ setIsNotificationSystemReady ( true ) ;
227+ } , 1000 ) ;
228+ } else if ( ! isReady && isNotificationSystemReady ) {
229+ setIsNotificationSystemReady ( false ) ;
230+ }
231+ } , [ activeUnitId , config , rights ?. DepartmentCode , isNotificationSystemReady ] ) ;
232+
218233 if ( isFirstTime ) {
219234 //setIsOnboarding();
220235 return < Redirect href = "/onboarding" /> ;
@@ -338,16 +353,16 @@ export default function TabLayout() {
338353 </ Tabs >
339354
340355 { /* NotificationInbox positioned within the tab content area */ }
341- { activeUnitId && config && rights ?. DepartmentCode && < NotificationInbox isOpen = { isNotificationsOpen } onClose = { ( ) => setIsNotificationsOpen ( false ) } /> }
356+ { isNotificationSystemReady && < NotificationInbox isOpen = { isNotificationsOpen } onClose = { ( ) => setIsNotificationsOpen ( false ) } /> }
342357 </ View >
343358 </ View >
344359 </ View >
345360 ) ;
346361
347362 return (
348363 < >
349- { activeUnitId && config && rights ?. DepartmentCode ? (
350- < NovuProvider subscriberId = { `${ rights ?. DepartmentCode } _Unit_${ activeUnitId } ` } applicationIdentifier = { config . NovuApplicationId } backendUrl = { config . NovuBackendApiUrl } socketUrl = { config . NovuSocketUrl } >
364+ { isNotificationSystemReady ? (
365+ < NovuProvider subscriberId = { `${ rights ?. DepartmentCode } _Unit_${ activeUnitId } ` } applicationIdentifier = { config ! . NovuApplicationId } backendUrl = { config ! . NovuBackendApiUrl } socketUrl = { config ! . NovuSocketUrl } >
351366 { content }
352367 </ NovuProvider >
353368 ) : (
@@ -394,11 +409,8 @@ const CreateNotificationButton = ({
394409 return null ;
395410 }
396411
397- return (
398- < NovuProvider subscriberId = { `${ departmentCode } _Unit_${ activeUnitId } ` } applicationIdentifier = { config . NovuApplicationId } backendUrl = { config . NovuBackendApiUrl } socketUrl = { config . NovuSocketUrl } >
399- < NotificationButton onPress = { ( ) => setIsNotificationsOpen ( true ) } />
400- </ NovuProvider >
401- ) ;
412+ // Only render after notification system is ready to prevent timing issues
413+ return < NotificationButton onPress = { ( ) => setIsNotificationsOpen ( true ) } /> ;
402414} ;
403415
404416const styles = StyleSheet . create ( {
0 commit comments