2019-12-07 23:40:42 +07:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2019-11-19 06:37:36 +07:00
|
|
|
import {
|
|
|
|
BrowserRouter as Router, Route, Switch, Redirect
|
|
|
|
} from "react-router-dom";
|
|
|
|
import ResetPasswordStep1 from './views/ResetPassword/ResetPasswordStep1';
|
|
|
|
import ResetPasswordStep2 from './views/ResetPassword/ResetPasswordStep2';
|
|
|
|
import RegisterSecurityKey from './views/DeviceRegistration/RegisterSecurityKey';
|
|
|
|
import RegisterOneTimePassword from './views/DeviceRegistration/RegisterOneTimePassword';
|
|
|
|
import {
|
|
|
|
FirstFactorRoute, ResetPasswordStep2Route,
|
|
|
|
ResetPasswordStep1Route, RegisterSecurityKeyRoute,
|
|
|
|
RegisterOneTimePasswordRoute,
|
|
|
|
LogoutRoute,
|
|
|
|
} from "./Routes";
|
|
|
|
import LoginPortal from './views/LoginPortal/LoginPortal';
|
|
|
|
import NotificationsContext from './hooks/NotificationsContext';
|
|
|
|
import { Notification } from './models/Notifications';
|
|
|
|
import NotificationBar from './components/NotificationBar';
|
|
|
|
import SignOut from './views/LoginPortal/SignOut/SignOut';
|
2019-12-07 23:40:42 +07:00
|
|
|
import { useConfiguration } from './hooks/Configuration';
|
|
|
|
import Tracker from "./components/Tracker";
|
|
|
|
import { useTracking } from "./hooks/Tracking";
|
2019-11-19 06:37:36 +07:00
|
|
|
|
|
|
|
const App: React.FC = () => {
|
|
|
|
const [notification, setNotification] = useState(null as Notification | null);
|
2019-12-07 23:40:42 +07:00
|
|
|
const [configuration, fetchConfig, , fetchConfigError] = useConfiguration();
|
|
|
|
const tracker = useTracking(configuration);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (fetchConfigError) {
|
|
|
|
console.error(fetchConfigError);
|
|
|
|
}
|
|
|
|
}, [fetchConfigError]);
|
|
|
|
|
|
|
|
useEffect(() => { fetchConfig() }, [fetchConfig]);
|
|
|
|
|
2019-11-19 06:37:36 +07:00
|
|
|
return (
|
|
|
|
<NotificationsContext.Provider value={{ notification, setNotification }} >
|
|
|
|
<Router>
|
2019-12-07 23:40:42 +07:00
|
|
|
<Tracker tracker={tracker}>
|
|
|
|
<NotificationBar onClose={() => setNotification(null)} />
|
|
|
|
<Switch>
|
|
|
|
<Route path={ResetPasswordStep1Route} exact>
|
|
|
|
<ResetPasswordStep1 />
|
|
|
|
</Route>
|
|
|
|
<Route path={ResetPasswordStep2Route} exact>
|
|
|
|
<ResetPasswordStep2 />
|
|
|
|
</Route>
|
|
|
|
<Route path={RegisterSecurityKeyRoute} exact>
|
|
|
|
<RegisterSecurityKey />
|
|
|
|
</Route>
|
|
|
|
<Route path={RegisterOneTimePasswordRoute} exact>
|
|
|
|
<RegisterOneTimePassword />
|
|
|
|
</Route>
|
|
|
|
<Route path={LogoutRoute} exact>
|
|
|
|
<SignOut />
|
|
|
|
</Route>
|
|
|
|
<Route path={FirstFactorRoute}>
|
2020-04-05 06:28:09 +07:00
|
|
|
<LoginPortal
|
|
|
|
rememberMe={configuration?.remember_me === true}
|
|
|
|
resetPassword={configuration?.reset_password === true} />
|
2019-12-07 23:40:42 +07:00
|
|
|
</Route>
|
|
|
|
<Route path="/">
|
|
|
|
<Redirect to={FirstFactorRoute}></Redirect>
|
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
</Tracker>
|
2019-11-19 06:37:36 +07:00
|
|
|
</Router>
|
|
|
|
</NotificationsContext.Provider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|