Skip to content

Commit ddc35ee

Browse files
committed
clean up pay suggestion logic
1 parent 0f6a8c4 commit ddc35ee

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/libs/PolicyUtils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,25 @@ function isPolicyMember(currentUserLogin: string | undefined, policyID: string |
284284
return !!currentUserLogin && !!policyID && !!allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.employeeList?.[currentUserLogin];
285285
}
286286

287+
function isPolicyPayer(policy: OnyxEntry<Policy>, currentUserLogin: string | undefined): boolean {
288+
if (!policy) {
289+
return false;
290+
}
291+
292+
const isAdmin = policy.role === CONST.POLICY.ROLE.ADMIN;
293+
const isReimburser = policy.reimburser === currentUserLogin;
294+
295+
if (policy.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) {
296+
return policy.reimburser ? isReimburser : isAdmin;
297+
}
298+
299+
if (policy.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) {
300+
return isAdmin;
301+
}
302+
303+
return false;
304+
}
305+
287306
function isExpensifyTeam(email: string | undefined): boolean {
288307
const emailDomain = Str.extractEmailDomain(email ?? '');
289308
return emailDomain === CONST.EXPENSIFY_PARTNER_NAME || emailDomain === CONST.EMAIL.GUIDES_DOMAIN;
@@ -1514,6 +1533,7 @@ export {
15141533
isPolicyFeatureEnabled,
15151534
isPolicyOwner,
15161535
isPolicyMember,
1536+
isPolicyPayer,
15171537
arePaymentsEnabled,
15181538
isSubmitAndClose,
15191539
isTaxTrackingEnabled,

src/libs/SearchUIUtils.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import {translateLocal} from './Localize';
5656
import Navigation from './Navigation/Navigation';
5757
import Parser from './Parser';
5858
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
59-
import {arePaymentsEnabled, canSendInvoice, getActivePolicy, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy} from './PolicyUtils';
59+
import {arePaymentsEnabled, canSendInvoice, getActivePolicy, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy, isPolicyPayer} from './PolicyUtils';
6060
import {getOriginalMessage, isCreatedAction, isDeletedAction, isMoneyRequestAction, isResolvedActionableWhisper, isWhisperActionTargetedToOthers} from './ReportActionsUtils';
6161
import {canReview} from './ReportPreviewActionUtils';
6262
import {isExportAction} from './ReportPrimaryActionUtils';
@@ -422,8 +422,8 @@ function getSuggestedSearchesVisibility(
422422
}
423423

424424
const isPaidPolicy = isPaidGroupPolicy(policy);
425+
const isPayer = isPolicyPayer(policy, currentUserEmail);
425426
const isAdmin = policy.role === CONST.POLICY.ROLE.ADMIN;
426-
const isReimburser = policy.reimburser === currentUserEmail;
427427
const isExporter = policy.exporter === currentUserEmail;
428428
const isApprover = policy.approver === currentUserEmail;
429429
const isApprovalEnabled = policy.approvalMode ? policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL : false;
@@ -433,16 +433,7 @@ function getSuggestedSearchesVisibility(
433433
});
434434

435435
const isEligibleForSubmitSuggestion = isPaidPolicy;
436-
const isEligibleForPaySuggestion =
437-
isPaidPolicy &&
438-
// eslint-disable-next-line no-nested-ternary
439-
(policy.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES
440-
? policy.reimburser
441-
? isReimburser
442-
: isAdmin
443-
: policy.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL
444-
? isAdmin
445-
: false);
436+
const isEligibleForPaySuggestion = isPaidPolicy && isPayer;
446437
const isEligibleForApproveSuggestion = isPaidPolicy && isApprovalEnabled && (isApprover || isSubmittedTo);
447438
const isEligibleForExportSuggestion = isExporter;
448439
const isEligibleForStatementsSuggestion = isPaidPolicy && !!policy.areCompanyCardsEnabled && cardFeedsByPolicy[policy.id]?.length > 0;

0 commit comments

Comments
 (0)