frontend/src/App.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-08-21 09:51:52 +00:00
import React, { useState } from 'react';
2020-08-19 18:04:52 +00:00
import 'rsuite/lib/styles/index.less';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
2020-08-21 09:51:52 +00:00
import { AuthContext } from './helpers/authContext';
2020-08-21 23:08:18 +00:00
import { PrivateRoute } from './components';
import {
Home,
Login,
Register,
Dashboard,
Invite,
Availability,
Schedule,
} from './screens';
2020-08-19 18:04:52 +00:00
2020-08-21 09:51:52 +00:00
const existingToken = localStorage.getItem('token');
// const existingUser = JSON.parse(localStorage.getItem('user'));
2020-08-19 18:04:52 +00:00
export default function App() {
2020-08-21 22:08:42 +00:00
const [authToken, setAuthToken] = useState(existingToken || '');
2020-08-21 09:51:52 +00:00
const setToken = (data) => {
localStorage.setItem('token', JSON.stringify(data));
setAuthToken(data);
};
2020-08-19 18:04:52 +00:00
return (
2020-08-21 09:51:52 +00:00
<AuthContext.Provider value={{ authToken, setAuthToken: setToken }}>
<Router>
<Switch>
<Route path='/' exact component={Home} />
<Route path='/login' component={Login} />
<Route path='/register' component={Register} />
<PrivateRoute path='/dashboard' component={Dashboard} />
<PrivateRoute path='/schedule' component={Schedule} />
<PrivateRoute path='/invite' component={Invite} />
<PrivateRoute
path='/availability'
component={Availability}
/>
<PrivateRoute path='/schedule' component={Schedule} />
</Switch>
</Router>
</AuthContext.Provider>
2020-08-19 18:04:52 +00:00
);
}