Last change
on this file since 0c049e9 was 3a58bd6, checked in by Viktor <39170279+Tasevski2@…>, 3 years ago |
Added Frontend
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[3a58bd6] | 1 | import './App.css';
|
---|
| 2 | import { Route, Switch, Redirect } from 'react-router-dom';
|
---|
| 3 |
|
---|
| 4 | import DestinationComponent from './utils/DestinationComponent';
|
---|
| 5 |
|
---|
| 6 | import AdminHomeScreen from './screens/AdminHomeScreen';
|
---|
| 7 | import LoginScreenImported from './screens/LoginScreen';
|
---|
| 8 |
|
---|
| 9 | import { roles } from './config/enums';
|
---|
| 10 |
|
---|
| 11 | const LoginScreen = new DestinationComponent('/', LoginScreenImported, true);
|
---|
| 12 | const AdminEmployeeHomeScreen = new DestinationComponent('/', AdminHomeScreen);
|
---|
| 13 | // const UserHomeScreen = new DestinationComponent('/', UserHomeScreen); TODO
|
---|
| 14 |
|
---|
| 15 | const publicRoutes = [LoginScreen];
|
---|
| 16 |
|
---|
| 17 | const userRoutes = [
|
---|
| 18 | // UserHomeScreen
|
---|
| 19 | ];
|
---|
| 20 |
|
---|
| 21 | const adminAndEmployeeRoutes = [AdminEmployeeHomeScreen];
|
---|
| 22 |
|
---|
| 23 | function App(props) {
|
---|
| 24 | const user = {
|
---|
| 25 | role: 'ROLE_ADMIN',
|
---|
| 26 | };
|
---|
| 27 |
|
---|
| 28 | // const user = null;
|
---|
| 29 |
|
---|
| 30 | let routes = publicRoutes;
|
---|
| 31 | if (user) {
|
---|
| 32 | switch (user.role) {
|
---|
| 33 | case roles.user:
|
---|
| 34 | routes = userRoutes;
|
---|
| 35 | break;
|
---|
| 36 | case roles.admin:
|
---|
| 37 | case roles.employee:
|
---|
| 38 | routes = adminAndEmployeeRoutes;
|
---|
| 39 | break;
|
---|
| 40 | default:
|
---|
| 41 | break;
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 | console.log(publicRoutes);
|
---|
| 45 | return (
|
---|
| 46 | <Switch>
|
---|
| 47 | {routes?.map((route, index) => (
|
---|
| 48 | <Route key={index} path={route.path} component={route.component} />
|
---|
| 49 | ))}
|
---|
| 50 | <Redirect to='/' />
|
---|
| 51 | </Switch>
|
---|
| 52 | );
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | export default App;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.