DocSpace-buildtools/web/ASC.Web.Client/src/App.js

133 lines
3.8 KiB
JavaScript
Raw Normal View History

import React, { Suspense, lazy } from "react";
import { Router, Route, Switch } from "react-router-dom";
import { connect } from "react-redux";
// import {
// Login,
// Error404,
// Offline,
// ComingSoon
// } from "@appserver/common";
import CommonStore from "@appserver/common/src/store";
import history from "@appserver/common/src/history";
import PrivateRoute from "@appserver/common/src/components/PrivateRoute";
import PublicRoute from "@appserver/common/src/components/PublicRoute";
import NavMenu from "@appserver/common/src/components/NavMenu";
import Main from "@appserver/common/src/components/Main";
Merge branch 'develop' into feature/workspaces # Conflicts: # packages/asc-web-common/src/components/FilterInput/FilterInput.js # packages/asc-web-common/src/components/FilterInput/sub-components/SortComboBox.js # packages/asc-web-common/src/components/PageLayout/index.js # packages/asc-web-common/src/components/PageLayout/sub-components/article-body.js # packages/asc-web-common/src/components/PageLayout/sub-components/article-header.js # packages/asc-web-common/src/components/PageLayout/sub-components/article-main-button.js # packages/asc-web-common/src/components/PageLayout/sub-components/section-body.js # packages/asc-web-common/src/components/PageLayout/sub-components/section-header.js # packages/asc-web-common/src/components/PrivateRoute/PrivateRoute.js # products/ASC.Files/Client/package.json # products/ASC.Files/Client/src/components/Article/Body/TreeFolders.js # products/ASC.Files/Client/src/components/pages/DocEditor/index.js # products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js # products/ASC.Files/Client/src/components/panels/OperationsPanel/index.js # products/ASC.Files/Client/src/components/panels/SharingPanel/SharingRow.js # products/ASC.Files/Client/src/components/panels/SharingPanel/index.js # products/ASC.Files/Client/src/index.js # products/ASC.Files/Client/src/store/files/actions.js # products/ASC.Files/Client/yarn.lock # products/ASC.People/Client/package.json # products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/ContactField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/DateField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/EmailField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/RadioField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/TextChangeField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/TextField.js # products/ASC.People/Client/src/index.js # products/ASC.People/Client/yarn.lock # web/ASC.Web.Client/package.json # web/ASC.Web.Client/src/App.js # web/ASC.Web.Client/src/components/pages/Confirm/index.js # web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateEmail.js # web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeEmail.js # web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeOwner.js # web/ASC.Web.Client/src/helpers/confirmRoute.js # web/ASC.Web.Client/src/index.js # web/ASC.Web.Common/package.json # web/ASC.Web.Common/yarn.lock # web/ASC.Web.Components/package.json # web/ASC.Web.Components/yarn.lock # web/ASC.Web.Login/src/LoginContent.jsx # web/ASC.Web.Login/src/sub-components/register-container.js # yarn.lock
2020-12-15 15:40:27 +00:00
import utils from "@appserver/common/src/utils";
import toastr from "@appserver/common/src/components/Toast/toastr";
import Home from "./components/pages/Home";
const About = lazy(() => import("./components/pages/About"));
const Confirm = lazy(() => import("./components/pages/Confirm"));
const Settings = lazy(() => import("./components/pages/Settings"));
const Wizard = lazy(() => import("./components/pages/Wizard"));
const Payments = lazy(() => import("./components/pages/Payments"));
const {
setIsLoaded,
getUser,
getPortalSettings,
getModules,
2020-12-07 08:11:04 +00:00
getIsAuthenticated,
} = CommonStore.auth.actions;
class App extends React.Component {
componentDidMount() {
2020-12-04 08:38:15 +00:00
const {
getPortalSettings,
getUser,
getModules,
setIsLoaded,
2020-12-07 08:11:04 +00:00
getIsAuthenticated,
2020-12-04 08:38:15 +00:00
} = this.props;
2020-12-04 11:21:51 +00:00
getIsAuthenticated()
2020-12-07 08:11:04 +00:00
.then((isAuthenticated) => {
if (isAuthenticated) utils.updateTempContent(isAuthenticated);
const requests = [];
2020-12-07 08:11:04 +00:00
if (!isAuthenticated) {
requests.push(getPortalSettings());
2020-12-07 08:11:04 +00:00
} else if (
!window.location.pathname.includes("confirm/EmailActivation")
) {
requests.push(getUser());
requests.push(getPortalSettings());
requests.push(getModules());
}
Promise.all(requests)
.catch((e) => {
toastr.error(e);
})
.finally(() => {
2020-12-07 08:11:04 +00:00
utils.updateTempContent();
setIsLoaded();
});
2020-12-07 08:11:04 +00:00
})
.catch((err) => toastr.error(err));
}
render() {
return navigator.onLine ? (
<Router history={history}>
<NavMenu />
<Main>
<Suspense fallback={null}>
<Switch>
<Route exact path="/wizard" component={Wizard} />
<PublicRoute
exact
path={[
"/login",
"/login/error=:error",
"/login/confirmed-email=:confirmedEmail",
]}
component={Login}
/>
<Route path="/confirm" component={Confirm} />
<PrivateRoute
exact
path={["/", "/error=:error"]}
component={Home}
/>
<PrivateRoute exact path="/about" component={About} />
<PrivateRoute restricted path="/settings" component={Settings} />
<PrivateRoute
exact
path={["/coming-soon"]}
component={ComingSoon}
/>
<PrivateRoute path="/payments" component={Payments} />
<PrivateRoute component={Error404} />
</Switch>
</Suspense>
</Main>
</Router>
) : (
<Offline />
);
}
}
const mapStateToProps = (state) => {
const { modules, isLoaded, settings } = state.auth;
const { organizationName } = settings;
return {
modules,
isLoaded,
organizationName,
};
};
const mapDispatchToProps = (dispatch) => {
return {
2020-12-04 08:38:15 +00:00
getIsAuthenticated: () => getIsAuthenticated(dispatch),
getPortalSettings: () => getPortalSettings(dispatch),
getUser: () => getUser(dispatch),
getModules: () => getModules(dispatch),
setIsLoaded: () => dispatch(setIsLoaded(true)),
};
};
export default connect(mapStateToProps, mapDispatchToProps)(App);