diff --git a/src/components/Header/AccountMenu.tsx b/src/components/Header/AccountMenu.tsx index 5a9b9fe4d..4a5c42b33 100644 --- a/src/components/Header/AccountMenu.tsx +++ b/src/components/Header/AccountMenu.tsx @@ -18,8 +18,8 @@ import { useActions } from '../../shared/hooks'; import { AuthContext } from '../../old/provider/AuthProvider/AuthContext'; import { AccountIcon } from '../../old/lib/components/icons/AccountIcon'; import { langTokens } from '../../locales/localizationInit'; -import { selectAuthorities } from '../../models/authorities'; import { clearAuthoritiesAction } from '../../models/authorities/reducers'; +import { useCheckAdmin } from '../../old/lib/hooks/useCheckAdmin'; export const AccountMenu: React.FC = () => { const { t } = useTranslation(); @@ -32,9 +32,7 @@ export const AccountMenu: React.FC = () => { const [boundSignOutAction] = useActions([signOutAction]); const [boundGetUserAsyncAction] = useActions([getUserAsyncAction]); const [boundClearAuthorities] = useActions([clearAuthoritiesAction]); - const authorities = useSelector(selectAuthorities).data?.includes( - 'SET_IMPORTANCE', - ); + const authorities = useCheckAdmin(); const onLogoutHandler = () => { boundSignOutAction(); diff --git a/src/components/Page/PageTitle.tsx b/src/components/Page/PageTitle.tsx index 2ec41a2b8..0eea9a933 100644 --- a/src/components/Page/PageTitle.tsx +++ b/src/components/Page/PageTitle.tsx @@ -6,7 +6,8 @@ export interface IPageTitleProps { } export const PageTitle: React.FC = ({ title }) => { - const newTitle = title ? `${appTitle} | ${title}` : appTitle; + const newTitle = + title && title !== appTitle ? `${appTitle} | ${title}` : appTitle; useEffect(() => { document.title = newTitle; diff --git a/src/models/experts/asyncActions.ts b/src/models/experts/asyncActions.ts index ac21fe951..abcb1ecee 100644 --- a/src/models/experts/asyncActions.ts +++ b/src/models/experts/asyncActions.ts @@ -1,9 +1,9 @@ /* eslint-disable */ import { createAsyncThunk } from '@reduxjs/toolkit'; import { - IFetchExpertsOptions, IExpertsAutorsListOptions, IExpertsDeleteAutor, + IFetchExpertsOptions, } from './types'; import { deleteAuthorById, diff --git a/src/models/experts/types.ts b/src/models/experts/types.ts index 39fcab69e..13ca20c1b 100644 --- a/src/models/experts/types.ts +++ b/src/models/experts/types.ts @@ -19,12 +19,12 @@ export interface IExpertsData { } export const AuthorsListSortBy = { - autorId: 'id', + autorId: 'authorId', fullName: 'firstName,lastName', firstName: 'firstName', lastName: 'lastName', - region: 'doctor.mainInstitution.city.region.name', - city: 'doctor.mainInstitution.city.name', + region: 'author.mainInstitution.city.region.name', + city: 'author.mainInstitution.city.name', createdAt: 'createdAt', editedAt: 'editedAt', }; @@ -66,6 +66,7 @@ export interface IFetchExpertsOptions { export interface IExpertsAutorsListOptions { page: number; } + export interface IExpertsDeleteAutor { id: number; } diff --git a/src/old/lib/components/Users/AdminPage/components/AdminPageWrapper.tsx b/src/old/lib/components/Users/AdminPage/components/AdminPageWrapper.tsx index e05e1c2d5..c48f3e412 100644 --- a/src/old/lib/components/Users/AdminPage/components/AdminPageWrapper.tsx +++ b/src/old/lib/components/Users/AdminPage/components/AdminPageWrapper.tsx @@ -1,12 +1,13 @@ import React, { useState } from 'react'; -import { useSelector } from 'react-redux'; import { Box } from '@material-ui/core'; import { useStyles } from '../styles/AdminPageWrapper.styles'; import OperationView from './OperationView'; import Sidemenu from './Sidemenu'; import { IAdminMenuOption } from '../../../../types'; import Page404 from '../../../Errors/Page404'; -import { selectAuthorities } from '../../../../../../models/authorities'; +import { PageTitle } from '../../../../../../components/Page/PageTitle'; +import appTitle from '../../../../constants/appTitle'; +import { useCheckAdmin } from '../../../../hooks/useCheckAdmin'; const AdminPage: React.FC = () => { const [selectedOption, changeOption] = useState< @@ -18,12 +19,11 @@ const AdminPage: React.FC = () => { }); const classes = useStyles(); - const authorities = useSelector(selectAuthorities).data?.includes( - 'SET_IMPORTANCE', - ); + const authorities = useCheckAdmin(); return authorities ? ( + diff --git a/src/old/lib/hooks/useCheckAdmin.ts b/src/old/lib/hooks/useCheckAdmin.ts new file mode 100644 index 000000000..9914af9f5 --- /dev/null +++ b/src/old/lib/hooks/useCheckAdmin.ts @@ -0,0 +1,7 @@ +import { useSelector } from 'react-redux'; +import { selectAuthorities } from '../../../models/authorities'; + +export const useCheckAdmin = () => { + const authorities = useSelector(selectAuthorities); + return authorities?.data?.includes('SET_IMPORTANCE'); +}; diff --git a/src/old/lib/types.ts b/src/old/lib/types.ts index dddb7f844..e5f789dc4 100644 --- a/src/old/lib/types.ts +++ b/src/old/lib/types.ts @@ -3,6 +3,7 @@ export enum ExpertStatus { ACTIVE = 'ACTIVE', DELETED = 'DELETED', } + export enum PostStatus { DRAFT = 'DRAFT', MODERATION_FIRST_SIGN = 'MODERATION_FIRST_SIGN', @@ -149,6 +150,7 @@ export interface IExpert { avatar?: string; qualification?: string; phone?: string; + publicEmail?: string; email?: string; region: { id: number; diff --git a/src/old/lib/utilities/API/api.ts b/src/old/lib/utilities/API/api.ts index dcdec06a3..bb1bb4790 100644 --- a/src/old/lib/utilities/API/api.ts +++ b/src/old/lib/utilities/API/api.ts @@ -1,40 +1,42 @@ /* eslint-disable no-param-reassign */ import axios, { AxiosError, + AxiosPromise, AxiosRequestConfig, AxiosResponse, - AxiosPromise, } from 'axios'; import qs from 'qs'; import { toast } from 'react-toastify'; import { IChangeLogOptions } from 'models/changeLog/types'; import { + ActiveDirectionType, + ActivePostType, + CityResponseType, + CreateAuthorRequestType, CreatePostRequestUnionType, CreateTagRequestType, DirectionResponseType, ExpertResponseType, ExpertsResponseType, + GetChangeLogType, GetExpertsConfigType, - GetPostsConfigType, - GetPostsAdminConfigType, GetFilteredPostsType, + GetPostsAdminConfigType, + GetPostsConfigType, GetTagsConfigType, LoginResponseType, NewestPostsResponseType, OriginResponseType, + PlatformInformationType, PostResponseType, PostsResponseType, PostTypeResponseType, RegionResponseType, TagResponseType, + UpdateAuthorRequestType, + UpdatePlatformInformationRequestType, UpdatePostRequestUnionType, VersionResponseType, - ActivePostType, - ActiveDirectionType, - PlatformInformationType, - UpdatePlatformInformationRequestType, - CityResponseType, - GetChangeLogType, } from './types'; import { BASE_URL } from '../../../apiURL'; import { getToken } from '../../../provider/AuthProvider/getToken'; @@ -356,3 +358,15 @@ export const deleteAuthorById = async ( ): Promise> => { return instance.delete(`/author/${id}`); }; + +export const createAuthor = async ( + requestBody: CreateAuthorRequestType, +): Promise> => { + return instance.post(`/author`, requestBody); +}; + +export const updateAuthorById = async ( + requestBody: UpdateAuthorRequestType, +): Promise> => { + return instance.put(`/author`, requestBody); +}; diff --git a/src/old/lib/utilities/API/types.ts b/src/old/lib/utilities/API/types.ts index ecfcd5e3e..8cb328777 100644 --- a/src/old/lib/utilities/API/types.ts +++ b/src/old/lib/utilities/API/types.ts @@ -316,3 +316,18 @@ export type GetChangeLogType = ChangeLogType & { title?: string; totalPages: number; }; + +export type CreateAuthorRequestType = { + avatar?: string; + firstName: string; + lastName: string; + cityId: number | null; + bio: string; + publicEmail?: string; + socialNetworks: (string | null)[]; + mainWorkingPlace: string; +}; + +export type UpdateAuthorRequestType = { + authorId: number; +} & CreateAuthorRequestType; diff --git a/src/old/modules/experts/components/Accordion.tsx b/src/old/modules/experts/components/Accordion.tsx index c87372b69..df30281ba 100644 --- a/src/old/modules/experts/components/Accordion.tsx +++ b/src/old/modules/experts/components/Accordion.tsx @@ -20,6 +20,7 @@ const Accordion: React.FC = ({ expert }) => { ]); const classes = useStyles(); + function toggleDetails() { if (showDetails[0] === 'none') { setShowDetails(['block', t(langTokens.common.hideContacts), '-']); @@ -29,8 +30,8 @@ const Accordion: React.FC = ({ expert }) => { } let mailTo = ''; - if (expert.email) { - mailTo = `mailto:${expert.email}`; + if (expert.publicEmail) { + mailTo = `mailto:${expert.publicEmail}`; } return ( @@ -57,7 +58,7 @@ const Accordion: React.FC = ({ expert }) => { style={{ display: showDetails[0] }} className={classes.accordionDetails} > - {expert.email ? ( + {expert.publicEmail ? ( diff --git a/src/old/modules/experts/components/ExpertInfo.tsx b/src/old/modules/experts/components/ExpertInfo.tsx index 204f7f59e..32951a5d4 100644 --- a/src/old/modules/experts/components/ExpertInfo.tsx +++ b/src/old/modules/experts/components/ExpertInfo.tsx @@ -1,4 +1,4 @@ -import { Avatar, Grid, Typography, Box } from '@material-ui/core'; +import { Avatar, Box, Grid, Typography } from '@material-ui/core'; import React, { useContext } from 'react'; import { IExpert } from '../../../lib/types'; import { useStyles } from '../styles/ExpertInfo.styles'; diff --git a/src/old/modules/posts/components/PostView.tsx b/src/old/modules/posts/components/PostView.tsx index ce6146a01..6e14712ca 100644 --- a/src/old/modules/posts/components/PostView.tsx +++ b/src/old/modules/posts/components/PostView.tsx @@ -16,7 +16,7 @@ import SecondTopSection from '../../../../components/Posts/SecondTopSection/Seco import { langTokens } from '../../../../locales/localizationInit'; import { PostBreadcrumbs } from '../../../../components/Breadcrumbs/PostBreadcrumbs'; import { selectCurrentUser } from '../../../../models/user'; -import { selectAuthorities } from '../../../../models/authorities'; +import { useCheckAdmin } from '../../../lib/hooks/useCheckAdmin'; export interface IPostViewProps { post: IPost; @@ -28,8 +28,7 @@ const PostView: React.FC = ({ isPreview, post, onDelete }) => { const { t } = useTranslation(); const user = useSelector(selectCurrentUser); - const authorities = useSelector(selectAuthorities); - const isAdmin = authorities?.data?.includes('SET_IMPORTANCE'); + const isAdmin = useCheckAdmin(); const permission = user?.data?.id === post?.author?.id || isAdmin; const isTopSectionShown = diff --git a/src/old/navigation/router-config.ts b/src/old/navigation/router-config.ts index d60450c05..992a6b1e2 100644 --- a/src/old/navigation/router-config.ts +++ b/src/old/navigation/router-config.ts @@ -43,9 +43,7 @@ const PasswordResetView = lazy( const PasswordUpdateView = lazy( () => import('../../views/PasswordUpdate/PasswordUpdateView'), ); -const PersonalInfo = lazy( - () => import('../../views/Profile/PersonalInfo/PersonalInfo'), -); +const CreateAuthor = lazy(() => import('../../views/Profile/CreateAuthor')); const EditAuthor = lazy( () => import('../../views/Profile/EditAuthor/EditAuthor'), ); @@ -124,7 +122,7 @@ export const ROUTER_CONFIG: IRouteConfig[] = [ { path: '/create-author', key: 'CREATE_AUTHOR', - component: PersonalInfo, + component: CreateAuthor, private: true, exact: true, }, diff --git a/src/views/Profile/AdminTable/AdminTable.tsx b/src/views/Profile/AdminTable/AdminTable.tsx index 38dfcd97a..1a1e55fab 100644 --- a/src/views/Profile/AdminTable/AdminTable.tsx +++ b/src/views/Profile/AdminTable/AdminTable.tsx @@ -2,8 +2,8 @@ import React, { useEffect } from 'react'; import { Paper, Table, TableContainer } from '@material-ui/core'; import { useSelector } from 'react-redux'; import { - getMaterialsAction, getAuthorMaterialsAction, + getMaterialsAction, selectAdminLab, selectMeta, setStateToInit, @@ -13,8 +13,8 @@ import AdminTableHead from './AdminTableHead'; import AdminTableBody from './AdminTableBody'; import AdminTableFilters from './AdminTableFilters'; import AdminTablePagination from './AdminTablePagination'; -import { selectAuthorities } from '../../../models/authorities'; import { useActions } from '../../../shared/hooks'; +import { useCheckAdmin } from '../../../old/lib/hooks/useCheckAdmin'; interface IAdminTable { expertId?: number; @@ -22,8 +22,7 @@ interface IAdminTable { export const AdminTable: React.FC = ({ expertId }) => { const classes = useStyles(); - const authorities = useSelector(selectAuthorities); - const isAdmin = authorities.data?.includes('SET_IMPORTANCE'); + const isAdmin = useCheckAdmin(); const [ boundedGetMaterialsAction, boundGetAuthorMaterialsAction, diff --git a/src/views/Profile/AdminTable/AdminTableFilters.tsx b/src/views/Profile/AdminTable/AdminTableFilters.tsx index 2f4b90c16..f60d09447 100644 --- a/src/views/Profile/AdminTable/AdminTableFilters.tsx +++ b/src/views/Profile/AdminTable/AdminTableFilters.tsx @@ -3,26 +3,26 @@ import { useSelector } from 'react-redux'; import { Grid, IconButton, Tooltip } from '@material-ui/core'; import HighlightOffRoundedIcon from '@material-ui/icons/HighlightOffRounded'; import i18, { langTokens } from '../../../locales/localizationInit'; -import { selectAuthorities } from '../../../models/authorities'; import { QueryTypeEnum } from '../../../old/lib/types'; import { FieldEnum } from '../../../models/adminLab/types'; import { selectDirections, - selectPostTypes, selectPostStatuses, + selectPostTypes, } from '../../../models/properties'; import { selectMeta, - setFiltersToInit, - setFilter, - setField, setDate, + setField, + setFilter, + setFiltersToInit, } from '../../../models/adminLab'; import { AdminFilter } from './AdminFilter'; import { AdminDatePicker } from './AdminDatePicker'; import { AdminTextField } from './AdminTextField'; import { useStyles } from './styles/AdminTableFilters.styles'; import { useActions } from '../../../shared/hooks'; +import { useCheckAdmin } from '../../../old/lib/hooks/useCheckAdmin'; const AdminTableFilters: React.FC = () => { const [ @@ -37,8 +37,7 @@ const AdminTableFilters: React.FC = () => { const allPostStatuses = useSelector(selectPostStatuses); const { filters, date, textFields } = useSelector(selectMeta); - const authorities = useSelector(selectAuthorities); - const isAdmin = authorities.data?.includes('SET_IMPORTANCE'); + const isAdmin = useCheckAdmin(); const classes = useStyles(); const resetFilters = () => { diff --git a/src/views/Profile/CreateAuthor.tsx b/src/views/Profile/CreateAuthor.tsx new file mode 100644 index 000000000..8f65449f2 --- /dev/null +++ b/src/views/Profile/CreateAuthor.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import { PersonalInfo } from './PersonalInfo/PersonalInfo'; + +const CreateAuthor = () => { + const history = useHistory(); + return ( + history.push(`/experts/${id}`)} /> + ); +}; + +export default CreateAuthor; diff --git a/src/views/Profile/EditAuthor/EditAuthor.tsx b/src/views/Profile/EditAuthor/EditAuthor.tsx index 320734419..cdf4706f7 100644 --- a/src/views/Profile/EditAuthor/EditAuthor.tsx +++ b/src/views/Profile/EditAuthor/EditAuthor.tsx @@ -39,7 +39,10 @@ const EditAuthor = () => { } return loadedAuthor ? ( - + history.push(`experts/${id}`)} + /> ) : ( ); diff --git a/src/views/Profile/OperationView.tsx b/src/views/Profile/OperationView.tsx index b4ccb99e8..02c1e1502 100644 --- a/src/views/Profile/OperationView.tsx +++ b/src/views/Profile/OperationView.tsx @@ -6,7 +6,8 @@ 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'; +import { getUserAsyncAction, selectCurrentUser } from '../../models/user'; +import { useActions } from '../../shared/hooks'; interface IOperationViewProps { selectedOption: IProfileMenuOption | Record; @@ -17,9 +18,16 @@ export const OperationView: React.FC = (props) => { const { value } = selectedOption; const classes = useStyles(); const currentUser = useSelector(selectCurrentUser); + const [boundGetUserAsyncAction] = useActions([getUserAsyncAction]); const operationViews = { - info: , + info: ( + boundGetUserAsyncAction()} + /> + ), materials: , passwordChange: , mail:
Mail
, diff --git a/src/views/Profile/PersonalInfo/PersonalInfo.tsx b/src/views/Profile/PersonalInfo/PersonalInfo.tsx index 3414239ee..65a26c4fc 100644 --- a/src/views/Profile/PersonalInfo/PersonalInfo.tsx +++ b/src/views/Profile/PersonalInfo/PersonalInfo.tsx @@ -13,6 +13,8 @@ import { PhotoCamera } from '@material-ui/icons'; import { uploadImageToImgur } from 'old/lib/utilities/Imgur/uploadImageToImgur'; import { getStringFromFile } from 'old/lib/utilities/Imgur/getStringFromFile'; import _isEqual from 'lodash/isEqual'; +import axios from 'axios'; +import { toast } from 'react-toastify'; import { useStyles } from './styles/PersonalInfo.styles'; import { ErrorField } from './ErrorField'; import { regex } from './constants/regex'; @@ -28,10 +30,16 @@ import RegionCityHandler from './RegionCityHandler'; import { validation } from './constants/validation'; import { validateInput } from './utilities/validateInput'; import { usePrevious } from '../../../old/lib/hooks/usePrevious'; +import { + createAuthor, + updateAuthorById, +} from '../../../old/lib/utilities/API/api'; +import { useCheckAdmin } from '../../../old/lib/hooks/useCheckAdmin'; export const PersonalInfo: React.FC = ({ author, isCurrentUser, + onSaveSuccessful, }) => { const classes = useStyles(); @@ -40,8 +48,8 @@ export const PersonalInfo: React.FC = ({ firstName: false, region: false, city: false, - email: false, - work: false, + publicEmail: false, + mainWorkingPlace: false, bio: false, facebook: false, instagram: false, @@ -58,12 +66,14 @@ export const PersonalInfo: React.FC = ({ regionId: author?.region.id ?? null, cityId: author?.mainInstitution.city.id ?? null, bio: author?.bio ?? '', - email: author?.email ?? '', - socialNetwork: author?.socialNetworks ?? [null, null, null, null, null], - work: author?.mainInstitution.name ?? '', + publicEmail: author?.publicEmail ?? '', + socialNetworks: author?.socialNetworks ?? [null, null, null, null, null], + mainWorkingPlace: author?.mainInstitution.name ?? '', }); const previousAuthorValues = usePrevious(newAuthorValues); + const [isLoading, setIsLoading] = useState(false); + const isAdmin = useCheckAdmin(); const errorMessages = useMemo(() => { const errors: IErrorFields = { avatar: '', @@ -71,8 +81,8 @@ export const PersonalInfo: React.FC = ({ firstName: '', regionId: '', cityId: '', - email: '', - work: '', + publicEmail: '', + mainWorkingPlace: '', bio: '', socialNetworks: ['', '', '', '', ''], socialNetwoksRequired: '', @@ -104,23 +114,23 @@ export const PersonalInfo: React.FC = ({ validation.bio.max, validation.bio.regexp, ); - errors.work = validateInput( - newAuthorValues.work, + errors.mainWorkingPlace = validateInput( + newAuthorValues.mainWorkingPlace, validation.bio.min, validation.bio.max, validation.bio.regexp, ); - if (!newAuthorValues.email && visitFields.email) { - errors.email = i18n.t(langTokens.admin.fieldCantBeEmpty); + if (!newAuthorValues.publicEmail && visitFields.publicEmail) { + errors.publicEmail = i18n.t(langTokens.admin.fieldCantBeEmpty); } else if ( - newAuthorValues.email && - !regex.validEmail.test(newAuthorValues.email) + newAuthorValues.publicEmail && + !regex.validEmail.test(newAuthorValues.publicEmail) ) { - errors.email = i18n.t(langTokens.admin.wrongEmail); + errors.publicEmail = i18n.t(langTokens.admin.wrongEmail); } else { - errors.email = ''; + errors.publicEmail = ''; } - newAuthorValues.socialNetwork.forEach((sn, index) => { + newAuthorValues.socialNetworks.forEach((sn, index) => { if (sn) { errors.socialNetworks[index] = validateInput( sn, @@ -130,7 +140,7 @@ export const PersonalInfo: React.FC = ({ ); } }); - if (newAuthorValues.socialNetwork.some((socialNetwork) => socialNetwork)) { + if (newAuthorValues.socialNetworks.some((socialNetwork) => socialNetwork)) { errors.socialNetwoksRequired = ''; } else { errors.socialNetwoksRequired = i18n.t( @@ -156,11 +166,11 @@ export const PersonalInfo: React.FC = ({ index: number, ) => { const { value } = event.target; - const newSocialNetworks = [...newAuthorValues.socialNetwork]; + const newSocialNetworks = [...newAuthorValues.socialNetworks]; newSocialNetworks.splice(index, 1, value); setNewAuthorValues({ ...newAuthorValues, - socialNetwork: newSocialNetworks, + socialNetworks: newSocialNetworks, }); }; @@ -188,11 +198,30 @@ export const PersonalInfo: React.FC = ({ setVisitFields({ ...visitFields, [inputIdentifier]: true }); }; - const buttonClickHandler = () => { - // TODO dispatch new author to server + const buttonClickHandler = async ( + e: React.MouseEvent, + ) => { + e.preventDefault(); + try { + setIsLoading(true); + const response = author + ? await updateAuthorById({ authorId: author.id, ...newAuthorValues }) + : await createAuthor(newAuthorValues); + + onSaveSuccessful(response.data.id); + } catch (err) { + if (axios.isAxiosError(err)) { + console.error(err.response); + } else { + console.error(err); + toast.error('Error occurred...'); + } + } finally { + setIsLoading(false); + } }; - const isSaveDisabled = useMemo( + const anyFieldWithError = useMemo( () => Object.keys(errorMessages).some((key) => { if (key === 'socialNetworks') { @@ -205,6 +234,7 @@ export const PersonalInfo: React.FC = ({ }), [errorMessages], ); + const isSaveDisabled = anyFieldWithError || isLoading; useEffect(() => { const handleBeforeUnload = (e: BeforeUnloadEvent) => { if (!_isEqual(previousAuthorValues, newAuthorValues)) { @@ -241,6 +271,7 @@ export const PersonalInfo: React.FC = ({ + @@ -252,6 +283,7 @@ export const PersonalInfo: React.FC = ({ = ({ = ({ {i18n.t(langTokens.admin.socialNetworkLinks)} - {visitFields.email && errorMessages.email && ( + {visitFields.publicEmail && errorMessages.publicEmail && ( - {errorMessages.email} + {errorMessages.publicEmail} )} = ({ required fullWidth label={i18n.t(langTokens.admin.email)} - name="email" - value={newAuthorValues.email} + name="publicEmail" + value={newAuthorValues.publicEmail} onChange={(event) => inputChangeHandler(event)} onBlur={blurHandler} /> @@ -329,7 +362,7 @@ export const PersonalInfo: React.FC = ({ fullWidth name={sn.name} placeholder={sn.placeholder} - value={newAuthorValues.socialNetwork[sn.index]} + value={newAuthorValues.socialNetworks[sn.index]} onChange={(event) => inputSocialNetworkChangeHandler(event, index) } @@ -344,9 +377,9 @@ export const PersonalInfo: React.FC = ({ {i18n.t(langTokens.admin.mainPlaceOfWork)} - {visitFields.work && errorMessages.work && ( + {visitFields.mainWorkingPlace && errorMessages.mainWorkingPlace && ( - {errorMessages.work} + {errorMessages.mainWorkingPlace} )} @@ -354,8 +387,8 @@ export const PersonalInfo: React.FC = ({ variant="outlined" required fullWidth - name="work" - value={newAuthorValues.work} + name="mainWorkingPlace" + value={newAuthorValues.mainWorkingPlace} onChange={inputChangeHandler} onBlur={blurHandler} /> diff --git a/src/views/Profile/PersonalInfo/types.ts b/src/views/Profile/PersonalInfo/types.ts index 8b3960269..2508b2201 100644 --- a/src/views/Profile/PersonalInfo/types.ts +++ b/src/views/Profile/PersonalInfo/types.ts @@ -7,9 +7,9 @@ export interface INewAuthorValues { regionId: number | null; cityId: number | null; bio: string; - email?: string; - socialNetwork: (string | null)[]; - work: string; + publicEmail?: string; + socialNetworks: (string | null)[]; + mainWorkingPlace: string; } export interface IErrorFields { @@ -18,8 +18,8 @@ export interface IErrorFields { firstName: string; regionId: string; cityId: string; - email: string; - work: string; + publicEmail: string; + mainWorkingPlace: string; bio: string; socialNetworks: string[]; socialNetwoksRequired: string; @@ -30,8 +30,8 @@ export interface IVisitFields { firstName: boolean; region: boolean; city: boolean; - email: boolean; - work: boolean; + publicEmail: boolean; + mainWorkingPlace: boolean; bio: boolean; facebook: boolean; instagram: boolean; @@ -53,4 +53,5 @@ export interface IRegionCityHandlerProps { export interface IEditAuthorProps { author?: IExpert; isCurrentUser?: boolean; + onSaveSuccessful: (id: number) => void; } diff --git a/src/views/Profile/Sidemenu.tsx b/src/views/Profile/Sidemenu.tsx index 1f8735ac2..2ff94cbf0 100644 --- a/src/views/Profile/Sidemenu.tsx +++ b/src/views/Profile/Sidemenu.tsx @@ -3,11 +3,10 @@ import Drawer from '@material-ui/core/Drawer'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemText from '@material-ui/core/ListItemText'; -import { useSelector } from 'react-redux'; -import { selectAuthorities } from '../../models/authorities'; import i18n, { langTokens } from '../../locales/localizationInit'; import { IProfileMenuOption } from '../../old/lib/types'; import { useStyles } from './styles/Sidemenu.styles'; +import { useCheckAdmin } from '../../old/lib/hooks/useCheckAdmin'; interface ISidemenuProps { selectedOption: IProfileMenuOption | Record; @@ -43,8 +42,7 @@ export const Sidemenu: React.FC = (props) => { const { selectedOption, changeOption } = props; const classes = useStyles(); - const authorities = useSelector(selectAuthorities); - const isAdmin = authorities.data?.includes('SET_IMPORTANCE'); + const isAdmin = useCheckAdmin(); return ( = ({ const { t } = useTranslation(); const history = useHistory(); const classes = useStyle(); - const authorities = useSelector(selectAuthorities); - const isAdmin = authorities.data?.includes('SET_IMPORTANCE'); + const isAdmin = useCheckAdmin(); const isVideoPost = postType.type === PostTypeEnum.VIDEO; const savedPostDraft = useSelector((state: RootStateType) => diff --git a/src/views/postUpdation/AllPostTypesUpdation.tsx b/src/views/postUpdation/AllPostTypesUpdation.tsx index dd0d02045..dde9782f3 100644 --- a/src/views/postUpdation/AllPostTypesUpdation.tsx +++ b/src/views/postUpdation/AllPostTypesUpdation.tsx @@ -1,7 +1,7 @@ -import React, { useCallback, useEffect, useState, useRef } from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; import { useHistory } from 'react-router-dom'; import _ from 'lodash'; -import { Box, TextField, Typography, List, ListItem } from '@material-ui/core'; +import { Box, List, ListItem, TextField, Typography } from '@material-ui/core'; import { useTranslation } from 'react-i18next'; import { DropEvent, FileRejection } from 'react-dropzone'; import { PageTitle } from 'components/Page/PageTitle'; @@ -12,9 +12,8 @@ import { import { useSelector } from 'react-redux'; import { CarouselImagesWrapper } from 'views/postCreation/CarouselImagesWrapper'; import { StatusesForActions } from 'models/adminLab/types'; -import { setChangesSize, selectSize } from 'models/changeLog'; +import { selectSize, setChangesSize } from 'models/changeLog'; import { useActions } from 'shared/hooks'; -import { Pagination } from '@material-ui/lab'; import { sanitizeHtml } from '../../old/lib/utilities/sanitizeHtml'; import { fetchChangeLog, @@ -50,7 +49,7 @@ import { uploadImageToImgur } from '../../old/lib/utilities/Imgur/uploadImageToI import { BackgroundImageContainer } from '../../components/Editor/CustomModules/BackgroundImageContainer/BackgroundImageContainer'; import { langTokens } from '../../locales/localizationInit'; import { useStyle } from '../postCreation/RequiredFieldsStyle'; -import { selectAuthorities } from '../../models/authorities'; +import { useCheckAdmin } from '../../old/lib/hooks/useCheckAdmin'; export interface IAllPostTypesUpdation { pageTitle: string; @@ -67,8 +66,7 @@ export const AllPostTypesUpdation: React.FC = ({ }) => { const history = useHistory(); const classes = useStyle(); - const authorities = useSelector(selectAuthorities); - const isAdmin = authorities.data?.includes('SET_IMPORTANCE'); + const isAdmin = useCheckAdmin(); const [autoChanges, setAutoChanges] = useState(true); const isVideoPost = post.type.id === 2; diff --git a/src/views/postUpdation/PostUpdationWrapper.tsx b/src/views/postUpdation/PostUpdationWrapper.tsx index c59cecbb5..e6e16c5d5 100644 --- a/src/views/postUpdation/PostUpdationWrapper.tsx +++ b/src/views/postUpdation/PostUpdationWrapper.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useCallback } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; import { useSelector } from 'react-redux'; import { langTokens } from 'locales/localizationInit'; @@ -11,15 +11,14 @@ import { useQuery } from '../../old/lib/hooks/useQuery'; import { setGALocation } from '../../utilities/setGALocation'; import { ERROR_404 } from '../../old/lib/constants/routes'; import { selectCurrentUser } from '../../models/user'; -import { selectAuthorities } from '../../models/authorities'; import { Notification } from '../../components/Notifications/Notification'; +import { useCheckAdmin } from '../../old/lib/hooks/useCheckAdmin'; const PostUpdationWrapper: React.FC = () => { const query = useQuery(); const history = useHistory(); const user = useSelector(selectCurrentUser); - const authorities = useSelector(selectAuthorities); - const isAdmin = authorities.data?.includes('SET_IMPORTANCE'); + const isAdmin = useCheckAdmin(); const { t } = useTranslation();