Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
localeCompare,
});

// Filter out members who are already assigned to a non-default approval workflow.
// This prevents them from appearing in the "Expenses from" picker when creating a new workflow.
// The edit flow is unaffected as it uses mergeWorkflowMembersWithAvailableMembers separately.
const availableMembersForNewWorkflow = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot, move this function to WorkflowUtils.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — extracted the filtering logic into filterAvailableMembersForNewWorkflow in WorkflowUtils.ts and updated the page to call it.

const membersInExistingWorkflows = new Set<string>();
for (const workflow of approvalWorkflows) {
if (workflow.isDefault) {
continue;
}
for (const member of workflow.members) {
membersInExistingWorkflows.add(member.email);
}
}
return availableMembers.filter((member) => !membersInExistingWorkflows.has(member.email));
}, [approvalWorkflows, availableMembers]);

const hasValidExistingAccounts = getEligibleExistingBusinessBankAccounts(bankAccountList, policy?.outputCurrency, true).length > 0;

const isAdvanceApproval = (approvalWorkflows.length > 1 || (approvalWorkflows?.at(0)?.approvers ?? []).length > 1) && isControlPolicy(policy);
Expand Down Expand Up @@ -158,7 +174,7 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
const addApprovalAction = useCallback(() => {
setApprovalWorkflow({
...INITIAL_APPROVAL_WORKFLOW,
availableMembers,
availableMembers: availableMembersForNewWorkflow,
usedApproverEmails,
});

Expand All @@ -174,7 +190,7 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
}

Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(route.params.policyID));
}, [policy, route.params.policyID, availableMembers, usedApproverEmails]);
}, [policy, route.params.policyID, availableMembersForNewWorkflow, usedApproverEmails]);

const filteredApprovalWorkflows =
policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.ADVANCED || policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.DYNAMICEXTERNAL
Expand Down
Loading