From cc49be75acc91d5301299641cc6b647aa34741b5 Mon Sep 17 00:00:00 2001 From: Monil Bhavsar Date: Thu, 18 Apr 2024 17:53:03 +0530 Subject: [PATCH 1/4] Fix: Displaying member options --- src/pages/workspace/WorkspaceMembersPage.tsx | 48 ++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index 9c5631eff0aa..9158e49b234a 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -39,7 +39,13 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {InvitedEmailsToAccountIDs, PersonalDetailsList, PolicyEmployee, PolicyEmployeeList, Session} from '@src/types/onyx'; +import type { + InvitedEmailsToAccountIDs, + PersonalDetailsList, + PolicyEmployee, + PolicyEmployeeList, + Session +} from '@src/types/onyx'; import type {Errors, PendingAction} from '@src/types/onyx/OnyxCommon'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading'; @@ -467,24 +473,30 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft, }, ]; - if (PolicyUtils.isPaidGroupPolicy(policy)) { - if (selectedEmployees.find((employeeEmail) => policy?.employeeList?.[policyMemberEmailsToAccountIDs[employeeEmail]]?.role === CONST.POLICY.ROLE.ADMIN)) { - options.push({ - text: translate('workspace.people.makeMember'), - value: CONST.POLICY.MEMBERS_BULK_ACTION_TYPES.MAKE_MEMBER, - icon: Expensicons.User, - onSelected: () => changeUserRole(CONST.POLICY.ROLE.USER), - }); - } + if (!PolicyUtils.isPaidGroupPolicy(policy)) { + return options; + } - if (selectedEmployees.find((employeeEmail) => policy?.employeeList?.[policyMemberEmailsToAccountIDs[employeeEmail]]?.role === CONST.POLICY.ROLE.USER)) { - options.push({ - text: translate('workspace.people.makeAdmin'), - value: CONST.POLICY.MEMBERS_BULK_ACTION_TYPES.MAKE_ADMIN, - icon: Expensicons.MakeAdmin, - onSelected: () => changeUserRole(CONST.POLICY.ROLE.ADMIN), - }); - } + const selectedEmployeesRoles = selectedEmployees.map(accountID => { + const email = Object.keys(policyMemberEmailsToAccountIDs).find(email => policyMemberEmailsToAccountIDs[email] === accountID) ?? ''; + return policy?.employeeList?.[email]?.role; + }); + if (selectedEmployeesRoles.find((role) => role === CONST.POLICY.ROLE.ADMIN)) { + options.push({ + text: translate('workspace.people.makeMember'), + value: CONST.POLICY.MEMBERS_BULK_ACTION_TYPES.MAKE_MEMBER, + icon: Expensicons.User, + onSelected: () => changeUserRole(CONST.POLICY.ROLE.USER), + }); + } + + if (selectedEmployeesRoles.find((role) => role === CONST.POLICY.ROLE.USER)) { + options.push({ + text: translate('workspace.people.makeAdmin'), + value: CONST.POLICY.MEMBERS_BULK_ACTION_TYPES.MAKE_ADMIN, + icon: Expensicons.MakeAdmin, + onSelected: () => changeUserRole(CONST.POLICY.ROLE.ADMIN), + }); } return options; }; From 39b95acf7cc83d67271654baf0f136089aeaa238 Mon Sep 17 00:00:00 2001 From: Monil Bhavsar Date: Thu, 18 Apr 2024 18:14:33 +0530 Subject: [PATCH 2/4] Fix change user method --- src/pages/workspace/WorkspaceMembersPage.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index 9158e49b234a..25e216204237 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -457,7 +457,10 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft, return; } - const accountIDsToUpdate = selectedEmployees.filter((id) => policy?.employeeList?.[policyMemberEmailsToAccountIDs[id]]?.role !== role); + const accountIDsToUpdate = selectedEmployees.filter((accountID) => { + const email = Object.keys(policyMemberEmailsToAccountIDs).find(email => policyMemberEmailsToAccountIDs[email] === accountID) ?? ''; + return policy?.employeeList?.[email]?.role !== role; + }); Policy.updateWorkspaceMembersRole(route.params.policyID, accountIDsToUpdate, role); setSelectedEmployees([]); From 5cf9d2dd9ccbc07aa8708c056da9d40f0d67abbf Mon Sep 17 00:00:00 2001 From: Monil Bhavsar Date: Thu, 18 Apr 2024 18:34:23 +0530 Subject: [PATCH 3/4] Use personal details object --- src/pages/workspace/WorkspaceMembersPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index 25e216204237..4114026145c0 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -458,7 +458,7 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft, } const accountIDsToUpdate = selectedEmployees.filter((accountID) => { - const email = Object.keys(policyMemberEmailsToAccountIDs).find(email => policyMemberEmailsToAccountIDs[email] === accountID) ?? ''; + const email = personalDetails?.[accountID]?.login ?? ''; return policy?.employeeList?.[email]?.role !== role; }); @@ -481,7 +481,7 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft, } const selectedEmployeesRoles = selectedEmployees.map(accountID => { - const email = Object.keys(policyMemberEmailsToAccountIDs).find(email => policyMemberEmailsToAccountIDs[email] === accountID) ?? ''; + const email = personalDetails?.[accountID]?.login ?? ''; return policy?.employeeList?.[email]?.role; }); if (selectedEmployeesRoles.find((role) => role === CONST.POLICY.ROLE.ADMIN)) { From 8377e34d2ce554fd62318846b50d084fa634621c Mon Sep 17 00:00:00 2001 From: Monil Bhavsar Date: Thu, 18 Apr 2024 18:43:32 +0530 Subject: [PATCH 4/4] Run prettier --- src/pages/workspace/WorkspaceMembersPage.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index 4114026145c0..d475a916e0d4 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -39,13 +39,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type { - InvitedEmailsToAccountIDs, - PersonalDetailsList, - PolicyEmployee, - PolicyEmployeeList, - Session -} from '@src/types/onyx'; +import type {InvitedEmailsToAccountIDs, PersonalDetailsList, PolicyEmployee, PolicyEmployeeList, Session} from '@src/types/onyx'; import type {Errors, PendingAction} from '@src/types/onyx/OnyxCommon'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading'; @@ -480,7 +474,7 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft, return options; } - const selectedEmployeesRoles = selectedEmployees.map(accountID => { + const selectedEmployeesRoles = selectedEmployees.map((accountID) => { const email = personalDetails?.[accountID]?.login ?? ''; return policy?.employeeList?.[email]?.role; });