Skip to content

Commit

Permalink
Bugfix694 personal information (#829)
Browse files Browse the repository at this point in the history
* Select current user to display info about him on Personal Information page

* Fix import order
  • Loading branch information
YuriyHryshchenko authored Oct 10, 2023
1 parent f74ca39 commit c039aed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/old/lib/components/Users/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -42,6 +43,7 @@ export const LoginModal: React.FC = () => {
});

const [boundAuthorities] = useActions([getAuthoritiesAsyncAction]);
const [boundCities] = useActions([fetchCities]);

const handleLoginOpen = () => {
setLoginOpen(true);
Expand Down Expand Up @@ -71,6 +73,7 @@ export const LoginModal: React.FC = () => {
.then((response) => {
setAuthorization(response.data.accessToken);
boundAuthorities();
boundCities();
handleLoginClose();
swalWithCustomButton
.fire(
Expand Down
5 changes: 4 additions & 1 deletion src/views/Profile/OperationView.tsx
Original file line number Diff line number Diff line change
@@ -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<string, never>;
Expand All @@ -14,9 +16,10 @@ export const OperationView: React.FC<IOperationViewProps> = (props) => {
const { selectedOption } = props;
const { value } = selectedOption;
const classes = useStyles();
const currentUser = useSelector(selectCurrentUser);

const operationViews = {
info: <PersonalInfo/>,
info: <PersonalInfo author={currentUser.data} isCurrentUser />,
materials: <MaterialsViewWrapper />,
passwordChange: <PasswordChangeView />,
mail: <div>Mail</div>,
Expand Down
8 changes: 5 additions & 3 deletions src/views/Profile/PersonalInfo/PersonalInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEditAuthorProps> = ({ author }) => {
export const PersonalInfo: React.FC<IEditAuthorProps> = ({
author,
isCurrentUser,
}) => {
const classes = useStyles();

const [visitFields, setVisitFields] = useState<IVisitFields>({
Expand Down Expand Up @@ -202,7 +205,6 @@ export const PersonalInfo: React.FC<IEditAuthorProps> = ({ author }) => {
}),
[errorMessages],
);

useEffect(() => {
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
if (!_isEqual(previousAuthorValues, newAuthorValues)) {
Expand Down Expand Up @@ -382,7 +384,7 @@ export const PersonalInfo: React.FC<IEditAuthorProps> = ({ author }) => {
</Grid>

<Box className={classes.ButtonBox}>
{author && (
{author && !isCurrentUser && (
<CancelButton
label={i18n.t(langTokens.common.cancelChanges)}
onClick={() => window.close()}
Expand Down
1 change: 1 addition & 0 deletions src/views/Profile/PersonalInfo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ export interface IRegionCityHandlerProps {

export interface IEditAuthorProps {
author?: IExpert;
isCurrentUser?: boolean;
}

0 comments on commit c039aed

Please sign in to comment.