From 55a9bb3944d0a576c6db9294f983c1d112f13380 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Thu, 12 Dec 2024 18:42:26 +0530 Subject: [PATCH] fix: filter approvers from submit to members page if preventSelfApproval is true. Signed-off-by: krishna2323 --- .../WorkspaceWorkflowsApprovalsExpensesFromPage.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx index 8f7553e97fe1..1e44135a6082 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx @@ -87,6 +87,7 @@ function WorkspaceWorkflowsApprovalsExpensesFromPage({policy, isLoadingReportDat ); }, [approvalWorkflow?.members, policy?.employeeList, translate]); + const approversEmail = useMemo(() => approvalWorkflow?.approvers.map((member) => member?.email), [approvalWorkflow?.approvers]); const sections: MembersSection[] = useMemo(() => { const members: SelectionListMember[] = [...selectedMembers]; @@ -107,7 +108,9 @@ function WorkspaceWorkflowsApprovalsExpensesFromPage({policy, isLoadingReportDat rightElement: isAdmin ? : undefined, }; }) - .filter((member) => !selectedMembers.some((selectedOption) => selectedOption.login === member.login)); + .filter( + (member) => (!policy?.preventSelfApproval || !approversEmail?.includes(member.login)) && !selectedMembers.some((selectedOption) => selectedOption.login === member.login), + ); members.push(...availableMembers); } @@ -128,7 +131,7 @@ function WorkspaceWorkflowsApprovalsExpensesFromPage({policy, isLoadingReportDat shouldShow: true, }, ]; - }, [approvalWorkflow?.availableMembers, debouncedSearchTerm, policy?.employeeList, selectedMembers, translate]); + }, [approvalWorkflow?.availableMembers, debouncedSearchTerm, policy?.preventSelfApproval, policy?.employeeList, selectedMembers, translate, approversEmail]); const goBack = useCallback(() => { let backTo;