Skip to content

Commit 805fd8c

Browse files
authored
Merge pull request Expensify#65150 from shubham1206agra/fix-per-diem-workspace
Fix per diem workspace
2 parents 15476a5 + 64e9f79 commit 805fd8c

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/libs/PolicyUtils.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,27 @@ function getActivePolicies(policies: OnyxCollection<Policy> | null, currentUserL
8888
);
8989
}
9090

91+
/**
92+
* Filter out the active policies, which will exclude policies with pending deletion
93+
* and policies the current user doesn't belong to.
94+
* These will be policies that has expense chat enabled.
95+
* These are policies that we can use to create reports with in NewDot.
96+
*/
97+
function getActivePoliciesWithExpenseChat(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined): Policy[] {
98+
return Object.values(policies ?? {}).filter<Policy>(
99+
(policy): policy is Policy =>
100+
!!policy &&
101+
policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
102+
!!policy.name &&
103+
!!policy.id &&
104+
!!getPolicyRole(policy, currentUserLogin) &&
105+
policy.isPolicyExpenseChatEnabled,
106+
);
107+
}
108+
91109
function getPerDiemCustomUnits(policies: OnyxCollection<Policy> | null, email: string | undefined): Array<{policyID: string; customUnit: CustomUnit}> {
92110
return (
93-
getActivePolicies(policies, email)
111+
getActivePoliciesWithExpenseChat(policies, email)
94112
.map((mappedPolicy) => ({policyID: mappedPolicy.id, customUnit: getPerDiemCustomUnit(mappedPolicy)}))
95113
// We filter out custom units that are undefine but ts cant' figure it out.
96114
.filter(({customUnit}) => !isEmptyObject(customUnit) && !!customUnit.enabled) as Array<{policyID: string; customUnit: CustomUnit}>
@@ -752,7 +770,7 @@ function canSendInvoiceFromWorkspace(policyID: string | undefined): boolean {
752770
/** Whether the user can submit per diem expense from the workspace */
753771
function canSubmitPerDiemExpenseFromWorkspace(policy: OnyxEntry<Policy>): boolean {
754772
const perDiemCustomUnit = getPerDiemCustomUnit(policy);
755-
return !isEmptyObject(perDiemCustomUnit) && !!perDiemCustomUnit?.enabled;
773+
return !!policy?.isPolicyExpenseChatEnabled && !isEmptyObject(perDiemCustomUnit) && !!perDiemCustomUnit?.enabled;
756774
}
757775

758776
/** Whether the user can send invoice */

0 commit comments

Comments
 (0)