From c039aed02565c591b8c2a6f9c1745dc81daa9164 Mon Sep 17 00:00:00 2001 From: Yurii Hryshchenko <79473530+YuriyHryshchenko@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:29:17 +0300 Subject: [PATCH] Bugfix694 personal information (#829) * Select current user to display info about him on Personal Information page * Fix import order --- src/old/lib/components/Users/LoginModal.tsx | 3 +++ src/views/Profile/OperationView.tsx | 5 ++++- src/views/Profile/PersonalInfo/PersonalInfo.tsx | 8 +++++--- src/views/Profile/PersonalInfo/types.ts | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/old/lib/components/Users/LoginModal.tsx b/src/old/lib/components/Users/LoginModal.tsx index c814683a9..bafd00995 100644 --- a/src/old/lib/components/Users/LoginModal.tsx +++ b/src/old/lib/components/Users/LoginModal.tsx @@ -26,6 +26,7 @@ import { BasicButton, BasicInput } from '../../../../components/Form'; import { useActions } from '../../../../shared/hooks'; import { getAuthoritiesAsyncAction } from '../../../../models/authorities'; import './LoginModal.css'; +import { fetchCities } from '../../../../models/properties'; export const LoginModal: React.FC = () => { const { t } = useTranslation(); @@ -42,6 +43,7 @@ export const LoginModal: React.FC = () => { }); const [boundAuthorities] = useActions([getAuthoritiesAsyncAction]); + const [boundCities] = useActions([fetchCities]); const handleLoginOpen = () => { setLoginOpen(true); @@ -71,6 +73,7 @@ export const LoginModal: React.FC = () => { .then((response) => { setAuthorization(response.data.accessToken); boundAuthorities(); + boundCities(); handleLoginClose(); swalWithCustomButton .fire( diff --git a/src/views/Profile/OperationView.tsx b/src/views/Profile/OperationView.tsx index a021c6fb0..b4ccb99e8 100644 --- a/src/views/Profile/OperationView.tsx +++ b/src/views/Profile/OperationView.tsx @@ -1,10 +1,12 @@ import React from 'react'; import { Container } from '@material-ui/core'; +import { useSelector } from 'react-redux'; import { MaterialsViewWrapper } from './MaterialsView/MaterialsViewWrapper'; import { useStyles } from './styles/OperationView.styles'; import { IProfileMenuOption } from '../../old/lib/types'; import { PasswordChangeView } from './PasswordChangeView'; import { PersonalInfo } from './PersonalInfo/PersonalInfo'; +import { selectCurrentUser } from '../../models/user'; interface IOperationViewProps { selectedOption: IProfileMenuOption | Record; @@ -14,9 +16,10 @@ export const OperationView: React.FC = (props) => { const { selectedOption } = props; const { value } = selectedOption; const classes = useStyles(); + const currentUser = useSelector(selectCurrentUser); const operationViews = { - info: , + info: , materials: , passwordChange: , mail:
Mail
, diff --git a/src/views/Profile/PersonalInfo/PersonalInfo.tsx b/src/views/Profile/PersonalInfo/PersonalInfo.tsx index 5e8d9c2b6..3414239ee 100644 --- a/src/views/Profile/PersonalInfo/PersonalInfo.tsx +++ b/src/views/Profile/PersonalInfo/PersonalInfo.tsx @@ -29,7 +29,10 @@ import { validation } from './constants/validation'; import { validateInput } from './utilities/validateInput'; import { usePrevious } from '../../../old/lib/hooks/usePrevious'; -export const PersonalInfo: React.FC = ({ author }) => { +export const PersonalInfo: React.FC = ({ + author, + isCurrentUser, +}) => { const classes = useStyles(); const [visitFields, setVisitFields] = useState({ @@ -202,7 +205,6 @@ export const PersonalInfo: React.FC = ({ author }) => { }), [errorMessages], ); - useEffect(() => { const handleBeforeUnload = (e: BeforeUnloadEvent) => { if (!_isEqual(previousAuthorValues, newAuthorValues)) { @@ -382,7 +384,7 @@ export const PersonalInfo: React.FC = ({ author }) => { - {author && ( + {author && !isCurrentUser && ( window.close()} diff --git a/src/views/Profile/PersonalInfo/types.ts b/src/views/Profile/PersonalInfo/types.ts index dda25097a..8b3960269 100644 --- a/src/views/Profile/PersonalInfo/types.ts +++ b/src/views/Profile/PersonalInfo/types.ts @@ -52,4 +52,5 @@ export interface IRegionCityHandlerProps { export interface IEditAuthorProps { author?: IExpert; + isCurrentUser?: boolean; }