Skip to content

Commit 093e29f

Browse files
authored
Merge pull request #146 from Resgrid/develop
CU-868f1731u More fixes for ios and a build issue fix.
2 parents 7bbdc0f + 1c8d55d commit 093e29f

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

.github/workflows/react-native-cicd.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ env:
6666
EXPO_APPLE_TEAM_TYPE: ${{ secrets.EXPO_APPLE_TEAM_TYPE }}
6767
UNIT_APTABASE_APP_KEY: ${{ secrets.UNIT_APTABASE_APP_KEY }}
6868
UNIT_APTABASE_URL: ${{ secrets.UNIT_APTABASE_URL }}
69+
UNIT_APP_KEY: ${{ secrets.UNIT_APP_KEY }}
70+
APP_KEY: ${{ secrets.APP_KEY }}
6971
NODE_OPTIONS: --openssl-legacy-provider
7072

7173
jobs:

src/app/(app)/_layout.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

404416
const styles = StyleSheet.create({

src/components/notifications/NotificationInbox.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ export const NotificationInbox = ({ isOpen, onClose }: NotificationInboxProps) =
235235
return null;
236236
}
237237

238+
// Additional safety check to prevent rendering overlay without proper config
239+
if (!activeUnitId || !config || !config.NovuApplicationId || !config.NovuBackendApiUrl || !config.NovuSocketUrl) {
240+
return null;
241+
}
242+
238243
return (
239244
<View style={StyleSheet.absoluteFill} pointerEvents={isOpen ? 'auto' : 'none'}>
240245
{/* Backdrop for tapping outside to close */}

src/components/notifications/__tests__/NotificationInbox.test.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ describe('NotificationInbox', () => {
8989
mockUseCoreStore.mockImplementation((selector: any) => {
9090
const state = {
9191
activeUnitId: 'unit-1',
92-
config: { apiUrl: 'test-url' },
92+
config: {
93+
apiUrl: 'test-url',
94+
NovuApplicationId: 'test-app-id',
95+
NovuBackendApiUrl: 'test-backend-url',
96+
NovuSocketUrl: 'test-socket-url'
97+
},
9398
};
9499
return selector(state);
95100
});
@@ -257,16 +262,18 @@ describe('NotificationInbox', () => {
257262
mockUseCoreStore.mockImplementation((selector: any) => {
258263
const state = {
259264
activeUnitId: null,
260-
config: null,
265+
config: { apiUrl: 'test-url' }, // Missing Novu config properties
261266
};
262267
return selector(state);
263268
});
264269

265-
const { getByText } = render(
270+
const { queryByText } = render(
266271
<NotificationInbox isOpen={true} onClose={mockOnClose} />
267272
);
268273

269-
expect(getByText('Unable to load notifications')).toBeTruthy();
274+
// Component should return null when required config is missing
275+
expect(queryByText('Notifications')).toBeNull();
276+
expect(queryByText('Unable to load notifications')).toBeNull();
270277
});
271278

272279
it('opens notification detail on tap in normal mode', async () => {

0 commit comments

Comments
 (0)