From 198a51f2acb81f343dbc34a4101b6979dc1f3f05 Mon Sep 17 00:00:00 2001 From: bohdanshcherba <73034554+bohdanshcherba@users.noreply.github.com> Date: Fri, 1 Apr 2022 16:48:46 +0300 Subject: [PATCH] bws-222: * some fix --- .../src/components/dashboard/dashboard.tsx | 20 +++++++++--- .../eam-configurate-group.tsx | 6 +--- .../store/eam-group-configurate/actions.ts | 32 +++++++++++++++---- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/dashboard/dashboard.tsx b/frontend/src/components/dashboard/dashboard.tsx index f4ecfe677..8c998eb72 100644 --- a/frontend/src/components/dashboard/dashboard.tsx +++ b/frontend/src/components/dashboard/dashboard.tsx @@ -2,11 +2,21 @@ import { FC } from 'react'; import { ServicesList } from './components/components'; import { SERVICE_MENU_ITEMS } from './common/constants'; import styles from './styles.module.scss'; +import { useAppDispatch, useEffect } from 'hooks/hooks'; +import { auth as authActions } from 'store/actions'; -const Dashboard: FC = () => ( -
- -
-); +const Dashboard: FC = () => { + const dispatch = useAppDispatch(); + + useEffect(() => { + dispatch(authActions.loadCurrentUser()); + }, []); + + return ( +
+ +
+ ); +}; export { Dashboard }; diff --git a/frontend/src/components/eam-configurate-group/eam-configurate-group.tsx b/frontend/src/components/eam-configurate-group/eam-configurate-group.tsx index 619a0e216..3b8d65671 100644 --- a/frontend/src/components/eam-configurate-group/eam-configurate-group.tsx +++ b/frontend/src/components/eam-configurate-group/eam-configurate-group.tsx @@ -16,10 +16,7 @@ import { InputType, } from 'common/enums/enums'; import { getNameOf } from 'helpers/helpers'; -import { - EAMGroupConfigurate as EAMGroupConfigurateActions, - auth as authActions, -} from 'store/actions'; +import { EAMGroupConfigurate as EAMGroupConfigurateActions } from 'store/actions'; import styles from './styles.module.scss'; import { EAMGroupConfigurateRequestDto, @@ -88,7 +85,6 @@ const EAMConfigurateGroup: FC = () => { permissionsIds: selectedPermissions.selectedItems, }; dispatch(EAMGroupConfigurateActions.update(newPayload)); - dispatch(authActions.loadCurrentUser()); } else { const newPayload: EAMGroupConfigurateRequestDto = { name: payload.name, diff --git a/frontend/src/store/eam-group-configurate/actions.ts b/frontend/src/store/eam-group-configurate/actions.ts index 9c23c4811..063ea85a1 100644 --- a/frontend/src/store/eam-group-configurate/actions.ts +++ b/frontend/src/store/eam-group-configurate/actions.ts @@ -1,5 +1,10 @@ import { createAsyncThunk } from '@reduxjs/toolkit'; -import { NotificationTitle, NotificationMessage } from 'common/enums/enums'; +import { + NotificationTitle, + NotificationMessage, + Permission, + AppRoute, +} from 'common/enums/enums'; import { AsyncThunkConfig, EAMGroupConfigurateRequestDto, @@ -13,7 +18,7 @@ import { EAMGroupUpdateRequestDto, } from 'common/types/types'; import { ActionType } from './common'; -import { AppRoute } from '../../common/enums/app/app-route.enum'; +import { checkHasPermission } from 'helpers/helpers'; const create = createAsyncThunk< EAMGroupCreateResponseDto, @@ -48,7 +53,7 @@ const update = createAsyncThunk< EAMGroupUpdateRequestDto, AsyncThunkConfig >(ActionType.UPDATE, async (payload, { getState, extra }) => { - const { eamApi, navigation, notification } = extra; + const { eamApi, navigation, notification, authApi } = extra; const { app } = getState(); const { tenant } = app; @@ -61,12 +66,25 @@ const update = createAsyncThunk< }; const group = await eamApi.updateGroup(payload.id, request); + const { user } = await authApi.getCurrentUser(); - navigation.push(AppRoute.EAM); - notification.success( - NotificationTitle.SUCCESS, - NotificationMessage.EAM_GROUP_UPDATE, + const hasEamPermission = checkHasPermission( + [Permission.MANAGE_EAM], + user.permissions, ); + if (hasEamPermission) { + navigation.push(AppRoute.EAM); + notification.success( + NotificationTitle.SUCCESS, + NotificationMessage.EAM_GROUP_UPDATE, + ); + } else { + notification.success( + NotificationTitle.SUCCESS, + NotificationMessage.EAM_GROUP_UPDATE, + ); + navigation.push(AppRoute.ROOT); + } return group; });