* TP-25164 location api fix * TP-25164 fix error message * TP-25164 warn eslint * fix error message TP-25164 * remove gibberish TP-25164
383 lines
16 KiB
TypeScript
383 lines
16 KiB
TypeScript
import crashlytics from '@react-native-firebase/crashlytics';
|
|
import { RouteProp } from '@react-navigation/native';
|
|
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
|
import React, { useEffect } from 'react';
|
|
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';
|
|
import { registerNavigateAndDispatch } from './src/components/utlis/apiHelper';
|
|
import { getLoanIdToValueFromLocal } from './src/components/utlis/registerPaymentUtils';
|
|
import { setGlobalUserData } from './src/constants/Global';
|
|
import { useAppDispatch, useAppSelector } from './src/hooks';
|
|
import useFirestoreUpdates from './src/hooks/useFirestoreUpdates';
|
|
import { setLoanIdToValue } from './src/reducer/paymentSlice';
|
|
import { setDeviceId } from './src/reducer/userSlice';
|
|
import AddressGeolocation from './src/screens/addressGeolocation';
|
|
import NewAddressContainer from './src/screens/addressGeolocation/NewAddressContainer';
|
|
import AllCasesMain from './src/screens/allCases';
|
|
import CompletedCase from './src/screens/allCases/CompletedCase';
|
|
import CaseDetails from './src/screens/caseDetails/CaseDetails';
|
|
import CollectionCaseDetails from './src/screens/caseDetails/CollectionCaseDetail';
|
|
import interactionsHandler from './src/screens/caseDetails/interactionsHandler';
|
|
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';
|
|
import TodoList from './src/screens/todoList/TodoList';
|
|
import { RootState } from './src/store/store';
|
|
import { CaseAllocationType } from "./src/screens/allCases/interface";
|
|
import { getTemplateRoute, navigateToScreen } 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";
|
|
import AddNewNumber from './src/screens/addNewNumber';
|
|
import useFCM from './src/hooks/useFCM';
|
|
import Notifications from './src/screens/notifications';
|
|
import { getNotifications, notificationAction } from './src/action/notificationActions';
|
|
import useIsOnline from './src/hooks/useIsOnline';
|
|
import CustomerProfile from './src/screens/caseDetails/CustomerProfile';
|
|
import VKYCFullScreen from './src/screens/caseDetails/VKYCFullScreen';
|
|
import { verifyGoogleSignIn } from './src/action/authActions';
|
|
import { Linking } from 'react-native';
|
|
import { getParamsObject } from './src/components/utlis/commonFunctions';
|
|
import useNativeButtons from './src/hooks/useNativeButton';
|
|
|
|
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 = () => {
|
|
useNativeButtons();
|
|
const user = useSelector(
|
|
(state: RootState) => state.user,
|
|
);
|
|
const { newVisitedCases, caseDetails } = useAppSelector(state => state.allCases);
|
|
const { data = [], notificationsWithActions } = useAppSelector(state => state.notifications);
|
|
const {isLoggedIn, deviceId, sessionDetails} = user;
|
|
const isOnline = useIsOnline();
|
|
|
|
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])
|
|
|
|
useEffect(() => {
|
|
if(isLoggedIn && isOnline) {
|
|
dispatch(getNotifications());
|
|
}
|
|
}, [isLoggedIn, isOnline]);
|
|
|
|
useEffect(() => {
|
|
if(isLoggedIn && isOnline && notificationsWithActions.length) {
|
|
dispatch(notificationAction(notificationsWithActions));
|
|
}
|
|
}, [isLoggedIn, isOnline, notificationsWithActions])
|
|
|
|
|
|
const avTemplate = useSelector(
|
|
(state: RootState) => state.case.templateData[CaseAllocationType.ADDRESS_VERIFICATION_CASE],
|
|
);
|
|
|
|
const collectionTemplate = useSelector(
|
|
(state: RootState) => state.case.templateData[CaseAllocationType.COLLECTION_CASE],
|
|
);
|
|
|
|
interactionsHandler()
|
|
const dispatch = useAppDispatch();
|
|
NetworkStatusService.listenForOnline(dispatch);
|
|
|
|
// Firestore listener hook
|
|
useFirestoreUpdates();
|
|
|
|
// Firebase cloud messaging
|
|
useFCM();
|
|
|
|
if (!deviceId) {
|
|
getUniqueId().then(id => dispatch(setDeviceId(id)));
|
|
}
|
|
// for setting user token in global.ts for api calling's
|
|
setGlobalUserData({token: sessionDetails?.sessionToken, deviceId, agentId: user?.user?.referenceId});
|
|
|
|
const getScreenFocusListenerObj = ({route}: {route: RouteProp<GenericType>}) => ({
|
|
focus: () => {
|
|
crashlytics().log(JSON.stringify(route));
|
|
}
|
|
});
|
|
|
|
registerNavigateAndDispatch(dispatch);
|
|
|
|
const handleUrl = (url: string) => {
|
|
if (url) {
|
|
const decodedUri = decodeURIComponent(url);
|
|
const fragmentIndex = decodedUri.indexOf('#');
|
|
if (fragmentIndex !== -1) {
|
|
const params = decodedUri.substring(fragmentIndex + 1);
|
|
const { code, state } = getParamsObject(params);
|
|
dispatch(verifyGoogleSignIn(code, state, deviceId));
|
|
}
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
Linking.addEventListener("url", event => handleUrl(event.url));
|
|
|
|
}, [])
|
|
|
|
// useEffect(() => {
|
|
// (async () => {
|
|
// const loanIdToValueStored = await getLoanIdToValueFromLocal();
|
|
// if (loanIdToValueStored) {
|
|
// dispatch(setLoanIdToValue(loanIdToValueStored));
|
|
// }
|
|
// })();
|
|
// }, []);
|
|
|
|
return (
|
|
<Stack.Navigator>
|
|
{isLoggedIn ? (
|
|
<>
|
|
<Stack.Screen
|
|
name="Home"
|
|
component={AllCasesMain}
|
|
options={{
|
|
header: () => null,
|
|
animation: 'slide_from_right',
|
|
animationDuration: ANIMATION_DURATION,
|
|
}}
|
|
listeners={getScreenFocusListenerObj}
|
|
/>
|
|
<Stack.Screen
|
|
name="Profile"
|
|
component={Profile}
|
|
options={{
|
|
header: () => null,
|
|
animation: 'slide_from_right',
|
|
animationDuration: ANIMATION_DURATION,
|
|
}}
|
|
listeners={getScreenFocusListenerObj}
|
|
/>
|
|
<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={'customerProfile'}
|
|
component={CustomerProfile}
|
|
options={{
|
|
header: () => null,
|
|
animationDuration: ANIMATION_DURATION,
|
|
animation: 'none',
|
|
}}
|
|
listeners={getScreenFocusListenerObj}
|
|
/>
|
|
<Stack.Screen
|
|
name={'vkycFull'}
|
|
component={VKYCFullScreen}
|
|
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}
|
|
/>
|
|
))}
|
|
<Stack.Screen
|
|
name="TodoList"
|
|
component={TodoList}
|
|
options={{
|
|
header: () => null,
|
|
animation: 'slide_from_bottom',
|
|
animationDuration: ANIMATION_DURATION,
|
|
}}
|
|
listeners={getScreenFocusListenerObj}
|
|
/>
|
|
<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,
|
|
}}
|
|
listeners={getScreenFocusListenerObj}
|
|
/>
|
|
<Stack.Screen
|
|
name="AddNewNumber"
|
|
component={AddNewNumber}
|
|
options={{
|
|
header: () => null,
|
|
animation: 'slide_from_right',
|
|
animationDuration: ANIMATION_DURATION,
|
|
}}
|
|
listeners={getScreenFocusListenerObj}
|
|
/>
|
|
<Stack.Screen
|
|
name="Notifications"
|
|
component={Notifications}
|
|
options={{
|
|
header: () => null,
|
|
animation: 'slide_from_right',
|
|
animationDuration: ANIMATION_DURATION,
|
|
}}
|
|
listeners={getScreenFocusListenerObj}
|
|
/>
|
|
</>
|
|
) : (
|
|
<>
|
|
<Stack.Screen
|
|
name="Login"
|
|
component={Login}
|
|
options={{
|
|
header: () => null,
|
|
animation: 'slide_from_right',
|
|
animationDuration: ANIMATION_DURATION,
|
|
}}
|
|
listeners={getScreenFocusListenerObj}
|
|
/>
|
|
<Stack.Screen
|
|
name="OTP"
|
|
component={OtpInput}
|
|
options={{
|
|
header: () => null,
|
|
animation: 'slide_from_right',
|
|
animationDuration: ANIMATION_DURATION,
|
|
}}
|
|
listeners={getScreenFocusListenerObj}
|
|
/>
|
|
</>
|
|
)}
|
|
</Stack.Navigator>
|
|
);
|
|
};
|
|
|
|
export default ProtectedRouter;
|