2023-01-16 15:23:57 +05:30
|
|
|
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';
|
2023-02-17 15:49:39 +05:30
|
|
|
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';
|
2023-01-16 15:23:57 +05:30
|
|
|
import { GenericType } from './src/common/GenericTypes';
|
2022-12-07 18:49:11 +05:30
|
|
|
import Widget from './src/components/form';
|
2023-01-23 14:33:07 +05:30
|
|
|
import { registerNavigateAndDispatch } from './src/components/utlis/apiHelper';
|
2023-02-17 15:49:39 +05:30
|
|
|
import { getLoanIdToValueFromLocal } from './src/components/utlis/registerPaymentUtils';
|
2022-12-20 14:30:41 +05:30
|
|
|
import { setGlobalUserData } from './src/constants/Global';
|
2023-03-17 13:10:19 +05:30
|
|
|
import { useAppDispatch, useAppSelector } from './src/hooks';
|
2023-01-16 15:23:57 +05:30
|
|
|
import useFirestoreUpdates from './src/hooks/useFirestoreUpdates';
|
2023-02-17 15:49:39 +05:30
|
|
|
import { setLoanIdToValue } from './src/reducer/paymentSlice';
|
2022-12-20 14:30:41 +05:30
|
|
|
import { setDeviceId } from './src/reducer/userSlice';
|
2023-02-22 13:35:44 +05:30
|
|
|
import AddressGeolocation from './src/screens/addressGeolocation';
|
2023-02-24 19:11:46 +05:30
|
|
|
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';
|
2023-02-22 14:46:57 +05:30
|
|
|
import CollectionCaseDetails from './src/screens/caseDetails/CollectionCaseDetail';
|
2023-01-16 15:23:57 +05:30
|
|
|
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';
|
2023-01-16 15:23:57 +05:30
|
|
|
import Profile from './src/screens/Profile';
|
2023-02-17 15:49:39 +05:30
|
|
|
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';
|
2023-02-25 13:32:34 +05:30
|
|
|
import { CaseAllocationType } from "./src/screens/allCases/interface";
|
|
|
|
|
import { getTemplateRoute } from "./src/components/utlis/navigationUtlis";
|
2023-03-17 13:10:19 +05:30
|
|
|
import { resetNewVisitedCases } from './src/reducer/allCasesSlice';
|
|
|
|
|
import { getCaseUnifiedData, UnifiedCaseDetailsTypes } from './src/action/caseApiActions';
|
2023-03-17 13:26:18 +05:30
|
|
|
import FeedbackDetailContainer from './src/screens/caseDetails/feedback/FeedbackDetailContainer';
|
2023-03-17 14:14:11 +05:30
|
|
|
import EmiSchedule from './src/screens/emiSchedule';
|
2023-03-20 19:15:28 +05:30
|
|
|
import { NetworkStatusService } from "./src/services/network-monitoring.service";
|
2022-12-07 18:49:11 +05:30
|
|
|
|
2023-01-12 17:01:51 +05:30
|
|
|
const ANIMATION_DURATION = 300;
|
|
|
|
|
|
2022-12-07 18:49:11 +05:30
|
|
|
const Stack = createNativeStackNavigator();
|
|
|
|
|
|
2023-02-23 17:06:33 +05:30
|
|
|
export enum PageRouteEnum {
|
|
|
|
|
PAYMENTS = 'registerPayments',
|
2023-02-24 19:11:46 +05:30
|
|
|
ADDRESS_GEO = 'addressGeolocation',
|
|
|
|
|
NEW_ADDRESS = 'newAddress',
|
2023-03-17 13:26:18 +05:30
|
|
|
COLLECTION_CASE_DETAIL = 'collectionCaseDetail',
|
2023-03-17 14:14:11 +05:30
|
|
|
EMI_SCHEDULE = 'EmiSchedule',
|
2023-03-17 13:26:18 +05:30
|
|
|
PAST_FEEDBACK_DETAIL = 'pastFeedbackDetail'
|
2023-02-23 17:06:33 +05:30
|
|
|
}
|
|
|
|
|
|
2022-12-07 18:49:11 +05:30
|
|
|
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
|
|
|
);
|
2023-03-17 13:10:19 +05:30
|
|
|
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])
|
2022-12-07 18:49:11 +05:30
|
|
|
|
2023-02-25 13:32:34 +05:30
|
|
|
const avTemplate = useSelector(
|
|
|
|
|
(state: RootState) => state.case.templateData[CaseAllocationType.ADDRESS_VERIFICATION_CASE],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const collectionTemplate = useSelector(
|
2023-03-17 14:14:11 +05:30
|
|
|
(state: RootState) => state.case.templateData[CaseAllocationType.COLLECTION_CASE],
|
|
|
|
|
);
|
2023-01-17 18:50:50 +05:30
|
|
|
|
2022-12-16 08:33:35 +05:30
|
|
|
const {isLoggedIn, deviceId, sessionDetails} = user;
|
|
|
|
|
|
2023-01-02 11:45:34 +05:30
|
|
|
interactionsHandler()
|
2022-12-07 18:49:11 +05:30
|
|
|
const dispatch = useAppDispatch();
|
2023-03-20 19:15:28 +05:30
|
|
|
NetworkStatusService.listenForOnline(dispatch);
|
|
|
|
|
|
|
|
|
|
// Firestore listener hook
|
2023-03-17 14:14:11 +05:30
|
|
|
useFirestoreUpdates();
|
|
|
|
|
|
2022-12-07 18:49:11 +05:30
|
|
|
if (!deviceId) {
|
2022-12-08 15:47:56 +05:30
|
|
|
getUniqueId().then(id => dispatch(setDeviceId(id)));
|
2022-12-07 18:49:11 +05:30
|
|
|
}
|
2023-01-18 16:39:24 +05:30
|
|
|
// for setting user token in global.ts for api calling's
|
|
|
|
|
setGlobalUserData(sessionDetails?.sessionToken, deviceId, user?.user?.referenceId);
|
2023-03-17 14:14:11 +05:30
|
|
|
|
2023-01-06 20:18:16 +05:30
|
|
|
const getScreenFocusListenerObj = ({route}: {route: RouteProp<GenericType>}) => ({
|
|
|
|
|
focus: () => {
|
|
|
|
|
crashlytics().log(JSON.stringify(route));
|
|
|
|
|
}
|
2023-03-17 14:14:11 +05:30
|
|
|
});
|
|
|
|
|
|
2023-01-23 14:33:07 +05:30
|
|
|
registerNavigateAndDispatch(dispatch);
|
2023-03-17 14:14:11 +05:30
|
|
|
|
2023-03-02 17:36:59 +05:30
|
|
|
// useEffect(() => {
|
|
|
|
|
// (async () => {
|
|
|
|
|
// const loanIdToValueStored = await getLoanIdToValueFromLocal();
|
|
|
|
|
// if (loanIdToValueStored) {
|
|
|
|
|
// dispatch(setLoanIdToValue(loanIdToValueStored));
|
|
|
|
|
// }
|
|
|
|
|
// })();
|
|
|
|
|
// }, []);
|
2023-02-17 15:49:39 +05:30
|
|
|
|
2022-12-07 18:49:11 +05:30
|
|
|
return (
|
|
|
|
|
<Stack.Navigator>
|
2022-12-14 18:58:35 +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,
|
2023-01-12 17:01:51 +05:30
|
|
|
animation: 'slide_from_right',
|
2023-03-17 14:14:11 +05:30
|
|
|
animationDuration: ANIMATION_DURATION,
|
2022-12-13 14:48:36 +05:30
|
|
|
}}
|
2023-01-06 20:18:16 +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,
|
2023-01-12 17:01:51 +05:30
|
|
|
animation: 'slide_from_right',
|
2023-03-17 14:14:11 +05:30
|
|
|
animationDuration: ANIMATION_DURATION,
|
2022-12-22 18:29:21 +05:30
|
|
|
}}
|
2023-01-06 20:18:16 +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}
|
2022-12-07 18:49:11 +05:30
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
2023-01-12 17:01:51 +05:30
|
|
|
animationDuration: ANIMATION_DURATION,
|
2023-01-16 15:23:57 +05:30
|
|
|
animation: 'none',
|
2023-02-22 14:46:57 +05:30
|
|
|
}}
|
|
|
|
|
listeners={getScreenFocusListenerObj}
|
|
|
|
|
/>
|
|
|
|
|
<Stack.Screen
|
2023-02-24 19:11:46 +05:30
|
|
|
name={PageRouteEnum.COLLECTION_CASE_DETAIL}
|
2023-02-22 14:46:57 +05:30
|
|
|
component={CollectionCaseDetails}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
animationDuration: ANIMATION_DURATION,
|
|
|
|
|
animation: 'none',
|
2022-12-07 18:49:11 +05:30
|
|
|
}}
|
2023-01-06 20:18:16 +05:30
|
|
|
listeners={getScreenFocusListenerObj}
|
2022-12-07 18:49:11 +05:30
|
|
|
/>
|
2023-02-17 15:49:39 +05:30
|
|
|
<Stack.Screen
|
2023-02-23 17:06:33 +05:30
|
|
|
name={PageRouteEnum.PAYMENTS}
|
2023-02-17 15:49:39 +05:30
|
|
|
component={RegisterPayments}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
animationDuration: ANIMATION_DURATION,
|
|
|
|
|
animation: 'none',
|
|
|
|
|
}}
|
|
|
|
|
listeners={getScreenFocusListenerObj}
|
|
|
|
|
/>
|
2023-02-22 13:35:44 +05:30
|
|
|
<Stack.Screen
|
2023-02-23 17:06:33 +05:30
|
|
|
name={PageRouteEnum.ADDRESS_GEO}
|
2023-02-22 13:35:44 +05:30
|
|
|
component={AddressGeolocation}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
animationDuration: ANIMATION_DURATION,
|
|
|
|
|
animation: 'none',
|
|
|
|
|
}}
|
|
|
|
|
listeners={getScreenFocusListenerObj}
|
|
|
|
|
/>
|
2023-02-24 19:11:46 +05:30
|
|
|
<Stack.Screen
|
|
|
|
|
name={PageRouteEnum.NEW_ADDRESS}
|
|
|
|
|
component={NewAddressContainer}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
animationDuration: ANIMATION_DURATION,
|
|
|
|
|
animation: 'none',
|
|
|
|
|
}}
|
|
|
|
|
listeners={getScreenFocusListenerObj}
|
|
|
|
|
/>
|
2023-03-17 13:26:18 +05:30
|
|
|
<Stack.Screen
|
|
|
|
|
name={PageRouteEnum.PAST_FEEDBACK_DETAIL}
|
|
|
|
|
component={FeedbackDetailContainer}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
|
|
|
|
animationDuration: ANIMATION_DURATION,
|
|
|
|
|
animation: 'none',
|
|
|
|
|
}}
|
|
|
|
|
listeners={getScreenFocusListenerObj}
|
|
|
|
|
/>
|
2023-02-25 13:32:34 +05:30
|
|
|
{_map(avTemplate?.widget, key => (
|
2022-12-07 18:49:11 +05:30
|
|
|
<Stack.Screen
|
2023-03-17 14:14:11 +05:30
|
|
|
key={getTemplateRoute(
|
|
|
|
|
key,
|
|
|
|
|
CaseAllocationType.ADDRESS_VERIFICATION_CASE,
|
|
|
|
|
)}
|
|
|
|
|
name={getTemplateRoute(
|
|
|
|
|
key,
|
|
|
|
|
CaseAllocationType.ADDRESS_VERIFICATION_CASE,
|
|
|
|
|
)}
|
2022-12-07 18:49:11 +05:30
|
|
|
component={Widget}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
2023-01-12 17:01:51 +05:30
|
|
|
animation: 'slide_from_right',
|
2023-03-17 14:14:11 +05:30
|
|
|
animationDuration: ANIMATION_DURATION,
|
2022-12-07 18:49:11 +05:30
|
|
|
}}
|
2023-01-06 20:18:16 +05:30
|
|
|
listeners={getScreenFocusListenerObj}
|
2022-12-07 18:49:11 +05:30
|
|
|
/>
|
|
|
|
|
))}
|
2023-02-25 13:32:34 +05:30
|
|
|
{_map(collectionTemplate?.widget, key => (
|
2023-03-17 14:14:11 +05:30
|
|
|
<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}
|
|
|
|
|
/>
|
2023-02-25 13:32:34 +05:30
|
|
|
))}
|
2022-12-13 18:57:32 +05:30
|
|
|
<Stack.Screen
|
|
|
|
|
name="TodoList"
|
|
|
|
|
component={TodoList}
|
|
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
2023-01-12 17:01:51 +05:30
|
|
|
animation: 'slide_from_bottom',
|
2023-03-17 14:14:11 +05:30
|
|
|
animationDuration: ANIMATION_DURATION,
|
2022-12-13 18:57:32 +05:30
|
|
|
}}
|
2023-01-06 20:18:16 +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',
|
2023-03-17 14:14:11 +05:30
|
|
|
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}
|
|
|
|
|
/>
|
2022-12-07 18:49:11 +05:30
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<Stack.Screen
|
|
|
|
|
name="Login"
|
2022-12-22 18:29:21 +05:30
|
|
|
component={Login}
|
2022-12-07 18:49:11 +05:30
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
2023-01-12 17:01:51 +05:30
|
|
|
animation: 'slide_from_right',
|
2023-03-17 14:14:11 +05:30
|
|
|
animationDuration: ANIMATION_DURATION,
|
2022-12-07 18:49:11 +05:30
|
|
|
}}
|
2023-01-06 20:18:16 +05:30
|
|
|
listeners={getScreenFocusListenerObj}
|
2022-12-07 18:49:11 +05:30
|
|
|
/>
|
|
|
|
|
<Stack.Screen
|
|
|
|
|
name="OTP"
|
2022-12-22 18:29:21 +05:30
|
|
|
component={OtpInput}
|
2022-12-07 18:49:11 +05:30
|
|
|
options={{
|
|
|
|
|
header: () => null,
|
2023-01-12 17:01:51 +05:30
|
|
|
animation: 'slide_from_right',
|
2023-03-17 14:14:11 +05:30
|
|
|
animationDuration: ANIMATION_DURATION,
|
2022-12-07 18:49:11 +05:30
|
|
|
}}
|
2023-01-06 20:18:16 +05:30
|
|
|
listeners={getScreenFocusListenerObj}
|
2022-12-07 18:49:11 +05:30
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Stack.Navigator>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ProtectedRouter;
|