Web:People: added catalog

This commit is contained in:
Timofey Boyko 2021-09-30 21:17:10 +08:00
parent bd56abaa0a
commit 076fbcdab7
10 changed files with 547 additions and 130 deletions

View File

@ -14,7 +14,7 @@ import {
StyledCatalogItemInitialText, StyledCatalogItemInitialText,
} from "./styled-catalog-item"; } from "./styled-catalog-item";
const getInitial = (text) => text.substring(0, 1); const getInitial = (text) => text.substring(0, 1).toUpperCase();
const CatalogItem = (props) => { const CatalogItem = (props) => {
// console.log("render"); // console.log("render");

View File

@ -73,7 +73,7 @@ StyledCatalogItemBadgeWrapper.defaultProps = { theme: Base };
const StyledCatalogItemInitialText = styled(Text)` const StyledCatalogItemInitialText = styled(Text)`
position: absolute; position: absolute;
top: 3px; top: 2px;
left: 0; left: 0;
text-align: center; text-align: center;
width: ${(props) => props.theme.catalogItem.initialText.width}; width: ${(props) => props.theme.catalogItem.initialText.width};
@ -171,6 +171,8 @@ const StyledCatalogItemSibling = styled.div`
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
min-height: ${(props) => props.theme.catalogItem.container.height};
max-height: ${(props) => props.theme.catalogItem.container.height};
background-color: ${(props) => background-color: ${(props) =>
props.isActive && props.theme.catalogItem.sibling.active.background}; props.isActive && props.theme.catalogItem.sibling.active.background};
@ -179,6 +181,17 @@ const StyledCatalogItemSibling = styled.div`
background-color: ${(props) => background-color: ${(props) =>
props.theme.catalogItem.sibling.hover.background}; props.theme.catalogItem.sibling.hover.background};
} }
@media ${tablet} {
min-height: ${(props) => props.theme.catalogItem.container.tablet.height};
max-height: ${(props) => props.theme.catalogItem.container.tablet.height};
}
${isMobile &&
css`
min-height: ${(props) => props.theme.catalogItem.container.tablet.height};
max-height: ${(props) => props.theme.catalogItem.container.tablet.height};
`}
`; `;
StyledCatalogItemSibling.defaultProps = { theme: Base }; StyledCatalogItemSibling.defaultProps = { theme: Base };
@ -189,6 +202,7 @@ const StyledCatalogItemContainer = styled.div`
align-items: center; align-items: center;
min-width: ${(props) => props.theme.catalogItem.container.width}; min-width: ${(props) => props.theme.catalogItem.container.width};
min-height: ${(props) => props.theme.catalogItem.container.height}; min-height: ${(props) => props.theme.catalogItem.container.height};
max-height: ${(props) => props.theme.catalogItem.container.height};
position: relative; position: relative;
box-sizing: border-box; box-sizing: border-box;
padding: ${(props) => padding: ${(props) =>
@ -199,6 +213,7 @@ const StyledCatalogItemContainer = styled.div`
@media ${tablet} { @media ${tablet} {
min-height: ${(props) => props.theme.catalogItem.container.tablet.height}; min-height: ${(props) => props.theme.catalogItem.container.tablet.height};
max-height: ${(props) => props.theme.catalogItem.container.tablet.height};
padding: ${(props) => padding: ${(props) =>
props.showText && props.theme.catalogItem.container.tablet.padding}; props.showText && props.theme.catalogItem.container.tablet.padding};
margin-bottom: ${(props) => margin-bottom: ${(props) =>
@ -209,6 +224,7 @@ const StyledCatalogItemContainer = styled.div`
${isMobile && ${isMobile &&
css` css`
min-height: ${(props) => props.theme.catalogItem.container.tablet.height}; min-height: ${(props) => props.theme.catalogItem.container.tablet.height};
max-height: ${(props) => props.theme.catalogItem.container.tablet.height};
padding: ${(props) => padding: ${(props) =>
props.showText && props.theme.catalogItem.container.tablet.padding}; props.showText && props.theme.catalogItem.container.tablet.padding};
margin-bottom: ${(props) => margin-bottom: ${(props) =>

View File

@ -0,0 +1,145 @@
import React from 'react';
import { withTranslation } from 'react-i18next';
import Filter from '@appserver/common/api/people/filter';
import Loaders from '@appserver/common/components/Loaders';
import { inject, observer } from 'mobx-react';
import { getSelectedGroup } from '../../../helpers/people-helpers';
import { withRouter } from 'react-router';
import { isMobile } from '@appserver/components/utils/device';
import { isMobileOnly } from 'react-device-detect';
import config from '../../../../package.json';
import { combineUrl } from '@appserver/common/utils';
import { AppServerConfig } from '@appserver/common/constants';
import CatalogItem from '@appserver/components/catalog-item';
const departmentsIcon = 'images/departments.group.react.svg';
const groupIcon = '/static/images/catalog.folder.react.svg';
const CatalogBodyContent = ({
selectedKeys,
groups,
setFirstLoad,
toggleShowText,
showText,
groupsCaption,
history,
filter,
selectGroup,
isVisitor,
isLoaded,
setDocumentTitle,
}) => {
React.useEffect(() => {
changeTitleDocument();
setFirstLoad(false);
}, []);
React.useEffect(() => {
changeTitleDocument();
}, [selectedKeys[0]]);
const changeTitleDocument = (id) => {
const currentGroup = getSelectedGroup(groups, id === 'root' ? selectedKeys[0] : id);
currentGroup ? setDocumentTitle(currentGroup.name) : setDocumentTitle();
};
const isActive = (group) => {
if (group === selectedKeys[0]) return true;
return false;
};
const onClick = (data) => {
const isRoot = data === 'departments';
const groupId = isRoot ? 'root' : data;
changeTitleDocument(groupId);
if (window.location.pathname.indexOf('/people/filter') > 0) {
selectGroup(groupId);
if (isMobileOnly || isMobile()) toggleShowText();
} else {
const newFilter = isRoot ? Filter.getDefault() : filter.clone();
if (!isRoot) newFilter.group = groupId;
const urlFilter = newFilter.toUrlParams();
const url = combineUrl(AppServerConfig.proxyURL, config.homepage, `/filter?${urlFilter}`);
history.push(url);
if (isMobileOnly || isMobile()) toggleShowText();
}
};
const getItems = (data) => {
const items = data.map((group) => {
return (
<CatalogItem
key={group.id}
id={group.id}
icon={groupIcon}
text={group.name}
showText={showText}
showInitial={true}
onClick={onClick}
isActive={isActive(group.id)}
/>
);
});
return items;
};
return (
!isVisitor &&
(!isLoaded ? (
<Loaders.TreeFolders />
) : (
<>
<CatalogItem
key={'root'}
id={'departments'}
icon={departmentsIcon}
onClick={onClick}
text={groupsCaption}
showText={showText}
isActive={isActive('root')}
/>
{getItems(groups)}
</>
))
);
};
const BodyContent = withTranslation('Article')(withRouter(CatalogBodyContent));
export default inject(({ auth, peopleStore }) => {
const { settingsStore, isLoaded, setDocumentTitle, isAdmin } = auth;
const { customNames, showText, toggleShowText } = settingsStore;
const {
groupsStore,
selectedGroupStore,
editingFormStore,
filterStore,
loadingStore,
} = peopleStore;
const { filter } = filterStore;
const { groups } = groupsStore;
const { groupsCaption } = customNames;
const { isEdit, setIsVisibleDataLossDialog } = editingFormStore;
const { selectedGroup, selectGroup } = selectedGroupStore;
const selectedKeys = selectedGroup ? [selectedGroup] : ['root'];
const { setFirstLoad, isLoading } = loadingStore;
return {
setDocumentTitle,
isLoaded,
isVisitor: auth.userStore.user.isVisitor,
isAdmin,
groups,
groups,
groupsCaption,
selectedKeys,
selectGroup,
isEdit,
setIsVisibleDataLossDialog,
isLoading,
filter,
setFirstLoad,
showText,
toggleShowText,
};
})(observer(BodyContent));

View File

@ -0,0 +1,15 @@
import React from 'react';
import Loaders from '@appserver/common/components/Loaders';
import { inject, observer } from 'mobx-react';
const CatalogHeaderContent = ({ isVisitor, isLoaded, currentModuleName }) => {
return !isVisitor && (isLoaded ? <>{currentModuleName}</> : <Loaders.ArticleHeader />);
};
export default inject(({ auth }) => {
return {
isVisitor: auth.userStore.user.isVisitor,
isLoaded: auth.isLoaded,
currentModuleName: auth.product.title,
};
})(observer(CatalogHeaderContent));

View File

@ -0,0 +1,134 @@
import React from 'react';
//import PropTypes from "prop-types";
import { withRouter } from 'react-router';
import MainButton from '@appserver/components/main-button';
import DropDownItem from '@appserver/components/drop-down-item';
import InviteDialog from './../../dialogs/InviteDialog/index';
import { withTranslation } from 'react-i18next';
import toastr from 'studio/toastr';
import Loaders from '@appserver/common/components/Loaders';
import { inject, observer } from 'mobx-react';
import config from '../../../../package.json';
import { combineUrl } from '@appserver/common/utils';
import { AppServerConfig } from '@appserver/common/constants';
import withLoader from '../../../HOCs/withLoader';
import { isMobile } from 'react-device-detect';
import { isMobile as isMobileUtils } from '@appserver/components/utils/device';
class CatalogMainButtonContent extends React.Component {
constructor(props) {
super(props);
this.state = {
dialogVisible: false,
};
}
onImportClick = () => {
const { history, homepage } = this.props;
history.push(combineUrl(AppServerConfig.proxyURL, homepage, '${homepage}/import'));
if (isMobile || isMobileUtils()) this.props.toggleShowText();
};
goToEmployeeCreate = () => {
const { history, homepage } = this.props;
history.push(combineUrl(AppServerConfig.proxyURL, homepage, '/create/user'));
if (isMobile || isMobileUtils()) this.props.toggleShowText();
};
goToGuestCreate = () => {
const { history, homepage } = this.props;
history.push(combineUrl(AppServerConfig.proxyURL, homepage, '/create/guest'));
if (isMobile || isMobileUtils()) this.props.toggleShowText();
};
goToGroupCreate = () => {
const { history, homepage } = this.props;
history.push(combineUrl(AppServerConfig.proxyURL, homepage, '/group/create'));
if (isMobile || isMobileUtils()) this.props.toggleShowText();
};
onNotImplementedClick = (text) => {
toastr.success(text);
};
onInvitationDialogClick = () => this.setState({ dialogVisible: !this.state.dialogVisible });
render() {
//console.log("People ArticleMainButtonContent render");
const { t, isAdmin, homepage, userCaption, guestCaption, groupCaption } = this.props;
const { dialogVisible } = this.state;
return isAdmin ? (
<>
<MainButton isDisabled={false} isDropdown={true} text={t('Common:Actions')}>
<DropDownItem
icon={combineUrl(AppServerConfig.proxyURL, homepage, '/images/add.employee.react.svg')}
label={userCaption}
onClick={this.goToEmployeeCreate}
/>
<DropDownItem
icon={combineUrl(AppServerConfig.proxyURL, homepage, '/images/add.guest.react.svg')}
label={guestCaption}
onClick={this.goToGuestCreate}
/>
<DropDownItem
icon={combineUrl(
AppServerConfig.proxyURL,
homepage,
'/images/add.department.react.svg',
)}
label={groupCaption}
onClick={this.goToGroupCreate}
/>
<DropDownItem isSeparator />
<DropDownItem
icon={combineUrl(AppServerConfig.proxyURL, '/static/images/invitation.link.react.svg')}
label={t('Translations:InviteLinkTitle')}
onClick={this.onInvitationDialogClick}
/>
{/* <DropDownItem
icon="images/plane.react.svg"
label={t("SendInvitesAgain")}
onClick={this.onNotImplementedClick.bind(this, t("SendInvitesAgain"))}
/> */}
{false && (
<DropDownItem
icon={combineUrl(AppServerConfig.proxyURL, homepage, '/images/import.react.svg')}
label={t('ImportPeople')}
onClick={this.onImportClick}
/>
)}
</MainButton>
{dialogVisible && (
<InviteDialog
visible={dialogVisible}
onClose={this.onInvitationDialogClick}
onCloseButton={this.onInvitationDialogClick}
/>
)}
</>
) : (
<></>
);
}
}
export default withRouter(
inject(({ auth }) => {
const { userCaption, guestCaption, groupCaption } = auth.settingsStore.customNames;
return {
isAdmin: auth.isAdmin,
homepage: config.homepage,
userCaption,
guestCaption,
groupCaption,
toggleShowText: auth.settingsStore.toggleShowText,
};
})(
withTranslation(['Article', 'Common', 'Translations'])(
withLoader(observer(CatalogMainButtonContent))(<Loaders.MainButton />),
),
),
);

View File

@ -0,0 +1,3 @@
export { default as CatalogHeaderContent } from './Header';
export { default as CatalogBodyContent } from './Body';
export { default as CatalogMainButtonContent } from './MainButton';

View File

@ -1,22 +1,27 @@
import React from "react"; import React from 'react';
import Loader from "@appserver/components/loader"; import Loader from '@appserver/components/loader';
import PageLayout from "@appserver/common/components/PageLayout"; import PageLayout from '@appserver/common/components/PageLayout';
import { import {
ArticleHeaderContent, ArticleHeaderContent,
ArticleMainButtonContent, ArticleMainButtonContent,
ArticleBodyContent, ArticleBodyContent,
} from "../../components/Article"; } from '../../components/Article';
import { SectionHeaderContent, SectionBodyContent } from "./Section"; import {
import { withTranslation } from "react-i18next"; CatalogHeaderContent,
import { withRouter } from "react-router"; CatalogMainButtonContent,
import { inject, observer } from "mobx-react"; CatalogBodyContent,
} from '../../components/Catalog';
import { SectionHeaderContent, SectionBodyContent } from './Section';
import { withTranslation } from 'react-i18next';
import { withRouter } from 'react-router';
import { inject, observer } from 'mobx-react';
class GroupAction extends React.Component { class GroupAction extends React.Component {
componentDidMount() { componentDidMount() {
const { match, fetchGroup, t, setDocumentTitle, setFirstLoad } = this.props; const { match, fetchGroup, t, setDocumentTitle, setFirstLoad } = this.props;
const { groupId } = match.params; const { groupId } = match.params;
setFirstLoad(false); setFirstLoad(false);
setDocumentTitle(t("GroupAction")); setDocumentTitle(t('GroupAction'));
if (groupId) { if (groupId) {
fetchGroup(groupId); fetchGroup(groupId);
@ -38,25 +43,48 @@ class GroupAction extends React.Component {
} }
render() { render() {
console.log("GroupAction render"); console.log('GroupAction render');
const { group, match, tReady } = this.props; const { group, match, tReady, isAdmin, showCatalog } = this.props;
return ( return (
<> <>
{group || !match.params.groupId ? ( {group || !match.params.groupId ? (
<PageLayout withBodyScroll={true}> <PageLayout withBodyScroll={true}>
{showCatalog && (
<PageLayout.CatalogHeader>
<CatalogHeaderContent />
</PageLayout.CatalogHeader>
)}
{showCatalog && isAdmin && (
<PageLayout.CatalogMainButton>
<CatalogMainButtonContent />
</PageLayout.CatalogMainButton>
)}
{showCatalog && (
<PageLayout.CatalogBody>
<CatalogBodyContent />
</PageLayout.CatalogBody>
)}
{!showCatalog && (
<PageLayout.ArticleHeader> <PageLayout.ArticleHeader>
<ArticleHeaderContent /> <ArticleHeaderContent />
</PageLayout.ArticleHeader> </PageLayout.ArticleHeader>
)}
{!showCatalog && (
<PageLayout.ArticleMainButton> <PageLayout.ArticleMainButton>
<ArticleMainButtonContent /> <ArticleMainButtonContent />
</PageLayout.ArticleMainButton> </PageLayout.ArticleMainButton>
)}
{!showCatalog && (
<PageLayout.ArticleBody> <PageLayout.ArticleBody>
<ArticleBodyContent /> <ArticleBodyContent />
</PageLayout.ArticleBody> </PageLayout.ArticleBody>
)}
<PageLayout.SectionHeader> <PageLayout.SectionHeader>
<SectionHeaderContent /> <SectionHeaderContent />
@ -90,18 +118,12 @@ class GroupAction extends React.Component {
} }
} }
const GroupActionContainer = withTranslation(["GroupAction", "Common"])( const GroupActionContainer = withTranslation(['GroupAction', 'Common'])(GroupAction);
GroupAction
);
export default withRouter( export default withRouter(
inject(({ auth, peopleStore }) => { inject(({ auth, peopleStore }) => {
const { setDocumentTitle } = auth; const { setDocumentTitle } = auth;
const { selectedGroupStore, loadingStore } = peopleStore; const { selectedGroupStore, loadingStore } = peopleStore;
const { const { setTargetedGroup: fetchGroup, targetedGroup: group, resetGroup } = selectedGroupStore;
setTargetedGroup: fetchGroup,
targetedGroup: group,
resetGroup,
} = selectedGroupStore;
const { setFirstLoad } = loadingStore; const { setFirstLoad } = loadingStore;
return { return {
setDocumentTitle, setDocumentTitle,
@ -109,6 +131,8 @@ export default withRouter(
group, group,
resetGroup, resetGroup,
setFirstLoad, setFirstLoad,
isAdmin: auth.isAdmin,
showCatalog: auth.settingsStore.showCatalog,
}; };
})(observer(GroupActionContainer)) })(observer(GroupActionContainer)),
); );

View File

@ -1,42 +1,49 @@
import React, { useEffect } from "react"; import React, { useEffect } from 'react';
import PropTypes from "prop-types"; import PropTypes from 'prop-types';
import { withRouter } from "react-router"; import { withRouter } from 'react-router';
import Filter from "@appserver/common/api/people/filter"; import Filter from '@appserver/common/api/people/filter';
import PageLayout from "@appserver/common/components/PageLayout"; import PageLayout from '@appserver/common/components/PageLayout';
import { showLoader, hideLoader } from "@appserver/common/utils"; import { showLoader, hideLoader, isAdmin } from '@appserver/common/utils';
import { import {
ArticleHeaderContent, ArticleHeaderContent,
ArticleBodyContent, ArticleBodyContent,
ArticleMainButtonContent, ArticleMainButtonContent,
} from "../../components/Article"; } from '../../components/Article';
import {
CatalogHeaderContent,
CatalogMainButtonContent,
CatalogBodyContent,
} from '../../components/Catalog';
import { import {
SectionHeaderContent, SectionHeaderContent,
SectionBodyContent, SectionBodyContent,
SectionFilterContent, SectionFilterContent,
SectionPagingContent, SectionPagingContent,
} from "./Section"; } from './Section';
import { inject, observer } from "mobx-react"; import { inject, observer } from 'mobx-react';
import { isMobile } from "react-device-detect"; import { isMobile } from 'react-device-detect';
import Dialogs from "./Section/Body/Dialogs"; //TODO: Move dialogs to another folder import Dialogs from './Section/Body/Dialogs'; //TODO: Move dialogs to another folder
const Home = ({ const Home = ({
isAdmin,
isLoading, isLoading,
history, history,
getUsersList, getUsersList,
setIsLoading, setIsLoading,
setIsRefresh, setIsRefresh,
selectedGroup, selectedGroup,
showCatalog,
}) => { }) => {
const { location } = history; const { location } = history;
const { pathname } = location; const { pathname } = location;
console.log("People Home render"); console.log('People Home render');
useEffect(() => { useEffect(() => {
if (pathname.indexOf("/people/filter") > -1) { if (pathname.indexOf('/people/filter') > -1) {
setIsLoading(true); setIsLoading(true);
setIsRefresh(true); setIsRefresh(true);
const newFilter = Filter.getFilter(location); const newFilter = Filter.getFilter(location);
console.log("PEOPLE URL changed", pathname, newFilter); console.log('PEOPLE URL changed', pathname, newFilter);
getUsersList(newFilter).finally(() => { getUsersList(newFilter).finally(() => {
setIsLoading(false); setIsLoading(false);
setIsRefresh(false); setIsRefresh(false);
@ -45,9 +52,7 @@ const Home = ({
}, [pathname, location]); }, [pathname, location]);
useEffect(() => { useEffect(() => {
if (isMobile) { if (isMobile) {
const customScrollElm = document.querySelector( const customScrollElm = document.querySelector('#customScrollBar > .scroll-body');
"#customScrollBar > .scroll-body"
);
customScrollElm && customScrollElm.scrollTo(0, 0); customScrollElm && customScrollElm.scrollTo(0, 0);
} }
}, [selectedGroup]); }, [selectedGroup]);
@ -58,22 +63,41 @@ const Home = ({
return ( return (
<> <>
<PageLayout <PageLayout withBodyScroll withBodyAutoFocus={!isMobile} isLoading={isLoading}>
withBodyScroll {showCatalog && (
withBodyAutoFocus={!isMobile} <PageLayout.CatalogHeader>
isLoading={isLoading} <CatalogHeaderContent />
> </PageLayout.CatalogHeader>
)}
{showCatalog && isAdmin && (
<PageLayout.CatalogMainButton>
<CatalogMainButtonContent />
</PageLayout.CatalogMainButton>
)}
{showCatalog && (
<PageLayout.CatalogBody>
<CatalogBodyContent />
</PageLayout.CatalogBody>
)}
{!showCatalog && (
<PageLayout.ArticleHeader> <PageLayout.ArticleHeader>
<ArticleHeaderContent /> <ArticleHeaderContent />
</PageLayout.ArticleHeader> </PageLayout.ArticleHeader>
)}
{!showCatalog && (
<PageLayout.ArticleMainButton> <PageLayout.ArticleMainButton>
<ArticleMainButtonContent /> <ArticleMainButtonContent />
</PageLayout.ArticleMainButton> </PageLayout.ArticleMainButton>
)}
{!showCatalog && (
<PageLayout.ArticleBody> <PageLayout.ArticleBody>
<ArticleBodyContent /> <ArticleBodyContent />
</PageLayout.ArticleBody> </PageLayout.ArticleBody>
)}
<PageLayout.SectionHeader> <PageLayout.SectionHeader>
<SectionHeaderContent /> <SectionHeaderContent />
@ -101,17 +125,21 @@ Home.propTypes = {
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
}; };
export default inject(({ peopleStore }) => { export default inject(({ auth, peopleStore }) => {
const { settingsStore } = auth;
const { showCatalog, showText, toggleShowText, userShowText } = settingsStore;
const { usersStore, selectedGroupStore, loadingStore } = peopleStore; const { usersStore, selectedGroupStore, loadingStore } = peopleStore;
const { getUsersList } = usersStore; const { getUsersList } = usersStore;
const { selectedGroup } = selectedGroupStore; const { selectedGroup } = selectedGroupStore;
const { isLoading, setIsLoading, setIsRefresh } = loadingStore; const { isLoading, setIsLoading, setIsRefresh } = loadingStore;
return { return {
isAdmin: auth.isAdmin,
isLoading, isLoading,
getUsersList, getUsersList,
setIsLoading, setIsLoading,
setIsRefresh, setIsRefresh,
selectedGroup, selectedGroup,
showCatalog,
}; };
})(observer(withRouter(Home))); })(observer(withRouter(Home)));

View File

@ -1,17 +1,22 @@
import React from "react"; import React from 'react';
import PropTypes from "prop-types"; import PropTypes from 'prop-types';
import PageLayout from "@appserver/common/components/PageLayout"; import PageLayout from '@appserver/common/components/PageLayout';
import toastr from "studio/toastr"; import toastr from 'studio/toastr';
import { import {
ArticleHeaderContent, ArticleHeaderContent,
ArticleMainButtonContent, ArticleMainButtonContent,
ArticleBodyContent, ArticleBodyContent,
} from "../../components/Article"; } from '../../components/Article';
import { SectionHeaderContent, SectionBodyContent } from "./Section"; import {
import { withRouter } from "react-router"; CatalogHeaderContent,
CatalogMainButtonContent,
CatalogBodyContent,
} from '../../components/Catalog';
import { SectionHeaderContent, SectionBodyContent } from './Section';
import { withRouter } from 'react-router';
import { inject, observer } from "mobx-react"; import { inject, observer } from 'mobx-react';
import { withTranslation } from "react-i18next"; import { withTranslation } from 'react-i18next';
class Profile extends React.Component { class Profile extends React.Component {
componentDidMount() { componentDidMount() {
@ -32,19 +37,17 @@ class Profile extends React.Component {
setFirstLoad(false); setFirstLoad(false);
setIsEditTargetUser(false); setIsEditTargetUser(false);
if (!userId) userId = "@self"; if (!userId) userId = '@self';
setDocumentTitle(t("Common:Profile")); setDocumentTitle(t('Common:Profile'));
this.documentElement = document.getElementsByClassName("hidingHeader"); this.documentElement = document.getElementsByClassName('hidingHeader');
const queryString = ((location && location.search) || "").slice(1); const queryString = ((location && location.search) || '').slice(1);
const queryParams = queryString.split("&"); const queryParams = queryString.split('&');
const arrayOfQueryParams = queryParams.map((queryParam) => const arrayOfQueryParams = queryParams.map((queryParam) => queryParam.split('='));
queryParam.split("=")
);
const linkParams = Object.fromEntries(arrayOfQueryParams); const linkParams = Object.fromEntries(arrayOfQueryParams);
if (linkParams.email_change && linkParams.email_change === "success") { if (linkParams.email_change && linkParams.email_change === 'success') {
toastr.success(t("ChangeEmailSuccess")); toastr.success(t('ChangeEmailSuccess'));
} }
if (!profile || profile.userName !== userId) { if (!profile || profile.userName !== userId) {
setIsLoading(true); setIsLoading(true);
@ -57,7 +60,7 @@ class Profile extends React.Component {
if (!profile && this.documentElement) { if (!profile && this.documentElement) {
for (var i = 0; i < this.documentElement.length; i++) { for (var i = 0; i < this.documentElement.length; i++) {
this.documentElement[i].style.transition = "none"; this.documentElement[i].style.transition = 'none';
} }
} }
} }
@ -74,7 +77,7 @@ class Profile extends React.Component {
if (profile && this.documentElement) { if (profile && this.documentElement) {
for (var i = 0; i < this.documentElement.length; i++) { for (var i = 0; i < this.documentElement.length; i++) {
this.documentElement[i].style.transition = ""; this.documentElement[i].style.transition = '';
} }
} }
} }
@ -89,21 +92,44 @@ class Profile extends React.Component {
render() { render() {
//console.log("Profile render"); //console.log("Profile render");
const { profile } = this.props; const { profile, showCatalog, isAdmin } = this.props;
return ( return (
<PageLayout withBodyAutoFocus> <PageLayout withBodyAutoFocus>
{showCatalog && (
<PageLayout.CatalogHeader>
<CatalogHeaderContent />
</PageLayout.CatalogHeader>
)}
{showCatalog && isAdmin && (
<PageLayout.CatalogMainButton>
<CatalogMainButtonContent />
</PageLayout.CatalogMainButton>
)}
{showCatalog && (
<PageLayout.CatalogBody>
<CatalogBodyContent />
</PageLayout.CatalogBody>
)}
{!showCatalog && (
<PageLayout.ArticleHeader> <PageLayout.ArticleHeader>
<ArticleHeaderContent /> <ArticleHeaderContent />
</PageLayout.ArticleHeader> </PageLayout.ArticleHeader>
)}
{!showCatalog && (
<PageLayout.ArticleMainButton> <PageLayout.ArticleMainButton>
<ArticleMainButtonContent /> <ArticleMainButtonContent />
</PageLayout.ArticleMainButton> </PageLayout.ArticleMainButton>
)}
{!showCatalog && (
<PageLayout.ArticleBody> <PageLayout.ArticleBody>
<ArticleBodyContent /> <ArticleBodyContent />
</PageLayout.ArticleBody> </PageLayout.ArticleBody>
)}
<PageLayout.SectionHeader> <PageLayout.SectionHeader>
<SectionHeaderContent profile={profile} /> <SectionHeaderContent profile={profile} />
@ -150,6 +176,7 @@ export default withRouter(
isEditTargetUser, isEditTargetUser,
setIsEditTargetUser, setIsEditTargetUser,
setLoadedProfile, setLoadedProfile,
showCatalog: auth.settingsStore.showCatalog,
}; };
})(observer(withTranslation(["Profile", "Common"])(Profile))) })(observer(withTranslation(['Profile', 'Common'])(Profile))),
); );

View File

@ -1,27 +1,32 @@
import React from "react"; import React from 'react';
import PropTypes from "prop-types"; import PropTypes from 'prop-types';
import PageLayout from "@appserver/common/components/PageLayout"; import PageLayout from '@appserver/common/components/PageLayout';
import Loaders from "@appserver/common/components/Loaders"; import Loaders from '@appserver/common/components/Loaders';
import toastr from "studio/toastr"; import toastr from 'studio/toastr';
import { linkOAuth } from "@appserver/common/api/people"; import { linkOAuth } from '@appserver/common/api/people';
import { getAuthProviders } from "@appserver/common/api/settings"; import { getAuthProviders } from '@appserver/common/api/settings';
import { import {
ArticleHeaderContent, ArticleHeaderContent,
ArticleMainButtonContent, ArticleMainButtonContent,
ArticleBodyContent, ArticleBodyContent,
} from "../../components/Article"; } from '../../components/Article';
import SectionUserBody from "./Section/Body/index"; import {
CatalogHeaderContent,
CatalogMainButtonContent,
CatalogBodyContent,
} from '../../components/Catalog';
import SectionUserBody from './Section/Body/index';
import { import {
SectionHeaderContent, SectionHeaderContent,
// CreateUserForm, // CreateUserForm,
// UpdateUserForm, // UpdateUserForm,
// AvatarEditorPage, // AvatarEditorPage,
// CreateAvatarEditorPage, // CreateAvatarEditorPage,
} from "./Section"; } from './Section';
import { withTranslation } from "react-i18next"; import { withTranslation } from 'react-i18next';
import { withRouter } from "react-router"; import { withRouter } from 'react-router';
import { inject, observer } from "mobx-react"; import { inject, observer } from 'mobx-react';
class ProfileAction extends React.Component { class ProfileAction extends React.Component {
componentDidMount() { componentDidMount() {
@ -38,8 +43,8 @@ class ProfileAction extends React.Component {
} = this.props; } = this.props;
const { userId } = match.params; const { userId } = match.params;
setFirstLoad(false); setFirstLoad(false);
this.documentElement = document.getElementsByClassName("hidingHeader"); this.documentElement = document.getElementsByClassName('hidingHeader');
setDocumentTitle(t("ProfileAction")); setDocumentTitle(t('ProfileAction'));
if (isEdit) { if (isEdit) {
setIsEditingForm(false); setIsEditingForm(false);
} }
@ -50,7 +55,7 @@ class ProfileAction extends React.Component {
if (!this.loaded && this.documentElement) { if (!this.loaded && this.documentElement) {
for (var i = 0; i < this.documentElement.length; i++) { for (var i = 0; i < this.documentElement.length; i++) {
this.documentElement[i].style.transition = "none"; this.documentElement[i].style.transition = 'none';
} }
} }
} }
@ -66,7 +71,7 @@ class ProfileAction extends React.Component {
if (this.loaded && this.documentElement) { if (this.loaded && this.documentElement) {
for (var i = 0; i < this.documentElement.length; i++) { for (var i = 0; i < this.documentElement.length; i++) {
this.documentElement[i].style.transition = ""; this.documentElement[i].style.transition = '';
} }
} }
} }
@ -76,10 +81,10 @@ class ProfileAction extends React.Component {
} }
render() { render() {
console.log("ProfileAction render"); console.log('ProfileAction render');
this.loaded = false; this.loaded = false;
const { profile, match, isMy, tReady } = this.props; const { profile, match, isMy, tReady, showCatalog, isAdmin } = this.props;
const { userId, type } = match.params; const { userId, type } = match.params;
if (type) { if (type) {
@ -90,17 +95,40 @@ class ProfileAction extends React.Component {
return ( return (
<PageLayout> <PageLayout>
{showCatalog && (
<PageLayout.CatalogHeader>
<CatalogHeaderContent />
</PageLayout.CatalogHeader>
)}
{showCatalog && isAdmin && (
<PageLayout.CatalogMainButton>
<CatalogMainButtonContent />
</PageLayout.CatalogMainButton>
)}
{showCatalog && (
<PageLayout.CatalogBody>
<CatalogBodyContent />
</PageLayout.CatalogBody>
)}
{!showCatalog && (
<PageLayout.ArticleHeader> <PageLayout.ArticleHeader>
<ArticleHeaderContent /> <ArticleHeaderContent />
</PageLayout.ArticleHeader> </PageLayout.ArticleHeader>
)}
{!showCatalog && (
<PageLayout.ArticleMainButton> <PageLayout.ArticleMainButton>
<ArticleMainButtonContent /> <ArticleMainButtonContent />
</PageLayout.ArticleMainButton> </PageLayout.ArticleMainButton>
)}
{!showCatalog && (
<PageLayout.ArticleBody> <PageLayout.ArticleBody>
<ArticleBodyContent /> <ArticleBodyContent />
</PageLayout.ArticleBody> </PageLayout.ArticleBody>
)}
<PageLayout.SectionHeader> <PageLayout.SectionHeader>
<SectionHeaderContent tReady={tReady} loaded={this.loaded} /> <SectionHeaderContent tReady={tReady} loaded={this.loaded} />
@ -126,12 +154,7 @@ ProfileAction.propTypes = {
export default withRouter( export default withRouter(
inject(({ auth, peopleStore }) => { inject(({ auth, peopleStore }) => {
const { setDocumentTitle } = auth; const { setDocumentTitle } = auth;
const { const { usersStore, editingFormStore, targetUserStore, loadingStore } = peopleStore;
usersStore,
editingFormStore,
targetUserStore,
loadingStore,
} = peopleStore;
const { setProviders } = usersStore; const { setProviders } = usersStore;
const { isEdit, setIsEditingForm } = editingFormStore; const { isEdit, setIsEditingForm } = editingFormStore;
const { const {
@ -151,6 +174,8 @@ export default withRouter(
setFirstLoad, setFirstLoad,
setLoadedProfile, setLoadedProfile,
setIsEditTargetUser, setIsEditTargetUser,
isAdmin: auth.isAdmin,
showCatalog: auth.settingsStore.showCatalog,
}; };
})(withTranslation(["ProfileAction", "Common"])(observer(ProfileAction))) })(withTranslation(['ProfileAction', 'Common'])(observer(ProfileAction))),
); );