Update CBS Mobile App codebase
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import { View } from 'react-native';
|
||||
import {
|
||||
DarkTheme,
|
||||
NavigationContainer,
|
||||
@@ -6,10 +7,12 @@ import {
|
||||
|
||||
import { useAppSelector } from '../app/hooks';
|
||||
import { selectAuthHydrating, selectIsAuthenticated, selectAuthRole } from '../modules/auth/store/authSelectors';
|
||||
import { Loader } from '../components';
|
||||
import { FeatureKey } from '../constants/featureKeys';
|
||||
import { useFeature, useFeatureContext } from '../features';
|
||||
import { useTheme } from '../theme';
|
||||
import { AuthNavigator } from './AuthNavigator';
|
||||
import { MainTabNavigator } from './MainTabNavigator';
|
||||
import { EmployeeNavigator } from './EmployeeNavigator';
|
||||
import { AgentNavigator } from './AgentNavigator';
|
||||
|
||||
export const RootNavigator = () => {
|
||||
@@ -17,11 +20,22 @@ export const RootNavigator = () => {
|
||||
const isHydrating = useAppSelector(selectAuthHydrating);
|
||||
const isAuthenticated = useAppSelector(selectIsAuthenticated);
|
||||
const role = useAppSelector(selectAuthRole);
|
||||
const agentAppEnabled = useFeature(FeatureKey.AGENT);
|
||||
/**
|
||||
* Navigators register their screens at mount time, so mounting one before the
|
||||
* feature layers have resolved would leave a disabled route reachable — by
|
||||
* `navigate()`, a deep link or restored state — until the next launch. Waiting
|
||||
* is what makes a server-side kill switch take effect on this launch.
|
||||
*/
|
||||
const { ready: featuresReady } = useFeatureContext();
|
||||
|
||||
const renderAppStack = () => {
|
||||
switch (role) {
|
||||
// Turning off `agent` retires the whole field-agent application. An
|
||||
// already-signed-in agent falls back to the customer app rather than
|
||||
// landing on an empty navigator.
|
||||
case 'Agent':
|
||||
return <AgentNavigator />;
|
||||
return agentAppEnabled ? <AgentNavigator /> : <MainTabNavigator />;
|
||||
case 'User':
|
||||
default:
|
||||
return <MainTabNavigator />;
|
||||
@@ -43,7 +57,18 @@ export const RootNavigator = () => {
|
||||
},
|
||||
}}
|
||||
>
|
||||
{isAuthenticated ? renderAppStack() : <AuthNavigator />}
|
||||
{/* Bootstrap validates a stored session against the server before
|
||||
trusting it, so rendering the sign-in screen meanwhile would flash it
|
||||
at a user who turns out to be signed in already. */}
|
||||
{isHydrating || !featuresReady ? (
|
||||
<View style={{ flex: 1, backgroundColor: theme.colors.background }}>
|
||||
<Loader />
|
||||
</View>
|
||||
) : isAuthenticated ? (
|
||||
renderAppStack()
|
||||
) : (
|
||||
<AuthNavigator />
|
||||
)}
|
||||
</NavigationContainer>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user