2022-12-07 18:49:11 +05:30
|
|
|
import {createNativeStackNavigator} from '@react-navigation/native-stack';
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import {View} from 'react-native';
|
|
|
|
|
import {SafeAreaView} from 'react-native-safe-area-context';
|
|
|
|
|
import {useSelector} from 'react-redux';
|
|
|
|
|
import Widget from './src/components/form';
|
|
|
|
|
import RenderingEngine from './src/components/formRenderingEngine';
|
|
|
|
|
import Login from './src/components/login';
|
|
|
|
|
import OtpInput from './src/components/login/OtpInput';
|
|
|
|
|
import {RootState} from './src/store/store';
|
|
|
|
|
import data from './src/data/templateData.json';
|
|
|
|
|
import userData from './src/data/userData.json';
|
|
|
|
|
import {getUniqueId} from 'react-native-device-info';
|
|
|
|
|
import {useAppDispatch} from './src/hooks';
|
|
|
|
|
import {setAuthData} from './src/reducer/commonSlice';
|
2022-12-08 01:54:56 +05:30
|
|
|
import AllCases from './src/components/screens/allCases/AllCases';
|
2022-12-09 03:56:42 +05:30
|
|
|
import AllCasesMain from './src/components/screens/allCases';
|
2022-12-08 15:47:56 +05:30
|
|
|
import {setDeviceId} from './src/reducer/userSlice';
|
2022-12-08 11:24:39 +05:30
|
|
|
import { _map } from './RN-UI-LIB/src/utlis/common';
|
2022-12-13 14:48:36 +05:30
|
|
|
import CaseDetails from './src/components/caseDetails/CaseDetails';
|
2022-12-13 18:57:32 +05:30
|
|
|
import TodoList from './src/components/screens/todoList/TodoList';
|
2022-12-07 18:49:11 +05:30
|
|
|
|
|
|
|
|
const Stack = createNativeStackNavigator();
|
|
|
|
|
|
|
|
|
|
const LoginScreen = () => <Login />;
|
|
|
|
|
|
|
|
|
|
const OTPScreen = () => <OtpInput />;
|
|
|
|
|
|
|
|
|
|
const HomeScreen = () => (
|
|
|
|
|
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
|
|
|
|
|
<SafeAreaView>
|
|
|
|
|
<RenderingEngine data={data} userData={userData} />
|
|
|
|
|
</SafeAreaView>
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const ProtectedRouter = () => {
|
2022-12-08 15:47:56 +05:30
|
|
|
const user = useSelector(
|
|
|
|
|
(state: RootState) => state.user,
|
2022-12-07 18:49:11 +05:30
|
|
|
);
|
|
|
|
|
|
2022-12-08 15:47:56 +05:30
|
|
|
const {isLoggedIn, deviceId} = user;
|
|
|
|
|
|
2022-12-07 18:49:11 +05:30
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
|
|
|
|
|
if (!deviceId) {
|
2022-12-08 15:47:56 +05:30
|
|
|
getUniqueId().then(id => dispatch(setDeviceId(id)));
|
2022-12-07 18:49:11 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Stack.Navigator>
|
2022-12-13 18:18:21 +05:30
|
|
|
{!isLoggedIn ? (
|
2022-12-07 18:49:11 +05:30
|
|
|
<>
|
|
|
|
|
<Stack.Screen
|
|
|
|
|
name="Home"
|
2022-12-13 16:29:48 +05:30
|
|
|
component={AllCasesMain}
|
2022-12-13 14:48:36 +05:30
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Stack.Screen
|
|
|
|
|
name="caseDetail"
|
|
|
|
|
component={CaseDetails}
|
2022-12-07 18:49:11 +05:30
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2022-12-08 11:24:39 +05:30
|
|
|
{_map(data.widgets, key => (
|
2022-12-07 18:49:11 +05:30
|
|
|
<Stack.Screen
|
|
|
|
|
key={key}
|
|
|
|
|
name={key}
|
|
|
|
|
component={Widget}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2022-12-13 18:57:32 +05:30
|
|
|
<Stack.Screen
|
|
|
|
|
name="TodoList"
|
|
|
|
|
component={TodoList}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2022-12-07 18:49:11 +05:30
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<Stack.Screen
|
|
|
|
|
name="Login"
|
2022-12-13 14:48:36 +05:30
|
|
|
component={LoginScreen}
|
2022-12-07 18:49:11 +05:30
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Stack.Screen
|
|
|
|
|
name="OTP"
|
|
|
|
|
component={OTPScreen}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Stack.Navigator>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ProtectedRouter;
|