From ce668f805d06264e16fa2a25903c10e7f0fed6df Mon Sep 17 00:00:00 2001 From: shaked-hayek <85109951+shaked-hayek@users.noreply.github.com> Date: Tue, 26 Dec 2023 13:26:34 +0200 Subject: [PATCH] Add check for user authentication in NewsFlash (#990) (#1003) --- src/components/molecules/NewsFlashComp.tsx | 14 ++++++++------ src/store/user.store.ts | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/molecules/NewsFlashComp.tsx b/src/components/molecules/NewsFlashComp.tsx index f97b36c2..092adca5 100644 --- a/src/components/molecules/NewsFlashComp.tsx +++ b/src/components/molecules/NewsFlashComp.tsx @@ -14,6 +14,7 @@ import LocationApprove from 'components/organisms/LocationApproveWindow'; import {locationQualificationOptions} from 'components/organisms/LocationApproveWindow'; import { INewsFlash } from 'models/NewFlash'; import {useParams} from 'react-router-dom' +import { observer } from "mobx-react-lite"; const ICON_HEIGHT = 18 @@ -38,7 +39,6 @@ const NewsFlashComp: FC = ({ news }) => { const locale = useLocale(); const { userStore, settingsStore } = store; const { t } = useTranslation(); - const userAllowedChange = userStore.isUserAuthenticated && userStore.isAdmin; function getVerificationIcon(verificationText: string) { if (verificationText === locationQualificationOptions.REJECTED) { @@ -57,17 +57,19 @@ const NewsFlashComp: FC = ({ news }) => { const verificationIcon = getVerificationIcon(news.newsflash_location_qualification); const criticalIcon = news.critical && ; const {newsId} = useParams() - const newsID = newsId ? parseInt(newsId) : '' - + const newsID = newsId ? parseInt(newsId) : '' + const className = news.id === newsID ? classes.activeNewsFlash : ''; const date = news.date == null ? '' : dateFormat(new Date(news.date.replace(/-/g, '/')), locale); const handleLocationEditorOpen = () => setOpen(true); const handleLocationEditorClose = () => setOpen(false); - const locationChangeButton = userAllowedChange && + + const locationChangeButton = userStore.isUserAdmin && {t('changeLocationButton')} + return ( @@ -84,8 +86,8 @@ const NewsFlashComp: FC = ({ news }) => { - + ); } -export default NewsFlashComp; +export default observer(NewsFlashComp); diff --git a/src/store/user.store.ts b/src/store/user.store.ts index f96e2444..fbdd4b5a 100644 --- a/src/store/user.store.ts +++ b/src/store/user.store.ts @@ -56,6 +56,10 @@ export default class UserStore { return this.userInfo?.data.organizations; } + get isUserAdmin(){ + return this.isUserAuthenticated && this.isAdmin; + } + get usersManagementTableData(): any { return this.usersInfoList?.map((user) => ({ name: `${user.first_name} ${user.last_name}`,