diff --git a/packages/client/src/views/SysAdmin/Team/user/UserList.tsx b/packages/client/src/views/SysAdmin/Team/user/UserList.tsx index 34a7659c9ab..e48985f71b1 100644 --- a/packages/client/src/views/SysAdmin/Team/user/UserList.tsx +++ b/packages/client/src/views/SysAdmin/Team/user/UserList.tsx @@ -39,7 +39,8 @@ import { SysAdminContentWrapper } from '@client/views/SysAdmin/SysAdminContentWr import { getAddressName, getUserRoleIntlKey, - UserStatus + UserStatus, + canDeactivateUser } from '@client/views/SysAdmin/Team/utils' import { LinkButton } from '@opencrvs/components/lib/buttons' import { Button } from '@opencrvs/components/lib/Button' @@ -396,7 +397,7 @@ function UserListComponent(props: IProps) { ) const getMenuItems = useCallback( - function getMenuItems(user: User) { + function getMenuItems(user: User, userDetails: UserDetails | null) { const menuItems = [ { label: intl.formatMessage(messages.editUserDetailsTitle), @@ -432,7 +433,11 @@ function UserListComponent(props: IProps) { }) } - if (user.status === 'active') { + if ( + userDetails && + user.status === 'active' && + canDeactivateUser(user.id, userDetails) + ) { menuItems.push({ label: intl.formatMessage(messages.deactivate), handler: () => toggleUserActivationModal(user) @@ -530,7 +535,7 @@ function UserListComponent(props: IProps) { toggleButton={ } - menuItems={getMenuItems(user)} + menuItems={getMenuItems(user, userDetails)} /> )} diff --git a/packages/client/src/views/SysAdmin/Team/utils.ts b/packages/client/src/views/SysAdmin/Team/utils.ts index 19f647bb920..c02e5ac0556 100644 --- a/packages/client/src/views/SysAdmin/Team/utils.ts +++ b/packages/client/src/views/SysAdmin/Team/utils.ts @@ -13,6 +13,7 @@ import { IntlShape, MessageDescriptor } from 'react-intl' import { messages } from '@client/i18n/messages/views/userSetup' import { SystemRoleType } from '@client/utils/gateway' import { ILocation, IOfflineData } from '@client/offline/reducer' +import { UserDetails } from '@client/utils/userUtils' export enum UserStatus { ACTIVE, @@ -112,3 +113,7 @@ export function getUserSystemRole( export const getUserRoleIntlKey = (_roleId: string) => { return `role.${_roleId}` } + +export const canDeactivateUser = (id: string, userDetails: UserDetails) => { + return id !== userDetails.id ? true : false +} diff --git a/packages/client/src/views/UserAudit/UserAudit.tsx b/packages/client/src/views/UserAudit/UserAudit.tsx index 680ed4cec5d..fcf6fb32d8c 100644 --- a/packages/client/src/views/UserAudit/UserAudit.tsx +++ b/packages/client/src/views/UserAudit/UserAudit.tsx @@ -23,7 +23,10 @@ import { AvatarSmall } from '@client/components/Avatar' import styled from 'styled-components' import { ToggleMenu } from '@opencrvs/components/lib/ToggleMenu' import { Button } from '@opencrvs/components/lib/Button' -import { getUserRoleIntlKey } from '@client/views/SysAdmin//Team/utils' +import { + getUserRoleIntlKey, + canDeactivateUser +} from '@client/views/SysAdmin/Team/utils' import { EMPTY_STRING, LANG_EN } from '@client/utils/constants' import { Loader } from '@opencrvs/components/lib/Loader' import { messages as userSetupMessages } from '@client/i18n/messages/views/userSetup' @@ -246,7 +249,11 @@ export const UserAudit = () => { ) } - if (status === 'active') { + if ( + status === 'active' && + userDetails && + canDeactivateUser(userId, userDetails) + ) { menuItems.push({ label: intl.formatMessage(sysMessages.deactivate), handler: () => toggleUserActivationModal()