2021-06-17 13:42:03 +07:00
|
|
|
import React, { useState, useEffect } from "react";
|
2021-01-02 17:58:24 +07:00
|
|
|
|
|
|
|
import { config as faConfig } from "@fortawesome/fontawesome-svg-core";
|
2021-01-20 19:07:40 +07:00
|
|
|
import { CssBaseline, ThemeProvider } from "@material-ui/core";
|
2021-01-02 17:58:24 +07:00
|
|
|
import { BrowserRouter as Router, Route, Switch, Redirect } from "react-router-dom";
|
|
|
|
|
|
|
|
import NotificationBar from "./components/NotificationBar";
|
|
|
|
import NotificationsContext from "./hooks/NotificationsContext";
|
|
|
|
import { Notification } from "./models/Notifications";
|
2019-11-19 06:37:36 +07:00
|
|
|
import {
|
2021-01-02 17:58:24 +07:00
|
|
|
FirstFactorRoute,
|
|
|
|
ResetPasswordStep2Route,
|
|
|
|
ResetPasswordStep1Route,
|
|
|
|
RegisterSecurityKeyRoute,
|
2019-11-19 06:37:36 +07:00
|
|
|
RegisterOneTimePasswordRoute,
|
|
|
|
LogoutRoute,
|
2021-05-05 05:06:05 +07:00
|
|
|
ConsentRoute,
|
2019-11-19 06:37:36 +07:00
|
|
|
} from "./Routes";
|
2021-01-20 19:07:40 +07:00
|
|
|
import * as themes from "./themes";
|
2021-01-02 17:58:24 +07:00
|
|
|
import { getBasePath } from "./utils/BasePath";
|
2021-01-20 19:07:40 +07:00
|
|
|
import { getRememberMe, getResetPassword, getTheme } from "./utils/Configuration";
|
2021-01-02 17:58:24 +07:00
|
|
|
import RegisterOneTimePassword from "./views/DeviceRegistration/RegisterOneTimePassword";
|
|
|
|
import RegisterSecurityKey from "./views/DeviceRegistration/RegisterSecurityKey";
|
2021-05-05 05:06:05 +07:00
|
|
|
import ConsentView from "./views/LoginPortal/ConsentView/ConsentView";
|
2021-01-02 17:58:24 +07:00
|
|
|
import LoginPortal from "./views/LoginPortal/LoginPortal";
|
|
|
|
import SignOut from "./views/LoginPortal/SignOut/SignOut";
|
|
|
|
import ResetPasswordStep1 from "./views/ResetPassword/ResetPasswordStep1";
|
|
|
|
import ResetPasswordStep2 from "./views/ResetPassword/ResetPasswordStep2";
|
|
|
|
|
|
|
|
import "@fortawesome/fontawesome-svg-core/styles.css";
|
2020-04-26 05:12:55 +07:00
|
|
|
|
|
|
|
faConfig.autoAddCss = false;
|
2019-11-19 06:37:36 +07:00
|
|
|
|
2021-01-20 19:07:40 +07:00
|
|
|
function Theme() {
|
|
|
|
switch (getTheme()) {
|
|
|
|
case "dark":
|
|
|
|
return themes.Dark;
|
|
|
|
case "grey":
|
|
|
|
return themes.Grey;
|
2021-06-17 13:42:03 +07:00
|
|
|
case "auto":
|
|
|
|
return window.matchMedia("(prefers-color-scheme: dark)").matches ? themes.Dark : themes.Light;
|
2021-01-20 19:07:40 +07:00
|
|
|
default:
|
|
|
|
return themes.Light;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 06:37:36 +07:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [notification, setNotification] = useState(null as Notification | null);
|
2021-06-17 13:42:03 +07:00
|
|
|
const [theme, setTheme] = useState(Theme());
|
|
|
|
useEffect(() => {
|
|
|
|
if (getTheme() === "auto") {
|
|
|
|
const query = window.matchMedia("(prefers-color-scheme: dark)");
|
|
|
|
// MediaQueryLists does not inherit from EventTarget in Internet Explorer
|
|
|
|
if (query.addEventListener) {
|
|
|
|
query.addEventListener("change", (e) => {
|
|
|
|
setTheme(e.matches ? themes.Dark : themes.Light);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, []);
|
2019-11-19 06:37:36 +07:00
|
|
|
return (
|
2021-06-17 13:42:03 +07:00
|
|
|
<ThemeProvider theme={theme}>
|
2021-01-20 19:07:40 +07:00
|
|
|
<CssBaseline />
|
|
|
|
<NotificationsContext.Provider value={{ notification, setNotification }}>
|
|
|
|
<Router basename={getBasePath()}>
|
|
|
|
<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>
|
2021-05-05 05:06:05 +07:00
|
|
|
<Route path={ConsentRoute} exact>
|
|
|
|
<ConsentView />
|
|
|
|
</Route>
|
2021-01-20 19:07:40 +07:00
|
|
|
<Route path={FirstFactorRoute}>
|
|
|
|
<LoginPortal rememberMe={getRememberMe()} resetPassword={getResetPassword()} />
|
|
|
|
</Route>
|
|
|
|
<Route path="/">
|
|
|
|
<Redirect to={FirstFactorRoute} />
|
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
</Router>
|
|
|
|
</NotificationsContext.Provider>
|
|
|
|
</ThemeProvider>
|
2019-11-19 06:37:36 +07:00
|
|
|
);
|
2021-01-02 17:58:24 +07:00
|
|
|
};
|
2019-11-19 06:37:36 +07:00
|
|
|
|
|
|
|
export default App;
|