forked from Jacenty00/tagify-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
82 lines (75 loc) · 2.25 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import { createMuiTheme, CssBaseline, ThemeProvider } from "@material-ui/core";
import { App as GuestApp } from "./components/guest/App";
import { Impressum } from "./components/Impressum";
import { App as UserApp } from "./components/user/App";
import { raleway200, raleway300 } from "./fonts/Fonts";
import BackendToken, { Default, Status, UserRole } from "./utils/BackendAPI";
const theme = createMuiTheme({
palette: {
primary: {
main: "#dcedc8",
light: "#fffffb",
dark: "#aabb97",
contrastText: "#000000",
},
secondary: {
main: "#d9c8ed",
light: "#fffbff",
dark: "#a797bb",
contrastText: "#000000",
},
},
typography: {
fontFamily: "Raleway",
fontSize: 17,
fontWeightLight: 200,
fontWeightRegular: 300,
fontWeightMedium: 300,
},
overrides: {
MuiCssBaseline: {
"@global": {
"@font-face": [raleway200, raleway300],
},
},
},
});
function App() {
const [render, setRender] = useState<boolean>(false);
useEffect(() => {
(async () => {
let response = await Default.getUser();
let code = response.status;
let role: UserRole | undefined = response.data?.role;
BackendToken.authenticated = code == Status.Ok;
BackendToken.userRole = role;
BackendToken.nickname =
response.data == undefined ? "" : response.data.nickname;
if (BackendToken.userRole == UserRole.Admin)
window.location.replace("/admin");
setRender(true);
})();
}, []);
return (
<div>
{render && (
<BrowserRouter>
<ThemeProvider theme={theme}>
<CssBaseline />
<Switch>
<Route path="/welcome" component={GuestApp} />
<Route path="/login" component={GuestApp} />
<Route path="/impressum" component={Impressum} />
<Route path="/*" component={UserApp} />
<Route path="*" component={() => "404 NOT FOUND"} />
</Switch>
</ThemeProvider>
</BrowserRouter>
)}
</div>
);
}
ReactDOM.render(<App />, document.getElementById("app"));