Files
address-verification-app/ProtectedRouter.tsx

297 lines
12 KiB
TypeScript
Raw Normal View History

import crashlytics from '@react-native-firebase/crashlytics';
import { RouteProp } from '@react-navigation/native';
2022-12-20 14:30:41 +05:30
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import React, { useEffect } from 'react';
2022-12-20 14:30:41 +05:30
import { getUniqueId } from 'react-native-device-info';
import { useSelector } from 'react-redux';
import { _map } from './RN-UI-LIB/src/utlis/common';
import { GenericType } from './src/common/GenericTypes';
import Widget from './src/components/form';
2023-01-23 14:33:07 +05:30
import { registerNavigateAndDispatch } from './src/components/utlis/apiHelper';
import { getLoanIdToValueFromLocal } from './src/components/utlis/registerPaymentUtils';
2022-12-20 14:30:41 +05:30
import { setGlobalUserData } from './src/constants/Global';
import { useAppDispatch, useAppSelector } from './src/hooks';
import useFirestoreUpdates from './src/hooks/useFirestoreUpdates';
import { setLoanIdToValue } from './src/reducer/paymentSlice';
2022-12-20 14:30:41 +05:30
import { setDeviceId } from './src/reducer/userSlice';
import AddressGeolocation from './src/screens/addressGeolocation';
import NewAddressContainer from './src/screens/addressGeolocation/NewAddressContainer';
2022-12-15 14:32:07 +05:30
import AllCasesMain from './src/screens/allCases';
2023-02-24 11:56:48 +05:30
import CompletedCase from './src/screens/allCases/CompletedCase';
2022-12-15 14:32:07 +05:30
import CaseDetails from './src/screens/caseDetails/CaseDetails';
import CollectionCaseDetails from './src/screens/caseDetails/CollectionCaseDetail';
import interactionsHandler from './src/screens/caseDetails/interactionsHandler';
2022-12-20 14:30:41 +05:30
import Login from './src/screens/login';
import OtpInput from './src/screens/login/OtpInput';
import Profile from './src/screens/Profile';
import RegisterPayments from './src/screens/registerPayements/RegisterPayments';
2022-12-15 14:32:07 +05:30
import TodoList from './src/screens/todoList/TodoList';
2022-12-20 14:30:41 +05:30
import { RootState } from './src/store/store';
import { CaseAllocationType } from "./src/screens/allCases/interface";
import { getTemplateRoute } from "./src/components/utlis/navigationUtlis";
import { resetNewVisitedCases } from './src/reducer/allCasesSlice';
import { getCaseUnifiedData, UnifiedCaseDetailsTypes } from './src/action/caseApiActions';
import FeedbackDetailContainer from './src/screens/caseDetails/feedback/FeedbackDetailContainer';
import EmiSchedule from './src/screens/emiSchedule';
import { NetworkStatusService } from "./src/services/network-monitoring.service";
const ANIMATION_DURATION = 300;
const Stack = createNativeStackNavigator();
export enum PageRouteEnum {
PAYMENTS = 'registerPayments',
ADDRESS_GEO = 'addressGeolocation',
NEW_ADDRESS = 'newAddress',
COLLECTION_CASE_DETAIL = 'collectionCaseDetail',
EMI_SCHEDULE = 'EmiSchedule',
PAST_FEEDBACK_DETAIL = 'pastFeedbackDetail'
}
const ProtectedRouter = () => {
2022-12-08 15:47:56 +05:30
const user = useSelector(
(state: RootState) => state.user,
);
const { newVisitedCases, caseDetails } = useAppSelector(state => state.allCases);
useEffect(() => {
if(newVisitedCases?.length) {
const loanAccountNumbers: string[] = [];
newVisitedCases.forEach(caseId => {
const { loanAccountNumber } = caseDetails[caseId];
if(!loanAccountNumber) {
return;
}
loanAccountNumbers.push(loanAccountNumber);
});
if(loanAccountNumbers.length) {
const { EMI_SCHEDULE, REPAYMENTS, ADDRESS_AND_GEOLOCATIONS, FEEDBACKS } = UnifiedCaseDetailsTypes;
dispatch(getCaseUnifiedData(loanAccountNumbers, [EMI_SCHEDULE, REPAYMENTS, ADDRESS_AND_GEOLOCATIONS, FEEDBACKS]))
}
dispatch(resetNewVisitedCases());
}
}, [newVisitedCases])
const avTemplate = useSelector(
(state: RootState) => state.case.templateData[CaseAllocationType.ADDRESS_VERIFICATION_CASE],
);
const collectionTemplate = useSelector(
(state: RootState) => state.case.templateData[CaseAllocationType.COLLECTION_CASE],
);
2022-12-16 08:33:35 +05:30
const {isLoggedIn, deviceId, sessionDetails} = user;
2023-01-02 11:45:34 +05:30
interactionsHandler()
const dispatch = useAppDispatch();
NetworkStatusService.listenForOnline(dispatch);
// Firestore listener hook
useFirestoreUpdates();
if (!deviceId) {
2022-12-08 15:47:56 +05:30
getUniqueId().then(id => dispatch(setDeviceId(id)));
}
// for setting user token in global.ts for api calling's
setGlobalUserData(sessionDetails?.sessionToken, deviceId, user?.user?.referenceId);
const getScreenFocusListenerObj = ({route}: {route: RouteProp<GenericType>}) => ({
focus: () => {
crashlytics().log(JSON.stringify(route));
}
});
2023-01-23 14:33:07 +05:30
registerNavigateAndDispatch(dispatch);
// useEffect(() => {
// (async () => {
// const loanIdToValueStored = await getLoanIdToValueFromLocal();
// if (loanIdToValueStored) {
// dispatch(setLoanIdToValue(loanIdToValueStored));
// }
// })();
// }, []);
return (
<Stack.Navigator>
2022-12-14 18:58:35 +05:30
{isLoggedIn ? (
<>
<Stack.Screen
name="Home"
component={AllCasesMain}
2022-12-13 14:48:36 +05:30
options={{
header: () => null,
animation: 'slide_from_right',
animationDuration: ANIMATION_DURATION,
2022-12-13 14:48:36 +05:30
}}
listeners={getScreenFocusListenerObj}
2022-12-13 14:48:36 +05:30
/>
2022-12-22 18:29:21 +05:30
<Stack.Screen
name="Profile"
component={Profile}
options={{
header: () => null,
animation: 'slide_from_right',
animationDuration: ANIMATION_DURATION,
2022-12-22 18:29:21 +05:30
}}
listeners={getScreenFocusListenerObj}
2022-12-22 18:29:21 +05:30
/>
2022-12-13 14:48:36 +05:30
<Stack.Screen
name="caseDetail"
component={CaseDetails}
options={{
header: () => null,
animationDuration: ANIMATION_DURATION,
animation: 'none',
}}
listeners={getScreenFocusListenerObj}
/>
<Stack.Screen
name={PageRouteEnum.COLLECTION_CASE_DETAIL}
component={CollectionCaseDetails}
options={{
header: () => null,
animationDuration: ANIMATION_DURATION,
animation: 'none',
}}
listeners={getScreenFocusListenerObj}
/>
<Stack.Screen
name={PageRouteEnum.PAYMENTS}
component={RegisterPayments}
options={{
header: () => null,
animationDuration: ANIMATION_DURATION,
animation: 'none',
}}
listeners={getScreenFocusListenerObj}
/>
<Stack.Screen
name={PageRouteEnum.ADDRESS_GEO}
component={AddressGeolocation}
options={{
header: () => null,
animationDuration: ANIMATION_DURATION,
animation: 'none',
}}
listeners={getScreenFocusListenerObj}
/>
<Stack.Screen
name={PageRouteEnum.NEW_ADDRESS}
component={NewAddressContainer}
options={{
header: () => null,
animationDuration: ANIMATION_DURATION,
animation: 'none',
}}
listeners={getScreenFocusListenerObj}
/>
<Stack.Screen
name={PageRouteEnum.PAST_FEEDBACK_DETAIL}
component={FeedbackDetailContainer}
options={{
header: () => null,
animationDuration: ANIMATION_DURATION,
animation: 'none',
}}
listeners={getScreenFocusListenerObj}
/>
{_map(avTemplate?.widget, key => (
<Stack.Screen
key={getTemplateRoute(
key,
CaseAllocationType.ADDRESS_VERIFICATION_CASE,
)}
name={getTemplateRoute(
key,
CaseAllocationType.ADDRESS_VERIFICATION_CASE,
)}
component={Widget}
options={{
header: () => null,
animation: 'slide_from_right',
animationDuration: ANIMATION_DURATION,
}}
listeners={getScreenFocusListenerObj}
/>
))}
{_map(collectionTemplate?.widget, key => (
<Stack.Screen
key={getTemplateRoute(
key,
CaseAllocationType.COLLECTION_CASE,
)}
name={getTemplateRoute(
key,
CaseAllocationType.COLLECTION_CASE,
)}
component={Widget}
options={{
header: () => null,
animation: 'slide_from_right',
animationDuration: ANIMATION_DURATION,
}}
listeners={getScreenFocusListenerObj}
/>
))}
2022-12-13 18:57:32 +05:30
<Stack.Screen
name="TodoList"
component={TodoList}
options={{
header: () => null,
animation: 'slide_from_bottom',
animationDuration: ANIMATION_DURATION,
2022-12-13 18:57:32 +05:30
}}
listeners={getScreenFocusListenerObj}
2022-12-13 18:57:32 +05:30
/>
2023-02-24 11:56:48 +05:30
<Stack.Screen
name="CompletedCases"
component={CompletedCase}
options={{
header: () => null,
animation: 'slide_from_right',
animationDuration: ANIMATION_DURATION,
}}
listeners={getScreenFocusListenerObj}
/>
<Stack.Screen
name="EmiSchedule"
component={EmiSchedule}
options={{
header: () => null,
animation: 'slide_from_right',
animationDuration: ANIMATION_DURATION,
2023-02-24 11:56:48 +05:30
}}
listeners={getScreenFocusListenerObj}
/>
</>
) : (
<>
<Stack.Screen
name="Login"
2022-12-22 18:29:21 +05:30
component={Login}
options={{
header: () => null,
animation: 'slide_from_right',
animationDuration: ANIMATION_DURATION,
}}
listeners={getScreenFocusListenerObj}
/>
<Stack.Screen
name="OTP"
2022-12-22 18:29:21 +05:30
component={OtpInput}
options={{
header: () => null,
animation: 'slide_from_right',
animationDuration: ANIMATION_DURATION,
}}
listeners={getScreenFocusListenerObj}
/>
</>
)}
</Stack.Navigator>
);
};
export default ProtectedRouter;