From 09cb5792da56acf914f1b2ed6bb3589c25a1f5f4 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Sun, 29 Jun 2025 10:37:40 +0530 Subject: [PATCH 1/2] Fixed per-diem workspace selection --- src/libs/PolicyUtils.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 33521ce2b8f3..ed852f6ab077 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -88,9 +88,26 @@ function getActivePolicies(policies: OnyxCollection | null, currentUserL ); } +/** + * Filter out the active policies, which will exclude policies with pending deletion + * and policies the current user doesn't belong to. + * These are policies that we can use to create reports with in NewDot. + */ +function getActivePoliciesWithExpenseChat(policies: OnyxCollection | null, currentUserLogin: string | undefined): Policy[] { + return Object.values(policies ?? {}).filter( + (policy): policy is Policy => + !!policy && + policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && + !!policy.name && + !!policy.id && + !!getPolicyRole(policy, currentUserLogin) && + policy.isPolicyExpenseChatEnabled, + ); +} + function getPerDiemCustomUnits(policies: OnyxCollection | null, email: string | undefined): Array<{policyID: string; customUnit: CustomUnit}> { return ( - getActivePolicies(policies, email) + getActivePoliciesWithExpenseChat(policies, email) .map((mappedPolicy) => ({policyID: mappedPolicy.id, customUnit: getPerDiemCustomUnit(mappedPolicy)})) // We filter out custom units that are undefine but ts cant' figure it out. .filter(({customUnit}) => !isEmptyObject(customUnit) && !!customUnit.enabled) as Array<{policyID: string; customUnit: CustomUnit}> @@ -752,7 +769,7 @@ function canSendInvoiceFromWorkspace(policyID: string | undefined): boolean { /** Whether the user can submit per diem expense from the workspace */ function canSubmitPerDiemExpenseFromWorkspace(policy: OnyxEntry): boolean { const perDiemCustomUnit = getPerDiemCustomUnit(policy); - return !isEmptyObject(perDiemCustomUnit) && !!perDiemCustomUnit?.enabled; + return !!policy?.isPolicyExpenseChatEnabled && !isEmptyObject(perDiemCustomUnit) && !!perDiemCustomUnit?.enabled; } /** Whether the user can send invoice */ From 64e9f7938e51b534639e1ec6a8a9ab8b6ffed475 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Sun, 29 Jun 2025 10:40:21 +0530 Subject: [PATCH 2/2] Fix comment --- src/libs/PolicyUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index ed852f6ab077..bba43e856650 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -91,6 +91,7 @@ function getActivePolicies(policies: OnyxCollection | null, currentUserL /** * Filter out the active policies, which will exclude policies with pending deletion * and policies the current user doesn't belong to. + * These will be policies that has expense chat enabled. * These are policies that we can use to create reports with in NewDot. */ function getActivePoliciesWithExpenseChat(policies: OnyxCollection | null, currentUserLogin: string | undefined): Policy[] {