diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 6a1a61afa05d..fc7c1c43afee 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -194,6 +194,11 @@ function isExpensifyTeam(email: string | undefined): boolean { return emailDomain === CONST.EXPENSIFY_PARTNER_NAME || emailDomain === CONST.EMAIL.GUIDES_DOMAIN; } +/** + * Checks if the user with login is an admin of the policy. + */ +const isUserPolicyAdmin = (policy: OnyxInputOrEntry, login?: string) => !!(policy && policy.employeeList && login && policy.employeeList[login]?.role === CONST.POLICY.ROLE.ADMIN); + /** * Checks if the current user is an admin of the policy. */ @@ -1088,6 +1093,7 @@ export { getCorrectedAutoReportingFrequency, isPaidGroupPolicy, isPendingDeletePolicy, + isUserPolicyAdmin, isPolicyAdmin, isPolicyUser, isPolicyAuditor, diff --git a/src/pages/RoomMemberDetailsPage.tsx b/src/pages/RoomMemberDetailsPage.tsx index 475cf37a8847..3a9d51a251a1 100644 --- a/src/pages/RoomMemberDetailsPage.tsx +++ b/src/pages/RoomMemberDetailsPage.tsx @@ -12,10 +12,13 @@ import ScreenWrapper from '@components/ScreenWrapper'; import Text from '@components/Text'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; +import usePolicy from '@hooks/usePolicy'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import * as Report from '@libs/actions/Report'; import type {RoomMembersNavigatorParamList} from '@libs/Navigation/types'; +import * as PolicyUtils from '@libs/PolicyUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import Navigation from '@navigation/Navigation'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -34,6 +37,7 @@ function RoomMemberDetailsPage({report, route}: RoomMemberDetailsPagePageProps) const StyleUtils = useStyleUtils(); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); + const policy = usePolicy(report?.policyID); const [isRemoveMemberConfirmModalVisible, setIsRemoveMemberConfirmModalVisible] = React.useState(false); @@ -45,6 +49,8 @@ function RoomMemberDetailsPage({report, route}: RoomMemberDetailsPagePageProps) const fallbackIcon = details.fallbackIcon ?? ''; const displayName = details.displayName ?? ''; const isSelectedMemberCurrentUser = accountID === currentUserPersonalDetails?.accountID; + const isSelectedMemberOwner = accountID === report.ownerAccountID; + const shouldDisableRemoveUser = (ReportUtils.isPolicyExpenseChat(report) && PolicyUtils.isUserPolicyAdmin(policy, details.login)) || isSelectedMemberCurrentUser || isSelectedMemberOwner; const removeUser = useCallback(() => { setIsRemoveMemberConfirmModalVisible(false); Report.removeFromRoom(report?.reportID, [accountID]); @@ -88,7 +94,7 @@ function RoomMemberDetailsPage({report, route}: RoomMemberDetailsPagePageProps)