-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.tsx
More file actions
89 lines (76 loc) · 2.5 KB
/
Copy pathMain.tsx
File metadata and controls
89 lines (76 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { useEffect } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { useDispatch, useSelector } from "react-redux";
import { Text } from "react-native";
import Content from "Content";
import AppStack from "~navigators/AppStack";
import { AppDispatch } from "~store/store";
import {
clearUser,
setUser,
userSelector,
UserType,
} from "~store/user";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { getUserInfoThunk } from "~store/user/thunks";
const Main = () => {
const linking = {
config: {
screens: {
LoginScreen: "LoginScreen",
SignUp: "SignUp",
ForgotPassword: "ForgotPassword",
Home: "Home",
Types: "Types",
ICAS: "ICAS",
ExpensesTypes: "ExpensesTypes",
ExtraHours: "ExtraHours",
ManageManagerFunctions: "ManageManagerFunctions",
EditManagerInformation: "EditManagerInformation",
Delegate: "Delegate",
Employee: "Employee",
Expenses: "Expenses",
Recovery: "Recovery",
CurrentPeriod: "CurrentPeriod",
UserRoles: "UserRoles",
NotFound: '*',
}
}
};
const dispatch: AppDispatch = useDispatch()
const user = useSelector(userSelector)
const checkIfUserExists = async () => {
const token = await AsyncStorage.getItem("token")
const mail = await AsyncStorage.getItem("mail")
if (token && token != undefined && mail && mail != undefined) {
dispatch(
setUser(
{ token: token, mail: mail } as UserType
)
)
dispatch(getUserInfoThunk())
.unwrap()
.catch((error: string) => {
alert(error)
dispatch(clearUser())
})
}
}
useEffect(() => {
checkIfUserExists()
}, [])
if (!user.token || !user.mail)
return (
// @ts-ignore
<NavigationContainer linking={linking} fallback={<Text>Loading...</Text>}>
<AppStack/>
</NavigationContainer>
)
return (
// @ts-ignore
<NavigationContainer linking={linking} fallback={<Text>Loading...</Text>}>
<Content />
</NavigationContainer>
)
};
export default Main;