updated code with dsc and device binding

This commit is contained in:
Abin Toppo
2026-05-08 13:39:41 +05:30
parent c1ecc97e29
commit 66461370a2
120 changed files with 11910 additions and 8347 deletions
+36 -60
View File
@@ -1,9 +1,8 @@
import React, { useEffect, useRef, useState, useCallback } from 'react';
import React, { useCallback, useEffect, useRef } from 'react';
import { Animated, StyleSheet, View } from 'react-native';
import { useNavigation, useIsFocused } from '@react-navigation/native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { useSelector } from 'react-redux';
import { useStore } from 'react-redux'; // For hydration check
import { showToast } from '../../Constant/ShowDailog';
import { useRagistrationState } from '../../Services/ApiCall/Hooks';
@@ -24,37 +23,13 @@ const Splash: React.FC = () => {
const isFocused = useIsFocused();
const fadeAnim = useRef(new Animated.Value(0)).current;
const reduxToken = useSelector((state: any) => state.token?.token);
const store = useStore();
const isPersistRehydrated = useSelector((state: any) => state?._persist?.rehydrated);
const { mutateAsync: registrationStateMutate } = useRagistrationState();
const [isHydrated, setIsHydrated] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const hasSessionToken = Boolean(reduxToken && typeof reduxToken === 'object' && reduxToken.token);
useEffect(() => {
let unsubscribe: any;
const checkHydration = () => {
const token = (store.getState() as any).token?.token;
if (token !== undefined) {
setIsHydrated(true);
unsubscribe?.();
}
};
unsubscribe = store.subscribe(checkHydration);
checkHydration(); // Check immediately
return () => unsubscribe?.();
}, []);
const routeByOrgType = (params: { otherId: any; orgType: any }) => {
// const orgType = params.orgType;
const orgType = "7" as string; // For testing purpose
const routeByOrgType = useCallback((params: { otherId: any; orgType: any }) => {
const orgType = String(params.orgType ?? '');
if (orgType === '4' || orgType === '5' || orgType === '6') {
navigation.replace(NavigationString.StageThreeScreen, params);
return;
}
@@ -65,28 +40,35 @@ const Splash: React.FC = () => {
}
navigation.replace('Dashboard');
};
}, [navigation]);
const handleGetData = async () => {
const handleGetData = useCallback(async () => {
try {
const res = await registrationStateMutate();
console.log("splash", res);
if (res?.status === false) {
navigation.reset({
index: 0,
routes: [{ name: NavigationString.Login }],
});
return;
}
if ( res?.data?.message==="No Response From Server"&& res?.data?.success===false){
navigation.reset({
index: 0,
routes: [{ name: NavigationString.Login }],
});
return
if (res?.data?.message === 'No Response From Server' && res?.data?.success === false) {
navigation.reset({
index: 0,
routes: [{ name: NavigationString.Login }],
});
return;
}
if (res?.statusCode === 404 || res?.statusCode === 401) {
navigation.replace('Registration');
return;
}
if (res?.statusCode === 404 || res?.statusCode === 401) {
navigation.replace('Registration');
return;
}
if (res?.statusCode === 200 && res?.data) {
const { registrationStatus, contOtherId, contOrganization } = res.data;
const params = { otherId: contOtherId, orgType: contOrganization };
switch (registrationStatus) {
case null:
case undefined:
@@ -115,18 +97,19 @@ const Splash: React.FC = () => {
if (error?.response?.status === 404) {
navigation.replace('Registration');
} else {
await AsyncStorage.removeItem('token');
navigation.replace('Signin');
await AsyncStorage.removeItem('persist:root');
navigation.replace(NavigationString.Login);
}
}
};
}, [navigation, registrationStateMutate, routeByOrgType]);
useEffect(() => {
if (!isFocused || !isHydrated) return;
if (!isFocused || !isPersistRehydrated) {
return;
}
const runSplash = async () => {
try {
setIsLoading(true);
Animated.timing(fadeAnim, {
toValue: 1,
duration: 500,
@@ -134,7 +117,7 @@ const Splash: React.FC = () => {
}).start();
if (!reduxToken.token) {
if (!hasSessionToken) {
navigation.reset({
index: 0,
routes: [{ name: NavigationString.Login }],
@@ -142,7 +125,7 @@ const Splash: React.FC = () => {
return;
}
if (reduxToken.userType == 'tender') {
if (reduxToken.userType === 'tender') {
await handleGetData();
} else {
navigation.reset({
@@ -154,18 +137,16 @@ const Splash: React.FC = () => {
} catch (error) {
navigation.reset({
index: 0,
routes: [{ name: NavigationString.Login || 'Signin' }],
routes: [{ name: NavigationString.Login }],
});
} finally {
setIsLoading(false);
}
};
const timeoutId = setTimeout(runSplash, 200);
return () => clearTimeout(timeoutId);
}, [isFocused, isHydrated]);
}, [fadeAnim, handleGetData, hasSessionToken, isFocused, isPersistRehydrated, navigation, reduxToken?.userType]);
if (!isHydrated) {
if (!isPersistRehydrated) {
return (
<View style={styles.loadingContainer}>
<Animated.Image
@@ -185,11 +166,6 @@ const Splash: React.FC = () => {
style={[styles.logo, { opacity: fadeAnim }]}
resizeMode="contain"
/>
{isLoading && (
<View style={{ marginTop: 20 }}>
{/* Optional spinner */}
</View>
)}
</View>
</View>
);