From 203e02e931528a4d14c790680f60bb96985c1634 Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Thu, 4 Feb 2021 16:24:30 +0300 Subject: [PATCH 01/12] web: people: add People store models --- products/ASC.People/Client/src/App.js | 33 ++++++------ products/ASC.People/Client/src/index.js | 3 +- .../Client/src/store/GroupsStore.js | 20 ++++++++ .../Client/src/store/PeopleStore.js | 50 +++++++++++++++++++ .../ASC.People/Client/src/store/UsersStore.js | 27 ++++++++++ products/ASC.People/Client/src/store/index.js | 5 +- 6 files changed, 120 insertions(+), 18 deletions(-) create mode 100644 products/ASC.People/Client/src/store/GroupsStore.js create mode 100644 products/ASC.People/Client/src/store/PeopleStore.js create mode 100644 products/ASC.People/Client/src/store/UsersStore.js diff --git a/products/ASC.People/Client/src/App.js b/products/ASC.People/Client/src/App.js index 8d8b35ca50..3b380a2d7b 100644 --- a/products/ASC.People/Client/src/App.js +++ b/products/ASC.People/Client/src/App.js @@ -56,8 +56,8 @@ class App extends React.Component { setIsLoaded, getIsAuthenticated, loadBaseInfo, + loadBasePeopleInfo, } = this.props; - try { const isAuthenticated = await getIsAuthenticated(); @@ -181,18 +181,18 @@ const mapDispatchToProps = (dispatch) => { //getModules: () => getModules(dispatch), getPortalPasswordSettings: () => getPortalPasswordSettings(dispatch), getPortalCultures: () => getPortalCultures(dispatch), - fetchGroups: () => fetchGroups(dispatch), - fetchPeople: () => { - var re = new RegExp(`${config.homepage}((/?)$|/filter)`, "gm"); - const match = window.location.pathname.match(re); + // fetchGroups: () => fetchGroups(dispatch), + // fetchPeople: () => { + // var re = new RegExp(`${config.homepage}((/?)$|/filter)`, "gm"); + // const match = window.location.pathname.match(re); - if (match && match.length > 0) { - const newFilter = getFilterByLocation(window.location); - return fetchPeople(newFilter, dispatch); - } + // if (match && match.length > 0) { + // const newFilter = getFilterByLocation(window.location); + // return fetchPeople(newFilter, dispatch); + // } - return Promise.resolve(); - }, + // return Promise.resolve(); + // }, setIsLoaded: () => dispatch(setIsLoaded(true)), }; }; @@ -211,12 +211,17 @@ export default connect( null, mapDispatchToProps )( - inject(({ store }) => ({ + inject(({ store, peopleStore }) => ({ user: store.userStore.user, isAuthenticated: store.userStore.isAuthenticated, getUser: store.userStore.setCurrentUser, homepage: store.settingsStore.homepage || config.homepage, encryptionKeys: store.settingsStore.encryptionKeys, - loadBaseInfo: store.init, - }))(App) + loadBaseInfo: () => { + store.init(); + peopleStore.init(); + }, + + // loadBasePeopleInfo: peopleStore.init, + }))(observer(App)) ); diff --git a/products/ASC.People/Client/src/index.js b/products/ASC.People/Client/src/index.js index 1a1e9d97c0..760934e9a2 100644 --- a/products/ASC.People/Client/src/index.js +++ b/products/ASC.People/Client/src/index.js @@ -7,12 +7,13 @@ import App from "./App"; import * as serviceWorker from "./serviceWorker"; import { ErrorBoundary, store as commonStore } from "asc-web-common"; import { Provider as MobxProvider } from "mobx-react"; +import { peopleStore } from "./store/"; const { authStore } = commonStore; ReactDOM.render( - + diff --git a/products/ASC.People/Client/src/store/GroupsStore.js b/products/ASC.People/Client/src/store/GroupsStore.js new file mode 100644 index 0000000000..4e6b4cfe2f --- /dev/null +++ b/products/ASC.People/Client/src/store/GroupsStore.js @@ -0,0 +1,20 @@ +import { action, makeObservable, observable } from "mobx"; +import { api } from "asc-web-common"; + +class GroupsStore { + groups = null; + + constructor() { + makeObservable(this, { + groups: observable, + getGroupList: action, + }); + } + + getGroupList = async () => { + const res = await api.groups.getGroupList(); + this.groups = res; + }; +} + +export default GroupsStore; diff --git a/products/ASC.People/Client/src/store/PeopleStore.js b/products/ASC.People/Client/src/store/PeopleStore.js new file mode 100644 index 0000000000..25174b8341 --- /dev/null +++ b/products/ASC.People/Client/src/store/PeopleStore.js @@ -0,0 +1,50 @@ +import { action, computed, makeObservable, observable } from "mobx"; +// import api from "../api"; +// import history from "../history"; +// import ModuleStore from "./ModuleStore"; +// import SettingsStore from "./SettingsStore"; +import GroupsStore from "./GroupsStore"; +import UsersStore from "./UsersStore"; +import { getFilterByLocation } from "../helpers/converters"; +import config from "../../package.json"; + +class PeopleStore { + groupsStore = null; + usersStore = null; + + isLoading = false; + //isAuthenticated = false; + + constructor() { + this.setGroupsStore(new GroupsStore()); + this.setUsersStore(new UsersStore()); + + makeObservable(this, { + isLoading: observable, + setGroupsStore: action, + setUsersStore: action, + init: action, + }); + } + + init = async () => { + const re = new RegExp(`${config.homepage}((/?)$|/filter)`, "gm"); + const match = window.location.pathname.match(re); + + if (match && match.length > 0) { + const newFilter = getFilterByLocation(window.location); + await this.usersStore.getUsersList(newFilter); + } + await this.groupsStore.getGroupList(); + //await this.usersStore.getUsersList(); + }; + + setGroupsStore = (store) => { + this.groupsStore = store; + }; + setUsersStore = (store) => { + this.usersStore = store; + }; +} + +export default new PeopleStore(); diff --git a/products/ASC.People/Client/src/store/UsersStore.js b/products/ASC.People/Client/src/store/UsersStore.js new file mode 100644 index 0000000000..e6d7cb7621 --- /dev/null +++ b/products/ASC.People/Client/src/store/UsersStore.js @@ -0,0 +1,27 @@ +import { action, makeObservable, observable } from "mobx"; +import { getFilterByLocation } from "../helpers/converters"; +import { api } from "asc-web-common"; + +const { Filter } = api; + +class UsersStore { + users = null; + + constructor() { + makeObservable(this, { + users: observable, + getUsersList: action, + }); + } + + getUsersList = async (filter) => { + let filterData = filter && filter.clone(); + if (!filterData) { + filterData = Filter.getDefault(); + } + const res = await api.people.getListAdmins(filterData); + this.users = res; + }; +} + +export default UsersStore; diff --git a/products/ASC.People/Client/src/store/index.js b/products/ASC.People/Client/src/store/index.js index 28cb32a884..0509faaaaa 100644 --- a/products/ASC.People/Client/src/store/index.js +++ b/products/ASC.People/Client/src/store/index.js @@ -1,5 +1,4 @@ import { store } from "asc-web-common"; -const { moduleStore } = store.moduleStore; -const { settingsStore } = store.settingsStore; +import peopleStore from "./PeopleStore"; -export { moduleStore, settingsStore}; +export { store, peopleStore }; From 4f13f83a814ae8ade8bdf06b19b40adf7dc1e7dc Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Thu, 4 Feb 2021 18:18:17 +0300 Subject: [PATCH 02/12] web: people: replace isLoading to MobX prop --- .../Client/src/components/Article/Body/index.js | 13 +++++++++---- .../src/components/Article/MainButton/index.js | 3 ++- .../pages/GroupAction/Section/Body/index.js | 3 ++- .../src/components/pages/Home/Section/Body/index.js | 3 ++- .../components/pages/Home/Section/Filter/index.js | 3 ++- .../components/pages/Home/Section/Header/index.js | 3 ++- .../components/pages/Home/Section/Paging/index.js | 9 +++++++-- .../Client/src/components/pages/Home/index.js | 7 +++++-- .../Client/src/components/pages/Profile/index.js | 11 ++++++++--- 9 files changed, 39 insertions(+), 16 deletions(-) diff --git a/products/ASC.People/Client/src/components/Article/Body/index.js b/products/ASC.People/Client/src/components/Article/Body/index.js index a26f47c5ad..6a1946962c 100644 --- a/products/ASC.People/Client/src/components/Article/Body/index.js +++ b/products/ASC.People/Client/src/components/Article/Body/index.js @@ -17,6 +17,7 @@ import { import { createI18N } from "../../../helpers/i18n"; import styled, { css } from "styled-components"; import { setDocumentTitle } from "../../../helpers/utils"; +import { inject, observer } from "mobx-react"; const i18n = createI18N({ page: "Article", @@ -114,14 +115,14 @@ class ArticleBodyContent extends React.Component { } }; onSelect = (data) => { - const { setIsLoading } = this.props + const { setIsLoading } = this.props; return () => { const { selectGroup } = this.props; setIsLoading(true); this.changeTitleDocument(data); selectGroup( data && data.length === 1 && data[0] !== "root" ? data[0] : null - ).finally(() => setIsLoading(false)) + ).finally(() => setIsLoading(false)); }; }; switcherIcon = (obj) => { @@ -243,7 +244,7 @@ function mapStateToProps(state) { : ["root"], groups, isAdmin: isAdmin(state), - isLoaded, + // isLoaded, editingForm, }; } @@ -252,4 +253,8 @@ export default connect(mapStateToProps, { selectGroup, setIsVisibleDataLossDialog, setIsLoading, -})(BodyContent); +})( + inject(({ store }) => ({ + isLoaded: store.isLoaded, + }))(observer(BodyContent)) +); diff --git a/products/ASC.People/Client/src/components/Article/MainButton/index.js b/products/ASC.People/Client/src/components/Article/MainButton/index.js index ec3e96cae8..0e206caa94 100644 --- a/products/ASC.People/Client/src/components/Article/MainButton/index.js +++ b/products/ASC.People/Client/src/components/Article/MainButton/index.js @@ -136,7 +136,7 @@ ArticleMainButtonContent.propTypes = { const mapStateToProps = (state) => { const { isLoaded } = state.auth; return { - isLoaded, + // isLoaded, //settings: getSettings(state), language: getLanguage(state), }; @@ -151,5 +151,6 @@ const mapStateToProps = (state) => { export default connect(mapStateToProps)( inject(({ store }) => ({ settings: store.settingsStore, + isLoaded: store.isLoaded, }))(observer(withRouter(ArticleMainButtonContent))) ); diff --git a/products/ASC.People/Client/src/components/pages/GroupAction/Section/Body/index.js b/products/ASC.People/Client/src/components/pages/GroupAction/Section/Body/index.js index 0b14a6aa63..f7fb3dbba0 100644 --- a/products/ASC.People/Client/src/components/pages/GroupAction/Section/Body/index.js +++ b/products/ASC.People/Client/src/components/pages/GroupAction/Section/Body/index.js @@ -513,7 +513,7 @@ function mapStateToProps(state) { me: getCurrentUser(state), currentModuleName, filter: state.people.filter, - isLoaded, + // isLoaded, }; } @@ -547,6 +547,7 @@ export default connect(mapStateToProps, { groupCaption: store.settingsStore.customNames.groupCaption, groupsCaption: store.settingsStore.customNames.groupsCaption, groupHeadCaption: store.settingsStore.customNames.groupHeadCaption, + isLoaded: store.isLoaded, }))(observer(withRouter(withTranslation()(SectionBodyContent)))) ); diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js index 5f9c624f3d..6f8a7e9f06 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js @@ -544,7 +544,7 @@ const mapStateToProps = (state) => { const { isLoaded } = state.auth; const { filter, isLoading } = state.people; return { - isLoaded, + // isLoaded, isLoadedSection: getIsLoadedSection(state), filter, isLoading, @@ -582,5 +582,6 @@ export default connect(mapStateToProps, { })( inject(({ store }) => ({ settings: store.settingsStore, + isLoaded: store.isLoaded, }))(observer(withRouter(withTranslation()(SectionBodyContent)))) ); diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js index b165aa5cd5..90a92d40a8 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js @@ -272,7 +272,7 @@ function mapStateToProps(state) { filter: getFilter(state), //settings: getSettings(state), isAdmin: isAdmin(state), - isLoaded: getIsLoaded(state), + // isLoaded: getIsLoaded(state), }; } @@ -283,6 +283,7 @@ function mapStateToProps(state) { export default connect(mapStateToProps, { fetchPeople })( inject(({ store }) => ({ settings: store.settingsStore, + isLoaded: store.isLoaded, }))( observer( withRouter(withLayoutSize(withTranslation()(SectionFilterContent))) diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js index 66c6513f07..18247df3fe 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js @@ -494,7 +494,7 @@ const mapStateToProps = (state) => { //homepage, //customNames, selection, - isLoaded, + // isLoaded, hasAnybodySelected: hasAnybodySelected(state), hasUsersToMakeEmployees: hasUsersToMakeEmployees(state), hasUsersToMakeGuests: hasUsersToMakeGuests(state), @@ -525,5 +525,6 @@ export default connect(mapStateToProps, { inject(({ store }) => ({ customNames: store.settingsStore.customNames, homepage: store.settingsStore.homepage, + isLoaded: store.isLoaded, }))(observer(withTranslation()(withRouter(SectionHeaderContent)))) ); diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Paging/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Paging/index.js index 93c79270ae..3956c57142 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Paging/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Paging/index.js @@ -6,6 +6,7 @@ import { Paging } from "asc-web-components"; import { useTranslation } from "react-i18next"; import { getFilter } from "../../../../../store/people/selectors"; import { store, Loaders } from "asc-web-common"; +import { inject, observer } from "mobx-react"; const { getIsLoaded } = store.auth.selectors; const SectionPagingContent = ({ @@ -154,8 +155,12 @@ const SectionPagingContent = ({ function mapStateToProps(state) { return { filter: getFilter(state), - isLoaded: getIsLoaded(state), + // isLoaded: getIsLoaded(state), }; } -export default connect(mapStateToProps, { fetchPeople })(SectionPagingContent); +export default connect(mapStateToProps, { fetchPeople })( + inject(({ store }) => ({ + isLoaded: store.isLoaded, + }))(observer(SectionPagingContent)) +); diff --git a/products/ASC.People/Client/src/components/pages/Home/index.js b/products/ASC.People/Client/src/components/pages/Home/index.js index 4609d27b23..94b769fd4e 100644 --- a/products/ASC.People/Client/src/components/pages/Home/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/index.js @@ -20,6 +20,7 @@ import { setSelected, setIsLoading } from "../../../store/people/actions"; import { createI18N } from "../../../helpers/i18n"; import { isMobile } from "react-device-detect"; import { getIsLoading } from "../../../store/people/selectors"; +import { inject, observer } from "mobx-react"; const i18n = createI18N({ page: "Home", localesPath: "pages/Home", @@ -188,10 +189,12 @@ function mapStateToProps(state) { organizationName: getOrganizationName(state), isAdmin: isAdmin(state), isLoading: getIsLoading(state), - isLoaded: getIsLoaded(state), + // isLoaded: getIsLoaded(state), }; } export default connect(mapStateToProps, { setSelected, setIsLoading })( - withRouter(Home) + inject(({ store }) => ({ + isLoaded: store.isLoaded, + }))(observer(withRouter(Home))) ); diff --git a/products/ASC.People/Client/src/components/pages/Profile/index.js b/products/ASC.People/Client/src/components/pages/Profile/index.js index 28aa578e2f..a397438064 100644 --- a/products/ASC.People/Client/src/components/pages/Profile/index.js +++ b/products/ASC.People/Client/src/components/pages/Profile/index.js @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import React, { Profiler, useEffect } from "react"; import { connect } from "react-redux"; import PropTypes from "prop-types"; import { Loader } from "asc-web-components"; @@ -15,6 +15,7 @@ import { createI18N } from "../../../helpers/i18n"; import { setDocumentTitle } from "../../../helpers/utils"; import { withRouter } from "react-router"; import { isChrome, isAndroid } from "react-device-detect"; +import { inject, observer } from "mobx-react"; const i18n = createI18N({ page: "Profile", localesPath: "pages/Profile", @@ -121,7 +122,7 @@ function mapStateToProps(state) { const { targetUser } = state.profile; return { profile: targetUser, - isLoaded, + // isLoaded, isVisitor: isVisitor(state), isAdmin: isAdmin(state), language: getLanguage(state), @@ -131,4 +132,8 @@ function mapStateToProps(state) { export default connect(mapStateToProps, { fetchProfile, resetProfile, -})(Profile); +})( + inject(({ store }) => ({ + isLoaded: store.isLoaded, + }))(observer(Profile)) +); From ffbc9cb57e858cc7072b487052b2d80390d2b9de Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Thu, 4 Feb 2021 18:26:44 +0300 Subject: [PATCH 03/12] web: people: replace class component to functional --- products/ASC.People/Client/src/App.js | 227 ++++++++++++++++---------- 1 file changed, 141 insertions(+), 86 deletions(-) diff --git a/products/ASC.People/Client/src/App.js b/products/ASC.People/Client/src/App.js index 3b380a2d7b..aee8013717 100644 --- a/products/ASC.People/Client/src/App.js +++ b/products/ASC.People/Client/src/App.js @@ -1,5 +1,5 @@ import React, { Suspense, useEffect } from "react"; -import { connect } from "react-redux"; +// import { connect } from "react-redux"; import { Router, Switch, Redirect } from "react-router-dom"; import Home from "./components/pages/Home"; import Profile from "./components/pages/Profile"; @@ -15,57 +15,132 @@ import { Error520, Offline, utils, - store as commonStore, + // store as commonStore, NavMenu, Main, toastr, } from "asc-web-common"; -import { getFilterByLocation } from "./helpers/converters"; -import { fetchGroups, fetchPeople } from "./store/people/actions"; +// import { getFilterByLocation } from "./helpers/converters"; +// import { fetchGroups, fetchPeople } from "./store/people/actions"; import config from "../package.json"; import { inject, observer } from "mobx-react"; -const { - setIsLoaded, - //getUser, - getPortalSettings, - //getModules, - setCurrentProductId, - setCurrentProductHomePage, - getPortalPasswordSettings, - getPortalCultures, - getIsAuthenticated, -} = commonStore.auth.actions; +// const { +// setIsLoaded, +// getUser, +// getPortalSettings, +// getModules, +// setCurrentProductId, +// setCurrentProductHomePage, +// getPortalPasswordSettings, +// getPortalCultures, +// getIsAuthenticated, +// } = commonStore.auth.actions; // const { userStore, settingsStore } = commonStore; -/*const Profile = lazy(() => import("./components/pages/Profile")); -const ProfileAction = lazy(() => import("./components/pages/ProfileAction")); -const GroupAction = lazy(() => import("./components/pages/GroupAction"));*/ +// const Profile = lazy(() => import("./components/pages/Profile")); +// const ProfileAction = lazy(() => import("./components/pages/ProfileAction")); +// const GroupAction = lazy(() => import("./components/pages/GroupAction")); -class App extends React.Component { +const App = (props) => { + const { homepage, isLoaded, loadBaseInfo } = props; + + useEffect(() => { + try { + loadBaseInfo(); + } catch (err) { + toastr.error(err); + } + }, [loadBaseInfo]); + + useEffect(() => { + console.log("App People render", isLoaded); + if (isLoaded) utils.updateTempContent(); + }, [isLoaded]); + + return navigator.onLine ? ( + + +
+ + + + + + + + + + + + + + + +
+
+ ) : ( + + ); +}; + +/*class App extends React.Component { async componentDidMount() { const { - setModuleInfo, - getUser, - getPortalSettings, + // setModuleInfo, + // getUser, + // getPortalSettings, //getModules, - getPortalPasswordSettings, - getPortalCultures, - fetchGroups, - fetchPeople, - setIsLoaded, - getIsAuthenticated, + // getPortalPasswordSettings, + // getPortalCultures, + // fetchGroups, + // fetchPeople, + // setIsLoaded, + // getIsAuthenticated, loadBaseInfo, - loadBasePeopleInfo, + isLoaded, + // loadBasePeopleInfo, } = this.props; try { - const isAuthenticated = await getIsAuthenticated(); + // const isAuthenticated = await getIsAuthenticated(); - if (isAuthenticated) utils.updateTempContent(isAuthenticated); + // if (isAuthenticated) utils.updateTempContent(isAuthenticated); await loadBaseInfo(); utils.updateTempContent(); - setIsLoaded(); + // setIsLoaded(); } catch (e) { toastr.error(e); } @@ -169,59 +244,39 @@ class App extends React.Component { // }; // }; -const mapDispatchToProps = (dispatch) => { - return { - getIsAuthenticated: () => getIsAuthenticated(dispatch), - // setModuleInfo: () => { - // dispatch(setCurrentProductHomePage(config.homepage)); - // dispatch(setCurrentProductId("f4d98afd-d336-4332-8778-3c6945c81ea0")); - // }, - //getUser: () => getUser(dispatch), - //getPortalSettings: () => getPortalSettings(dispatch), - //getModules: () => getModules(dispatch), - getPortalPasswordSettings: () => getPortalPasswordSettings(dispatch), - getPortalCultures: () => getPortalCultures(dispatch), - // fetchGroups: () => fetchGroups(dispatch), - // fetchPeople: () => { - // var re = new RegExp(`${config.homepage}((/?)$|/filter)`, "gm"); - // const match = window.location.pathname.match(re); +// const mapDispatchToProps = (dispatch) => { +// return { +//getIsAuthenticated: () => getIsAuthenticated(dispatch), +// setModuleInfo: () => { +// dispatch(setCurrentProductHomePage(config.homepage)); +// dispatch(setCurrentProductId("f4d98afd-d336-4332-8778-3c6945c81ea0")); +// }, +//getUser: () => getUser(dispatch), +//getPortalSettings: () => getPortalSettings(dispatch), +//getModules: () => getModules(dispatch), +// getPortalPasswordSettings: () => getPortalPasswordSettings(dispatch), +// getPortalCultures: () => getPortalCultures(dispatch), +// fetchGroups: () => fetchGroups(dispatch), +// fetchPeople: () => { +// var re = new RegExp(`${config.homepage}((/?)$|/filter)`, "gm"); +// const match = window.location.pathname.match(re); - // if (match && match.length > 0) { - // const newFilter = getFilterByLocation(window.location); - // return fetchPeople(newFilter, dispatch); - // } +// if (match && match.length > 0) { +// const newFilter = getFilterByLocation(window.location); +// return fetchPeople(newFilter, dispatch); +// } - // return Promise.resolve(); - // }, - setIsLoaded: () => dispatch(setIsLoaded(true)), - }; -}; - -// const AppWrapper = observer((props) => { -// useEffect(() => { -// userStore.setCurrentUser(); -// }, []); - -// return ; -// }); - -// export default connect(mapStateToProps, mapDispatchToProps)(AppWrapper); - -export default connect( - null, - mapDispatchToProps -)( - inject(({ store, peopleStore }) => ({ - user: store.userStore.user, - isAuthenticated: store.userStore.isAuthenticated, - getUser: store.userStore.setCurrentUser, - homepage: store.settingsStore.homepage || config.homepage, - encryptionKeys: store.settingsStore.encryptionKeys, - loadBaseInfo: () => { - store.init(); - peopleStore.init(); - }, - - // loadBasePeopleInfo: peopleStore.init, - }))(observer(App)) -); +// return Promise.resolve(); +// }, +// setIsLoaded: () => dispatch(setIsLoaded(true)), +// }; +// }; +*/ +export default inject(({ store, peopleStore }) => ({ + homepage: store.settingsStore.homepage || config.homepage, + loadBaseInfo: () => { + store.init(); + peopleStore.init(); + }, + isLoaded: store.isLoaded, +}))(observer(App)); From 881c56d693fb8a98a0a06f53316c78a2bcddaa71 Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Thu, 4 Feb 2021 18:58:24 +0300 Subject: [PATCH 04/12] web: people: add current module name --- products/ASC.People/Client/src/App.js | 4 ++++ .../Client/src/components/Article/Header/index.js | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/products/ASC.People/Client/src/App.js b/products/ASC.People/Client/src/App.js index aee8013717..2496d31d58 100644 --- a/products/ASC.People/Client/src/App.js +++ b/products/ASC.People/Client/src/App.js @@ -276,6 +276,10 @@ export default inject(({ store, peopleStore }) => ({ homepage: store.settingsStore.homepage || config.homepage, loadBaseInfo: () => { store.init(); + store.settingsStore.setModuleInfo( + config.homepage, + "f4d98afd-d336-4332-8778-3c6945c81ea0" + ); peopleStore.init(); }, isLoaded: store.isLoaded, diff --git a/products/ASC.People/Client/src/components/Article/Header/index.js b/products/ASC.People/Client/src/components/Article/Header/index.js index d6eb59b91a..6be72669bf 100644 --- a/products/ASC.People/Client/src/components/Article/Header/index.js +++ b/products/ASC.People/Client/src/components/Article/Header/index.js @@ -1,6 +1,7 @@ import React from "react"; import { connect } from "react-redux"; import { store, Headline, Loaders } from "asc-web-common"; +import { inject, observer } from "mobx-react"; const { getCurrentProductName } = store.auth.selectors; @@ -19,4 +20,8 @@ const mapStateToProps = (state) => { }; }; -export default connect(mapStateToProps)(ArticleHeaderContent); +export default connect(mapStateToProps)( + inject(({ store }) => ({ + currentModuleName: store.product.title, + }))(observer(ArticleHeaderContent)) +); From a8eeb6e6e8ba358c185a85751835038a017e09ab Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Thu, 4 Feb 2021 19:29:53 +0300 Subject: [PATCH 05/12] web: people: migrate isAdmin prop --- .../src/components/Article/Body/index.js | 3 ++- .../src/components/pages/GroupAction/index.js | 9 +++++++-- .../pages/Home/Section/Body/index.js | 5 +++-- .../pages/Home/Section/Filter/index.js | 3 ++- .../pages/Home/Section/Header/index.js | 3 ++- .../Client/src/components/pages/Home/index.js | 3 ++- .../pages/Profile/Section/Body/index.js | 3 ++- .../pages/Profile/Section/Header/index.js | 3 ++- .../src/components/pages/Profile/index.js | 3 ++- .../Section/Body/updateUserForm.js | 3 ++- .../components/pages/ProfileAction/index.js | 7 +++++-- .../src/components/pages/Reassign/index.js | 19 ++++++++++++------- 12 files changed, 43 insertions(+), 21 deletions(-) diff --git a/products/ASC.People/Client/src/components/Article/Body/index.js b/products/ASC.People/Client/src/components/Article/Body/index.js index 6a1946962c..0f363922ca 100644 --- a/products/ASC.People/Client/src/components/Article/Body/index.js +++ b/products/ASC.People/Client/src/components/Article/Body/index.js @@ -243,7 +243,7 @@ function mapStateToProps(state) { ? [state.people.selectedGroup] : ["root"], groups, - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), // isLoaded, editingForm, }; @@ -256,5 +256,6 @@ export default connect(mapStateToProps, { })( inject(({ store }) => ({ isLoaded: store.isLoaded, + isAdmin: store.isAdmin, }))(observer(BodyContent)) ); diff --git a/products/ASC.People/Client/src/components/pages/GroupAction/index.js b/products/ASC.People/Client/src/components/pages/GroupAction/index.js index 965203242e..9e8bce2340 100644 --- a/products/ASC.People/Client/src/components/pages/GroupAction/index.js +++ b/products/ASC.People/Client/src/components/pages/GroupAction/index.js @@ -13,6 +13,7 @@ import { fetchGroup, resetGroup } from "../../../store/group/actions"; import { createI18N } from "../../../helpers/i18n"; import { setDocumentTitle } from "../../../helpers/utils"; import { withRouter } from "react-router"; +import { inject, observer } from "mobx-react"; const i18n = createI18N({ page: "GroupAction", localesPath: "pages/GroupAction", @@ -117,11 +118,15 @@ function mapStateToProps(state) { return { //settings: state.auth.settings, group: state.group.targetGroup, - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), }; } export default connect(mapStateToProps, { fetchGroup, resetGroup, -})(GroupActionContainer); +})( + inject(({ store }) => ({ + isAdmin: store.isAdmin, + }))(observer(GroupActionContainer)) +); diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js index 6f8a7e9f06..f525406a92 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js @@ -343,7 +343,7 @@ class SectionBodyContent extends React.PureComponent { }; onContentRowSelect = (checked, user) => { - //console.log("ContentRow onSelect", checked, user); + console.log("ContentRow onSelect", checked, user); if (checked) { this.props.selectUser(user); } else { @@ -550,7 +550,7 @@ const mapStateToProps = (state) => { isLoading, peopleList: getPeopleList(state), //settings: getSettings(state), - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), currentUserId: getCurrentUserId(state), }; }; @@ -583,5 +583,6 @@ export default connect(mapStateToProps, { inject(({ store }) => ({ settings: store.settingsStore, isLoaded: store.isLoaded, + isAdmin: store.isAdmin, }))(observer(withRouter(withTranslation()(SectionBodyContent)))) ); diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js index 90a92d40a8..7df085ce02 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js @@ -271,7 +271,7 @@ function mapStateToProps(state) { groups: getGroups(state), filter: getFilter(state), //settings: getSettings(state), - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), // isLoaded: getIsLoaded(state), }; } @@ -284,6 +284,7 @@ export default connect(mapStateToProps, { fetchPeople })( inject(({ store }) => ({ settings: store.settingsStore, isLoaded: store.isLoaded, + isAdmin: store.isAdmin, }))( observer( withRouter(withLayoutSize(withTranslation()(SectionFilterContent))) diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js index 18247df3fe..e56fad3ef9 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js @@ -490,7 +490,7 @@ const mapStateToProps = (state) => { return { group: getSelectedGroup(groups, selectedGroup), - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), //homepage, //customNames, selection, @@ -526,5 +526,6 @@ export default connect(mapStateToProps, { customNames: store.settingsStore.customNames, homepage: store.settingsStore.homepage, isLoaded: store.isLoaded, + isAdmin: store.isAdmin, }))(observer(withTranslation()(withRouter(SectionHeaderContent)))) ); diff --git a/products/ASC.People/Client/src/components/pages/Home/index.js b/products/ASC.People/Client/src/components/pages/Home/index.js index 94b769fd4e..0e1dd5d1ac 100644 --- a/products/ASC.People/Client/src/components/pages/Home/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/index.js @@ -187,7 +187,7 @@ function mapStateToProps(state) { selectedGroup, groups, organizationName: getOrganizationName(state), - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), isLoading: getIsLoading(state), // isLoaded: getIsLoaded(state), }; @@ -196,5 +196,6 @@ function mapStateToProps(state) { export default connect(mapStateToProps, { setSelected, setIsLoading })( inject(({ store }) => ({ isLoaded: store.isLoaded, + isAdmin: store.isAdmin, }))(observer(withRouter(Home))) ); diff --git a/products/ASC.People/Client/src/components/pages/Profile/Section/Body/index.js b/products/ASC.People/Client/src/components/pages/Profile/Section/Body/index.js index fb976eef77..6b9cbd7a76 100644 --- a/products/ASC.People/Client/src/components/pages/Profile/Section/Body/index.js +++ b/products/ASC.People/Client/src/components/pages/Profile/Section/Body/index.js @@ -187,7 +187,7 @@ const mapStateToProps = (state) => { return { //settings: state.auth.settings, profile: state.profile.targetUser, - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), viewer: state.auth.user, }; }; @@ -199,6 +199,7 @@ const mapStateToProps = (state) => { export default connect(mapStateToProps)( inject(({ store }) => ({ settings: store.settingsStore, + isAdmin: store.isAdmin, }))(observer(withRouter(withTranslation()(SectionBodyContent)))) ); diff --git a/products/ASC.People/Client/src/components/pages/Profile/Section/Header/index.js b/products/ASC.People/Client/src/components/pages/Profile/Section/Header/index.js index cd5506bc86..4cf9e180c9 100644 --- a/products/ASC.People/Client/src/components/pages/Profile/Section/Header/index.js +++ b/products/ASC.People/Client/src/components/pages/Profile/Section/Header/index.js @@ -511,7 +511,7 @@ const mapStateToProps = (state) => { //settings: state.auth.settings, profile: state.profile.targetUser, viewer: state.auth.user, - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), filter: state.people.filter, }; }; @@ -528,6 +528,7 @@ export default connect(mapStateToProps, { })( inject(({ store }) => ({ settings: store.settingsStore, + isAdmin: store.isAdmin, }))(observer(withRouter(withTranslation()(SectionHeaderContent)))) ); diff --git a/products/ASC.People/Client/src/components/pages/Profile/index.js b/products/ASC.People/Client/src/components/pages/Profile/index.js index a397438064..1120840bed 100644 --- a/products/ASC.People/Client/src/components/pages/Profile/index.js +++ b/products/ASC.People/Client/src/components/pages/Profile/index.js @@ -124,7 +124,7 @@ function mapStateToProps(state) { profile: targetUser, // isLoaded, isVisitor: isVisitor(state), - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), language: getLanguage(state), }; } @@ -135,5 +135,6 @@ export default connect(mapStateToProps, { })( inject(({ store }) => ({ isLoaded: store.isLoaded, + isAdmin: store.isAdmin, }))(observer(Profile)) ); diff --git a/products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/updateUserForm.js b/products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/updateUserForm.js index 2cf4751a85..735960b670 100644 --- a/products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/updateUserForm.js +++ b/products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/updateUserForm.js @@ -922,7 +922,7 @@ const mapStateToProps = (state) => { editingForm: state.people.editingForm, filter: state.people.filter, disableProfileType: getDisableProfileType(state), - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), }; }; @@ -942,6 +942,7 @@ export default connect(mapStateToProps, { })( inject(({ store }) => ({ settings: store.settingsStore, + isAdmin: store.isAdmin, }))(observer(withRouter(withTranslation()(UpdateUserForm)))) ); diff --git a/products/ASC.People/Client/src/components/pages/ProfileAction/index.js b/products/ASC.People/Client/src/components/pages/ProfileAction/index.js index f7de66da8c..b249bef495 100644 --- a/products/ASC.People/Client/src/components/pages/ProfileAction/index.js +++ b/products/ASC.People/Client/src/components/pages/ProfileAction/index.js @@ -21,6 +21,7 @@ import { I18nextProvider, withTranslation } from "react-i18next"; import { createI18N } from "../../../helpers/i18n"; import { setDocumentTitle } from "../../../helpers/utils"; import { withRouter } from "react-router"; +import { inject, observer } from "mobx-react"; const i18n = createI18N({ page: "ProfileAction", localesPath: "pages/ProfileAction", @@ -143,12 +144,14 @@ function mapStateToProps(state) { return { isVisitor: state.auth.user.isVisitor, profile: state.profile.targetUser, - isAdmin: isAdmin(state), + // isAdmin: isAdmin(state), isEdit: state.people.editingForm.isEdit, avatarEditorIsOpen: state.people.avatarEditorIsOpen, }; } export default connect(mapStateToProps, { fetchProfile, setIsEditingForm })( - ProfileActionContainer + inject(({ store }) => ({ + isAdmin: store.isAdmin, + }))(observer(ProfileActionContainer)) ); diff --git a/products/ASC.People/Client/src/components/pages/Reassign/index.js b/products/ASC.People/Client/src/components/pages/Reassign/index.js index 57897a9891..ef993ccc06 100644 --- a/products/ASC.People/Client/src/components/pages/Reassign/index.js +++ b/products/ASC.People/Client/src/components/pages/Reassign/index.js @@ -12,6 +12,7 @@ import { import { I18nextProvider } from "react-i18next"; import { SectionHeaderContent, SectionBodyContent } from "./Section"; import { createI18N } from "../../../helpers/i18n"; +import { inject, observer } from "mobx-react"; const i18n = createI18N({ page: "Reassign", localesPath: "pages/Reassign", @@ -86,11 +87,15 @@ Reassign.propTypes = { // fetchProfile: PropTypes.func.isRequired }; -function mapStateToProps(state) { - return { - isAdmin: isAdmin(state), - // profile: state.profile.targetUser - }; -} +// function mapStateToProps(state) { +// return { +// isAdmin: isAdmin(state), +// profile: state.profile.targetUser +// }; +// } -export default connect(mapStateToProps, {})(Reassign); +// export default connect(mapStateToProps, {})(Reassign); + +export default inject(({ store }) => ({ + isAdmin: store.isAdmin, +}))(observer(Reassign)); From 79a3ca68fd0557b5859b97c3347f42685dd8d201 Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Thu, 4 Feb 2021 20:11:41 +0300 Subject: [PATCH 06/12] web: fix data --- products/ASC.People/Client/src/store/UsersStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/products/ASC.People/Client/src/store/UsersStore.js b/products/ASC.People/Client/src/store/UsersStore.js index e6d7cb7621..a5fcc37375 100644 --- a/products/ASC.People/Client/src/store/UsersStore.js +++ b/products/ASC.People/Client/src/store/UsersStore.js @@ -20,7 +20,7 @@ class UsersStore { filterData = Filter.getDefault(); } const res = await api.people.getListAdmins(filterData); - this.users = res; + this.users = res.items; }; } From 6b98264bb2b12b9a5b1f6f91215ff1f6352cb35e Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Thu, 4 Feb 2021 20:11:58 +0300 Subject: [PATCH 07/12] web: add current user id --- .../Client/src/components/pages/Home/Section/Body/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js index f525406a92..67f8f27f09 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js @@ -551,7 +551,7 @@ const mapStateToProps = (state) => { peopleList: getPeopleList(state), //settings: getSettings(state), // isAdmin: isAdmin(state), - currentUserId: getCurrentUserId(state), + // currentUserId: getCurrentUserId(state), }; }; @@ -580,9 +580,11 @@ export default connect(mapStateToProps, { selectGroup, setIsLoadedSection, })( - inject(({ store }) => ({ + inject(({ store, peopleStore }) => ({ settings: store.settingsStore, isLoaded: store.isLoaded, isAdmin: store.isAdmin, + currentUserId: store.userStore.user.id, + //peopleList: peopleStore.usersStore.users, }))(observer(withRouter(withTranslation()(SectionBodyContent)))) ); From d98b554695a490b207dcf3f56665408aacc7e055 Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Fri, 5 Feb 2021 13:49:44 +0300 Subject: [PATCH 08/12] web: people: replace redux connect with mobx --- .../components/Article/MainButton/index.js | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/products/ASC.People/Client/src/components/Article/MainButton/index.js b/products/ASC.People/Client/src/components/Article/MainButton/index.js index 0e206caa94..54c7580220 100644 --- a/products/ASC.People/Client/src/components/Article/MainButton/index.js +++ b/products/ASC.People/Client/src/components/Article/MainButton/index.js @@ -1,8 +1,6 @@ import React, { useEffect } from "react"; -import { connect } from "react-redux"; import PropTypes from "prop-types"; import { withRouter } from "react-router"; -import { store } from "asc-web-common"; import { MainButton, DropDownItem } from "asc-web-components"; import { InviteDialog } from "./../../dialogs"; import { withTranslation, I18nextProvider } from "react-i18next"; @@ -10,14 +8,12 @@ import { utils, toastr, Loaders } from "asc-web-common"; import { createI18N } from "../../../helpers/i18n"; import { inject, observer } from "mobx-react"; -const { getLanguage /* getSettings */ } = store.auth.selectors; const i18n = createI18N({ page: "Article", localesPath: "Article", }); const { changeLanguage } = utils; -const { settingsStore } = store; class PureArticleMainButtonContent extends React.Component { constructor(props) { @@ -133,24 +129,8 @@ ArticleMainButtonContent.propTypes = { language: PropTypes.string, }; -const mapStateToProps = (state) => { - const { isLoaded } = state.auth; - return { - // isLoaded, - //settings: getSettings(state), - language: getLanguage(state), - }; -}; - -// const MainButtonWrapper = observer((props) => { -// return ( -// -// ); -// }); - -export default connect(mapStateToProps)( - inject(({ store }) => ({ - settings: store.settingsStore, - isLoaded: store.isLoaded, - }))(observer(withRouter(ArticleMainButtonContent))) -); +export default inject(({ store }) => ({ + settings: store.settingsStore, + isLoaded: store.isLoaded, + language: store.userStore.user.cultureName || store.settingsStore.culture, +}))(observer(withRouter(ArticleMainButtonContent))); From ce9b0e9ba8dcf5e9fe13407c94a97310ba6d3f61 Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Fri, 5 Feb 2021 13:50:02 +0300 Subject: [PATCH 09/12] web: people: add mobx props --- .../src/components/Article/Body/index.js | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/products/ASC.People/Client/src/components/Article/Body/index.js b/products/ASC.People/Client/src/components/Article/Body/index.js index 0f363922ca..05a3a5b127 100644 --- a/products/ASC.People/Client/src/components/Article/Body/index.js +++ b/products/ASC.People/Client/src/components/Article/Body/index.js @@ -231,18 +231,17 @@ const BodyContent = (props) => { }; function mapStateToProps(state) { - const groups = state.people.groups; + //const groups = state.people.groups; const { isLoaded, settings } = state.auth; const { customNames } = settings; const { groupsCaption } = customNames; const { editingForm } = state.people; - return { - data: getTreeGroups(groups, groupsCaption), + // data: getTreeGroups(groups, groupsCaption), selectedKeys: state.people.selectedGroup ? [state.people.selectedGroup] : ["root"], - groups, + // groups, // isAdmin: isAdmin(state), // isLoaded, editingForm, @@ -254,8 +253,15 @@ export default connect(mapStateToProps, { setIsVisibleDataLossDialog, setIsLoading, })( - inject(({ store }) => ({ - isLoaded: store.isLoaded, - isAdmin: store.isAdmin, - }))(observer(BodyContent)) + inject(({ store, peopleStore }) => { + const groups = peopleStore.groupsStore.groups; + const { groupsCaption } = store.settingsStore.customNames; + const data = getTreeGroups(groups, groupsCaption); + return { + isLoaded: store.isLoaded, + isAdmin: store.isAdmin, + groups, + data, + }; + })(observer(BodyContent)) ); From 6ca4a97547992c136392aaa126f2a24aa4759803 Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Fri, 5 Feb 2021 16:15:44 +0300 Subject: [PATCH 10/12] web: people: add target user store --- .../Client/src/store/PeopleStore.js | 6 +++++ .../Client/src/store/TargetUserStore.js | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 products/ASC.People/Client/src/store/TargetUserStore.js diff --git a/products/ASC.People/Client/src/store/PeopleStore.js b/products/ASC.People/Client/src/store/PeopleStore.js index 25174b8341..25615efa7d 100644 --- a/products/ASC.People/Client/src/store/PeopleStore.js +++ b/products/ASC.People/Client/src/store/PeopleStore.js @@ -7,10 +7,12 @@ import GroupsStore from "./GroupsStore"; import UsersStore from "./UsersStore"; import { getFilterByLocation } from "../helpers/converters"; import config from "../../package.json"; +import TargetUserStore from "./TargetUserStore"; class PeopleStore { groupsStore = null; usersStore = null; + targetUserStore = null; isLoading = false; //isAuthenticated = false; @@ -18,6 +20,7 @@ class PeopleStore { constructor() { this.setGroupsStore(new GroupsStore()); this.setUsersStore(new UsersStore()); + this.setTargetUserStore(new TargetUserStore()); makeObservable(this, { isLoading: observable, @@ -45,6 +48,9 @@ class PeopleStore { setUsersStore = (store) => { this.usersStore = store; }; + setTargetUserStore = (store) => { + this.targetUserStore = store; + }; } export default new PeopleStore(); diff --git a/products/ASC.People/Client/src/store/TargetUserStore.js b/products/ASC.People/Client/src/store/TargetUserStore.js new file mode 100644 index 0000000000..90c1b14d8d --- /dev/null +++ b/products/ASC.People/Client/src/store/TargetUserStore.js @@ -0,0 +1,24 @@ +import { api } from "asc-web-common"; +import { action, makeObservable, observable } from "mobx"; +// import { getFilterByLocation } from "../helpers/converters"; +// import { api } from "asc-web-common"; + +// const { Filter } = api; + +class TargetUserStore { + targetUser = null; + + constructor() { + makeObservable(this, { + targetUser: observable, + getTargetUser: action, + }); + } + + getTargetUser = async (userName) => { + const user = await api.people.getUser(userName); + this.targetUser = user; + }; +} + +export default TargetUserStore; From 7deee30d24de3a168187b810ce826f42914173aa Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Fri, 5 Feb 2021 16:19:18 +0300 Subject: [PATCH 11/12] web: people: migrate props to mobx --- .../components/Article/MainButton/index.js | 2 +- .../pages/GroupAction/Section/Body/index.js | 48 +++++++------------ .../pages/Home/Section/Filter/index.js | 24 ++++++---- .../Client/src/components/pages/Home/index.js | 11 +++-- .../pages/Profile/Section/Header/index.js | 3 +- .../src/components/pages/Profile/index.js | 3 +- 6 files changed, 45 insertions(+), 46 deletions(-) diff --git a/products/ASC.People/Client/src/components/Article/MainButton/index.js b/products/ASC.People/Client/src/components/Article/MainButton/index.js index 54c7580220..7dc6fe8085 100644 --- a/products/ASC.People/Client/src/components/Article/MainButton/index.js +++ b/products/ASC.People/Client/src/components/Article/MainButton/index.js @@ -132,5 +132,5 @@ ArticleMainButtonContent.propTypes = { export default inject(({ store }) => ({ settings: store.settingsStore, isLoaded: store.isLoaded, - language: store.userStore.user.cultureName || store.settingsStore.culture, + language: store.language, }))(observer(withRouter(ArticleMainButtonContent))); diff --git a/products/ASC.People/Client/src/components/pages/GroupAction/Section/Body/index.js b/products/ASC.People/Client/src/components/pages/GroupAction/Section/Body/index.js index f7fb3dbba0..c0a0280a8c 100644 --- a/products/ASC.People/Client/src/components/pages/GroupAction/Section/Body/index.js +++ b/products/ASC.People/Client/src/components/pages/GroupAction/Section/Body/index.js @@ -493,48 +493,30 @@ const convertGroups = (groups) => { }; function mapStateToProps(state) { - const currentModuleName = getCurrentProductName(state); + //const currentModuleName = getCurrentProductName(state); //const settings = getSettings(state); // const { // groupHeadCaption, // groupsCaption, // groupCaption, // } = settings.customNames; - const { isLoaded } = state.auth; + //const { isLoaded } = state.auth; return { //settings, group: state.group.targetGroup, - groups: convertGroups(state.people.groups), + //groups: convertGroups(state.people.groups), users: convertUsers(state.people.selector.users), //TODO: replace to api requests with search // groupHeadCaption, // groupsCaption, // groupCaption, - me: getCurrentUser(state), - currentModuleName, + //me: getCurrentUser(state), + //currentModuleName, filter: state.people.filter, // isLoaded, }; } -// const SectionBodyContentWrapper = observer((props) => { -// const { -// groupHeadCaption, -// groupsCaption, -// groupCaption, -// } = settingsStore.customNames; - -// return ( -// -// ); -// }); - export default connect(mapStateToProps, { resetGroup, createGroup, @@ -542,13 +524,19 @@ export default connect(mapStateToProps, { selectGroup, setFilter, })( - inject(({ store }) => ({ - settings: store.settingsStore, - groupCaption: store.settingsStore.customNames.groupCaption, - groupsCaption: store.settingsStore.customNames.groupsCaption, - groupHeadCaption: store.settingsStore.customNames.groupHeadCaption, - isLoaded: store.isLoaded, - }))(observer(withRouter(withTranslation()(SectionBodyContent)))) + inject(({ store, peopleStore }) => { + const groups = convertGroups(peopleStore.groupsStore.groups); + return { + settings: store.settingsStore, + groupCaption: store.settingsStore.customNames.groupCaption, + groupsCaption: store.settingsStore.customNames.groupsCaption, + groupHeadCaption: store.settingsStore.customNames.groupHeadCaption, + isLoaded: store.isLoaded, + currentModuleName: store.product.title, + me: store.userStore.user, + groups, + }; + })(observer(withRouter(withTranslation()(SectionBodyContent)))) ); // export default connect(mapStateToProps, { diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js index 7df085ce02..f9321fb211 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js @@ -266,11 +266,11 @@ class SectionFilterContent extends React.Component { function mapStateToProps(state) { return { - user: getCurrentUser(state), - language: getLanguage(state), - groups: getGroups(state), + //user: getCurrentUser(state), + //language: getLanguage(state), + //groups: getGroups(state), filter: getFilter(state), - //settings: getSettings(state), + // settings: getSettings(state), // isAdmin: isAdmin(state), // isLoaded: getIsLoaded(state), }; @@ -281,11 +281,17 @@ function mapStateToProps(state) { // }); export default connect(mapStateToProps, { fetchPeople })( - inject(({ store }) => ({ - settings: store.settingsStore, - isLoaded: store.isLoaded, - isAdmin: store.isAdmin, - }))( + inject(({ store, peopleStore }) => { + // const { isAdmin, isLoaded, language, settings } = store; + return { + settings: store.settingsStore, + isLoaded: store.isLoaded, + isAdmin: store.isAdmin, + language: store.language, + user: store.userStore.user, + groups: peopleStore.groupsStore.groups, + }; + })( observer( withRouter(withLayoutSize(withTranslation()(SectionFilterContent))) ) diff --git a/products/ASC.People/Client/src/components/pages/Home/index.js b/products/ASC.People/Client/src/components/pages/Home/index.js index 0e1dd5d1ac..c5747d7057 100644 --- a/products/ASC.People/Client/src/components/pages/Home/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/index.js @@ -181,12 +181,12 @@ Home.propTypes = { function mapStateToProps(state) { const { users, selection, selected, selectedGroup, groups } = state.people; return { - users, + //users, selection, selected, selectedGroup, - groups, - organizationName: getOrganizationName(state), + // groups, + // organizationName: getOrganizationName(state), // isAdmin: isAdmin(state), isLoading: getIsLoading(state), // isLoaded: getIsLoaded(state), @@ -194,8 +194,11 @@ function mapStateToProps(state) { } export default connect(mapStateToProps, { setSelected, setIsLoading })( - inject(({ store }) => ({ + inject(({ store, peopleStore }) => ({ isLoaded: store.isLoaded, isAdmin: store.isAdmin, + organizationName: store.settingsStore.organizationName, + users: peopleStore.usersStore.users, + groups: peopleStore.groupsStore.groups, }))(observer(withRouter(Home))) ); diff --git a/products/ASC.People/Client/src/components/pages/Profile/Section/Header/index.js b/products/ASC.People/Client/src/components/pages/Profile/Section/Header/index.js index 4cf9e180c9..fe93ba9c7a 100644 --- a/products/ASC.People/Client/src/components/pages/Profile/Section/Header/index.js +++ b/products/ASC.People/Client/src/components/pages/Profile/Section/Header/index.js @@ -510,7 +510,7 @@ const mapStateToProps = (state) => { return { //settings: state.auth.settings, profile: state.profile.targetUser, - viewer: state.auth.user, + //viewer: state.auth.user, // isAdmin: isAdmin(state), filter: state.people.filter, }; @@ -529,6 +529,7 @@ export default connect(mapStateToProps, { inject(({ store }) => ({ settings: store.settingsStore, isAdmin: store.isAdmin, + viewer: store.userStore.user, }))(observer(withRouter(withTranslation()(SectionHeaderContent)))) ); diff --git a/products/ASC.People/Client/src/components/pages/Profile/index.js b/products/ASC.People/Client/src/components/pages/Profile/index.js index 1120840bed..923197e380 100644 --- a/products/ASC.People/Client/src/components/pages/Profile/index.js +++ b/products/ASC.People/Client/src/components/pages/Profile/index.js @@ -125,7 +125,7 @@ function mapStateToProps(state) { // isLoaded, isVisitor: isVisitor(state), // isAdmin: isAdmin(state), - language: getLanguage(state), + //language: getLanguage(state), }; } @@ -136,5 +136,6 @@ export default connect(mapStateToProps, { inject(({ store }) => ({ isLoaded: store.isLoaded, isAdmin: store.isAdmin, + language: store.language, }))(observer(Profile)) ); From e747eeab926e2df97631534b5aa367de085bd2d3 Mon Sep 17 00:00:00 2001 From: Vladislav Makhov Date: Fri, 5 Feb 2021 16:19:46 +0300 Subject: [PATCH 12/12] web: people: remove dep from use effect --- products/ASC.People/Client/src/App.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/products/ASC.People/Client/src/App.js b/products/ASC.People/Client/src/App.js index 2496d31d58..3d8d954811 100644 --- a/products/ASC.People/Client/src/App.js +++ b/products/ASC.People/Client/src/App.js @@ -47,11 +47,12 @@ const App = (props) => { useEffect(() => { try { + console.log("loadBaseInfo call"); loadBaseInfo(); } catch (err) { toastr.error(err); } - }, [loadBaseInfo]); + }, []); useEffect(() => { console.log("App People render", isLoaded);