Skip to content

Commit

Permalink
bws-222: * some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdanshcherba committed Apr 1, 2022
1 parent dab2018 commit 198a51f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
20 changes: 15 additions & 5 deletions frontend/src/components/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => (
<div className={styles.wrapper}>
<ServicesList services={SERVICE_MENU_ITEMS} />
</div>
);
const Dashboard: FC = () => {
const dispatch = useAppDispatch();

useEffect(() => {
dispatch(authActions.loadCurrentUser());
}, []);

return (
<div className={styles.wrapper}>
<ServicesList services={SERVICE_MENU_ITEMS} />
</div>
);
};

export { Dashboard };
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -88,7 +85,6 @@ const EAMConfigurateGroup: FC = () => {
permissionsIds: selectedPermissions.selectedItems,
};
dispatch(EAMGroupConfigurateActions.update(newPayload));
dispatch(authActions.loadCurrentUser());
} else {
const newPayload: EAMGroupConfigurateRequestDto = {
name: payload.name,
Expand Down
32 changes: 25 additions & 7 deletions frontend/src/store/eam-group-configurate/actions.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
});
Expand Down

0 comments on commit 198a51f

Please sign in to comment.