-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
58 lines (53 loc) · 1.68 KB
/
App.tsx
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
import React, { useCallback, useEffect } from "react";
import AppRouter from "./routes/AppRouter";
import { getCookieValue } from "./utils/cookie";
import useCluster from "./utils/hooks/useCluster";
import useUser from "./utils/hooks/useUser";
import { version } from "../package.json";
import { formatLunchTime, formatOfficeHours } from "./utils/time";
import { getClusterUsingInfo, getConfigInfo } from "./api/configAPI";
const App = () => {
const { setCluster, setOfficeHour, setOfficeLunchTime } = useCluster();
const { login, logout } = useUser();
const getConfig = useCallback(async () => {
try {
const [
{
data: {
payload: { open_at, close_at, seocho: seochoLimitation, gaepo: gaepoLimitation },
},
},
{
data: {
payload: { gaepo, seocho },
},
},
] = await Promise.all([getConfigInfo(), getClusterUsingInfo()]);
setCluster({
openAt: open_at,
closeAt: close_at,
seochoLimitation,
gaepoLimitation,
gaepo,
seocho,
});
setOfficeHour({ officeHour: formatOfficeHours({ openAt: open_at, closeAt: close_at }) });
setOfficeLunchTime({ officeLunchTime: formatLunchTime(new Date().toString()) });
} catch (err) {
console.log(err);
throw err;
}
}, [setCluster, setOfficeHour, setOfficeLunchTime]);
useEffect(() => {
if (getCookieValue(process.env.REACT_APP_AUTH_KEY)) login();
else logout();
getConfig();
}, [getConfig, login, logout]);
return (
<main className='wrapper'>
<AppRouter />
<footer className='footer'>v{version}</footer>
</main>
);
};
export default App;