@@ -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+
91109function 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 */
753771function 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