merge signup process
This commit is contained in:
@@ -12,7 +12,7 @@ import NavigationString from '../../Constant/NavigationString';
|
||||
// Navigation type
|
||||
export type Navigation = {
|
||||
reset(arg0: {
|
||||
index: number;
|
||||
index: number;
|
||||
routes: { name: string; }[];
|
||||
}): unknown;
|
||||
navigate: (route: string, params?: { [key: string]: any }) => void;
|
||||
@@ -29,12 +29,11 @@ const Splash: React.FC = () => {
|
||||
const [isHydrated, setIsHydrated] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
// Wait for Redux hydration (works with/without redux-persist)
|
||||
useEffect(() => {
|
||||
let unsubscribe: any;
|
||||
const checkHydration = () => {
|
||||
const token = (store.getState() as any).token?.token;
|
||||
if (token !== undefined) { // Defined = hydrated (null/empty/string ok)
|
||||
if (token !== undefined) {
|
||||
setIsHydrated(true);
|
||||
unsubscribe?.();
|
||||
}
|
||||
@@ -46,23 +45,11 @@ const Splash: React.FC = () => {
|
||||
return () => unsubscribe?.();
|
||||
}, []);
|
||||
|
||||
const getToken = useCallback(async (): Promise<string | null> => {
|
||||
try {
|
||||
// Redux first (post-hydration), then AsyncStorage fallback
|
||||
let token = reduxToken;
|
||||
if (token === undefined) {
|
||||
token = await AsyncStorage.getItem('token');
|
||||
}
|
||||
return token || null;
|
||||
} catch (error) {
|
||||
console.error('Token fetch error:', error);
|
||||
return null;
|
||||
}
|
||||
}, [reduxToken]);
|
||||
|
||||
|
||||
const routeByOrgType = (params: { otherId: any; orgType: any }) => {
|
||||
const orgType = String(params.orgType);
|
||||
console.log("hitting here ")
|
||||
console.log("hitting here ")
|
||||
if (orgType === '4' || orgType === '5' || orgType === '6') {
|
||||
navigation.replace('StageThree', params);
|
||||
return;
|
||||
@@ -138,22 +125,25 @@ const Splash: React.FC = () => {
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
|
||||
const token = await getToken();
|
||||
console.log("Token after hydration -", token, typeof token, !!token);
|
||||
|
||||
if (!token) {
|
||||
console.log('No valid token, navigating to Login');
|
||||
if (!reduxToken.token) {
|
||||
navigation.reset({
|
||||
index: 0,
|
||||
routes: [{ name: NavigationString.Login || 'Signin' }], // Fallback
|
||||
routes: [{ name: NavigationString.Login }],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Valid token, fetching registration data');
|
||||
await handleGetData();
|
||||
if (reduxToken.userType == 'tender') {
|
||||
await handleGetData();
|
||||
} else {
|
||||
navigation.reset({
|
||||
index: 0,
|
||||
routes: [{ name: NavigationString.Home }],
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Splash Error:', error);
|
||||
navigation.reset({
|
||||
index: 0,
|
||||
routes: [{ name: NavigationString.Login || 'Signin' }],
|
||||
@@ -163,10 +153,9 @@ const Splash: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Small delay ensures hydration + native animation complete
|
||||
const timeoutId = setTimeout(runSplash, 200);
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [isFocused, isHydrated, getToken]);
|
||||
}, [isFocused, isHydrated]);
|
||||
|
||||
if (!isHydrated) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user