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-19 18:04:52 +00:00
|
|
|
|
2020-08-21 09:51:52 +00:00
|
|
|
import PrivateRoute from './components/Routes/PrivateRoute';
|
|
|
|
|
|
|
|
import Home from './screens/Home';
|
2020-08-19 18:04:52 +00:00
|
|
|
import Dashboard from './screens/Dashboard';
|
|
|
|
import Schedule from './screens/Schedule/Schedule';
|
|
|
|
import Availability from './screens/Availability/Availability';
|
|
|
|
import Invite from './screens/Invite/Invite';
|
|
|
|
import Login from './screens/Login';
|
|
|
|
import Register from './screens/Register';
|
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|