From 8efc85b1b274d77729b37fff073c878304da2771 Mon Sep 17 00:00:00 2001 From: c3024 Date: Tue, 20 Feb 2024 00:57:12 +0530 Subject: [PATCH 1/9] pay conditions based on reimbursement settings --- src/CONST.ts | 6 +++--- src/components/MoneyReportHeader.tsx | 5 +---- src/components/ReportActionItem/ReportPreview.tsx | 5 +---- src/libs/PolicyUtils.ts | 13 ++++++++++++- src/types/onyx/Policy.ts | 3 +++ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index df0e1ad1c4ee..6be700673ac9 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1373,9 +1373,9 @@ const CONST = { OWNER_EMAIL_FAKE: '_FAKE_', OWNER_ACCOUNT_ID_FAKE: 0, REIMBURSEMENT_CHOICES: { - REIMBURSEMENT_YES: 'reimburseYes', - REIMBURSEMENT_NO: 'reimburseNo', - REIMBURSEMENT_MANUAL: 'reimburseManual', + REIMBURSEMENT_YES: 'reimburseYes', // Direct + REIMBURSEMENT_NO: 'reimburseNo', // None + REIMBURSEMENT_MANUAL: 'reimburseManual', // Indirect }, ID_FAKE: '_FAKE_', EMPTY: 'EMPTY', diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 3f551da788f5..d94a0596e0c2 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -59,10 +59,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(moneyRequestReport, policy); const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicy(moneyRequestReport); const isManager = ReportUtils.isMoneyRequestReport(moneyRequestReport) && session?.accountID === moneyRequestReport.managerID; - const isPayer = isPaidGroupPolicy - ? // In a group policy, the admin approver can pay the report directly by skipping the approval step - isPolicyAdmin && (isApproved || isManager) - : isPolicyAdmin || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && isManager); + const isPayer = PolicyUtils.isPolicyPayer(policy, session, isApproved, isManager, isPolicyAdmin); const isDraft = ReportUtils.isDraftExpenseReport(moneyRequestReport); const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 591767234b8b..5c61f83c426c 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -210,10 +210,7 @@ function ReportPreview({ const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport); const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN; - const isPayer = isPaidGroupPolicy - ? // In a paid group policy, the admin approver can pay the report directly by skipping the approval step - isPolicyAdmin && (isApproved || isCurrentUserManager) - : isPolicyAdmin || (isMoneyRequestReport && isCurrentUserManager); + const isPayer = PolicyUtils.isPolicyPayer(policy, session, isApproved, isCurrentUserManager, isPolicyAdmin); const isOnInstantSubmitPolicy = PolicyUtils.isInstantSubmitEnabled(policy); const isOnSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); const shouldShowPayButton = useMemo( diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index a8c0508e30b6..d8e039bcdfd6 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -3,7 +3,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTagList, PolicyTags} from '@src/types/onyx'; +import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTagList, PolicyTags, Session} from '@src/types/onyx'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -110,6 +110,16 @@ const isPolicyAdmin = (policy: OnyxEntry | EmptyObject): boolean => poli const isPolicyMember = (policyID: string, policies: OnyxCollection): boolean => Object.values(policies ?? {}).some((policy) => policy?.id === policyID); +const isPolicyPayer = (policy: OnyxEntry | EmptyObject, session: OnyxEntry, isApproved: boolean, isManager: boolean, isPolicyAdmin: boolean): boolean => { + if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { + const isReimburser = session?.email === policy?.reimbursersEmail; + return isReimburser && (isApproved || isManager); + } else if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { + return isPolicyAdmin && (isApproved || isManager); + } else { + return false; + } +}; /** * Create an object mapping member emails to their accountIDs. Filter for members without errors, and get the login email from the personalDetail object using the accountID. * @@ -269,6 +279,7 @@ export { getCountOfEnabledTagsOfList, isPendingDeletePolicy, isPolicyMember, + isPolicyPayer, isPaidGroupPolicy, extractPolicyIDFromPath, getPathWithoutPolicyID, diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 7d4c08374b81..44a96d23cf09 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -171,6 +171,9 @@ type Policy = { trackingEnabled: boolean; }; + /** Email of the reimburser when reimbursement is set direct */ + reimbursersEmail?: string; + /** ReportID of the admins room for this workspace */ chatReportIDAdmins?: number; From 7b5b8acae1ec0aeeb118d95d9ee3f3301e3e4023 Mon Sep 17 00:00:00 2001 From: c3024 Date: Tue, 20 Feb 2024 13:20:09 +0530 Subject: [PATCH 2/9] fix lint --- src/components/ReportActionItem/ReportPreview.tsx | 1 - src/libs/PolicyUtils.ts | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 5c61f83c426c..1c2c385e43bf 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -132,7 +132,6 @@ function ReportPreview({ const isApproved = ReportUtils.isReportApproved(iouReport); const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport); - const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(iouReport); const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(iouReportID); const numberOfScanningReceipts = transactionsWithReceipts.filter((transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length; diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index d8e039bcdfd6..3b2fbc43eb8f 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -110,15 +110,15 @@ const isPolicyAdmin = (policy: OnyxEntry | EmptyObject): boolean => poli const isPolicyMember = (policyID: string, policies: OnyxCollection): boolean => Object.values(policies ?? {}).some((policy) => policy?.id === policyID); -const isPolicyPayer = (policy: OnyxEntry | EmptyObject, session: OnyxEntry, isApproved: boolean, isManager: boolean, isPolicyAdmin: boolean): boolean => { +const isPolicyPayer = (policy: OnyxEntry | EmptyObject, session: OnyxEntry, isApproved: boolean, isManager: boolean, isAdmin: boolean): boolean => { if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { const isReimburser = session?.email === policy?.reimbursersEmail; return isReimburser && (isApproved || isManager); - } else if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { - return isPolicyAdmin && (isApproved || isManager); - } else { - return false; } + if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { + return isAdmin && (isApproved || isManager); + } + return false; }; /** * Create an object mapping member emails to their accountIDs. Filter for members without errors, and get the login email from the personalDetail object using the accountID. From 1c9b2a2eb74cb08be241f31befa13ccd23bd5c81 Mon Sep 17 00:00:00 2001 From: c3024 Date: Fri, 23 Feb 2024 20:46:07 +0530 Subject: [PATCH 3/9] payment options based on reimbursement choice --- src/components/SettlementButton.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/SettlementButton.tsx b/src/components/SettlementButton.tsx index 50bfcd4cc8be..50da110f6902 100644 --- a/src/components/SettlementButton.tsx +++ b/src/components/SettlementButton.tsx @@ -21,6 +21,7 @@ import type {EmptyObject} from '@src/types/utils/EmptyObject'; import ButtonWithDropdownMenu from './ButtonWithDropdownMenu'; import * as Expensicons from './Icon/Expensicons'; import KYCWall from './KYCWall'; +import {useSession} from './OnyxProvider'; type KYCFlowEvent = GestureResponderEvent | KeyboardEvent | undefined; @@ -133,6 +134,10 @@ function SettlementButton({ PaymentMethods.openWalletPage(); }, []); + const policy = ReportUtils.getPolicy(policyID); + const session = useSession(); + const shouldShowPaywithExpensifyOption = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES ? policy?.reimbursersEmail === session?.email : false; + const paymentButtonOptions = useMemo(() => { const buttonOptions = []; const isExpenseReport = ReportUtils.isExpenseReport(iouReport); @@ -172,7 +177,7 @@ function SettlementButton({ if (canUseWallet) { buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.EXPENSIFY]); } - if (isExpenseReport) { + if (isExpenseReport && shouldShowPaywithExpensifyOption) { buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.VBBA]); } buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]); From 6cd13a0fc085d400c44f0634cdf2f3534289e0f2 Mon Sep 17 00:00:00 2001 From: c3024 Date: Sat, 24 Feb 2024 21:21:57 +0530 Subject: [PATCH 4/9] fix review comments --- src/components/SettlementButton.tsx | 2 +- src/libs/PolicyUtils.ts | 2 +- src/types/onyx/Policy.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/SettlementButton.tsx b/src/components/SettlementButton.tsx index 50da110f6902..fd54144374c4 100644 --- a/src/components/SettlementButton.tsx +++ b/src/components/SettlementButton.tsx @@ -136,7 +136,7 @@ function SettlementButton({ const policy = ReportUtils.getPolicy(policyID); const session = useSession(); - const shouldShowPaywithExpensifyOption = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES ? policy?.reimbursersEmail === session?.email : false; + const shouldShowPaywithExpensifyOption = !shouldHidePaymentOptions && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && policy?.reimburserEmail === session?.email; const paymentButtonOptions = useMemo(() => { const buttonOptions = []; diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 3b2fbc43eb8f..34fc57ccf8cc 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -112,7 +112,7 @@ const isPolicyMember = (policyID: string, policies: OnyxCollection): boo const isPolicyPayer = (policy: OnyxEntry | EmptyObject, session: OnyxEntry, isApproved: boolean, isManager: boolean, isAdmin: boolean): boolean => { if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { - const isReimburser = session?.email === policy?.reimbursersEmail; + const isReimburser = session?.email === policy?.reimburserEmail; return isReimburser && (isApproved || isManager); } if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 44a96d23cf09..cb14fd69898b 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -172,7 +172,7 @@ type Policy = { }; /** Email of the reimburser when reimbursement is set direct */ - reimbursersEmail?: string; + reimburserEmail?: string; /** ReportID of the admins room for this workspace */ chatReportIDAdmins?: number; From c142581e0cf9e13ca9abaa46fc048a978596740e Mon Sep 17 00:00:00 2001 From: c3024 Date: Mon, 26 Feb 2024 21:52:34 +0530 Subject: [PATCH 5/9] fix lint --- src/components/SettlementButton.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/SettlementButton.tsx b/src/components/SettlementButton.tsx index fd54144374c4..e8d55eff88c0 100644 --- a/src/components/SettlementButton.tsx +++ b/src/components/SettlementButton.tsx @@ -136,7 +136,8 @@ function SettlementButton({ const policy = ReportUtils.getPolicy(policyID); const session = useSession(); - const shouldShowPaywithExpensifyOption = !shouldHidePaymentOptions && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && policy?.reimburserEmail === session?.email; + const shouldShowPaywithExpensifyOption = + !shouldHidePaymentOptions && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && policy?.reimburserEmail === session?.email; const paymentButtonOptions = useMemo(() => { const buttonOptions = []; From e616fe72848b0aba5a13bb078156582f00219940 Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 28 Feb 2024 08:24:18 +0530 Subject: [PATCH 6/9] fix prettier --- src/types/onyx/Policy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 30ec15fe61ee..98a3139f807a 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -215,8 +215,8 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< /** Collection of tax rates attached to a policy */ taxRates?: TaxRatesWithDefault; - /** Email of the reimburser when reimbursement is set direct */ - reimburserEmail?: string; + /** Email of the reimburser when reimbursement is set direct */ + reimburserEmail?: string; /** ReportID of the admins room for this workspace */ chatReportIDAdmins?: number; From 760e51b82c8359865251e6aa106c92931dc5040d Mon Sep 17 00:00:00 2001 From: c3024 Date: Thu, 29 Feb 2024 18:08:20 +0530 Subject: [PATCH 7/9] fix pay button for ious and free policies --- src/components/MoneyReportHeader.tsx | 2 +- .../ReportActionItem/ReportPreview.tsx | 2 +- src/libs/PolicyUtils.ts | 13 +-------- src/libs/ReportUtils.ts | 29 +++++++++++++++++++ 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index d94a0596e0c2..670f4e0c7be5 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -59,7 +59,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(moneyRequestReport, policy); const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicy(moneyRequestReport); const isManager = ReportUtils.isMoneyRequestReport(moneyRequestReport) && session?.accountID === moneyRequestReport.managerID; - const isPayer = PolicyUtils.isPolicyPayer(policy, session, isApproved, isManager, isPolicyAdmin); + const isPayer = ReportUtils.isPayer(policy, session, moneyRequestReport, isPaidGroupPolicy, isPolicyAdmin); const isDraft = ReportUtils.isDraftExpenseReport(moneyRequestReport); const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index b5d307f57b9c..d8cd3c3869a5 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -209,7 +209,7 @@ function ReportPreview({ const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport); const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN; - const isPayer = PolicyUtils.isPolicyPayer(policy, session, isApproved, isCurrentUserManager, isPolicyAdmin); + const isPayer = ReportUtils.isPayer(policy, session, iouReport, isPaidGroupPolicy, isPolicyAdmin); const isOnInstantSubmitPolicy = PolicyUtils.isInstantSubmitEnabled(policy); const isOnSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); const shouldShowPayButton = useMemo( diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index ec8e72568c89..70f87a8c7373 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -4,7 +4,7 @@ import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTagList, PolicyTags, Session} from '@src/types/onyx'; +import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTagList, PolicyTags} from '@src/types/onyx'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import Navigation from './Navigation/Navigation'; @@ -117,16 +117,6 @@ const isFreeGroupPolicy = (policy: OnyxEntry | EmptyObject): boolean => const isPolicyMember = (policyID: string, policies: OnyxCollection): boolean => Object.values(policies ?? {}).some((policy) => policy?.id === policyID); -const isPolicyPayer = (policy: OnyxEntry | EmptyObject, session: OnyxEntry, isApproved: boolean, isManager: boolean, isAdmin: boolean): boolean => { - if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { - const isReimburser = session?.email === policy?.reimburserEmail; - return isReimburser && (isApproved || isManager); - } - if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { - return isAdmin && (isApproved || isManager); - } - return false; -}; /** * Create an object mapping member emails to their accountIDs. Filter for members without errors, and get the login email from the personalDetail object using the accountID. * @@ -294,7 +284,6 @@ export { getCountOfEnabledTagsOfList, isPendingDeletePolicy, isPolicyMember, - isPolicyPayer, isPaidGroupPolicy, extractPolicyIDFromPath, getPathWithoutPolicyID, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0f8656adfa51..5f4e5fa9fbed 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1221,6 +1221,33 @@ function isOneOnOneChat(report: OnyxEntry): boolean { ); } +/** + * Checks if the current user is a payer of the request + */ + +function isPayer( + policy: OnyxEntry | EmptyObject, + session: OnyxEntry, + iouReport: OnyxEntry, + // eslint-disable-next-line @typescript-eslint/no-shadow + isPaidGroupPolicy: boolean, + isAdmin: boolean, +) { + const isApproved = isReportApproved(iouReport); + const isManager = iouReport?.managerID === session?.accountID; + if (isPaidGroupPolicy) { + if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { + const isReimburser = session?.email === policy?.reimburserEmail; + return isReimburser && (isApproved || isManager); + } + if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { + return isAdmin && (isApproved || isManager); + } + return false; + } + return isAdmin || (isMoneyRequestReport(iouReport) && isManager); +} + /** * Get the notification preference given a report */ @@ -1603,6 +1630,7 @@ function getIcons( name: personalDetails?.[report?.ownerAccountID ?? -1]?.displayName ?? '', fallbackIcon: personalDetails?.[report?.ownerAccountID ?? -1]?.fallbackIcon, }; + // eslint-disable-next-line @typescript-eslint/no-shadow const isPayer = currentUserAccountID === report?.managerID; return isPayer ? [managerIcon, ownerIcon] : [ownerIcon, managerIcon]; @@ -5156,6 +5184,7 @@ export { hasSingleParticipant, getReportRecipientAccountIDs, isOneOnOneChat, + isPayer, goBackToDetailsPage, getTransactionReportName, getTransactionDetails, From f0b7d003cae1553a3e0387e5fcc9f4dcfddfa974 Mon Sep 17 00:00:00 2001 From: c3024 Date: Fri, 1 Mar 2024 15:48:19 +0530 Subject: [PATCH 8/9] show pay with expensify for free policies --- src/components/SettlementButton.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/SettlementButton.tsx b/src/components/SettlementButton.tsx index e8d55eff88c0..42d0ab7e7cda 100644 --- a/src/components/SettlementButton.tsx +++ b/src/components/SettlementButton.tsx @@ -136,9 +136,11 @@ function SettlementButton({ const policy = ReportUtils.getPolicy(policyID); const session = useSession(); + const chatReport = ReportUtils.getReport(chatReportID); + const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicy(iouReport as OnyxEntry) || ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry); const shouldShowPaywithExpensifyOption = - !shouldHidePaymentOptions && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && policy?.reimburserEmail === session?.email; - + !isPaidGroupPolicy || + (!shouldHidePaymentOptions && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && policy?.reimburserEmail === session?.email); const paymentButtonOptions = useMemo(() => { const buttonOptions = []; const isExpenseReport = ReportUtils.isExpenseReport(iouReport); @@ -195,7 +197,6 @@ function SettlementButton({ // We don't want to reorder the options when the preferred payment method changes while the button is still visible // eslint-disable-next-line react-hooks/exhaustive-deps }, [currency, formattedAmount, iouReport, policyID, translate, shouldHidePaymentOptions, shouldShowApproveButton]); - const selectPaymentType = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => { if (iouPaymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY || iouPaymentType === CONST.IOU.PAYMENT_TYPE.VBBA) { triggerKYCFlow(event, iouPaymentType); From e9306bd11b29127edad18c3faec86b229a13274b Mon Sep 17 00:00:00 2001 From: c3024 Date: Mon, 4 Mar 2024 17:48:22 +0530 Subject: [PATCH 9/9] fewer params for isPayer,simplify paidPolicy check --- src/components/MoneyReportHeader.tsx | 3 +-- .../ReportActionItem/ReportPreview.tsx | 4 +--- src/components/SettlementButton.tsx | 2 +- src/libs/ReportUtils.ts | 19 +++++++------------ 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 670f4e0c7be5..102f85ea49b9 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -55,11 +55,10 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); const canAllowSettlement = ReportUtils.hasUpdatedTotal(moneyRequestReport); const policyType = policy?.type; - const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN; const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(moneyRequestReport, policy); const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicy(moneyRequestReport); const isManager = ReportUtils.isMoneyRequestReport(moneyRequestReport) && session?.accountID === moneyRequestReport.managerID; - const isPayer = ReportUtils.isPayer(policy, session, moneyRequestReport, isPaidGroupPolicy, isPolicyAdmin); + const isPayer = ReportUtils.isPayer(session, moneyRequestReport); const isDraft = ReportUtils.isDraftExpenseReport(moneyRequestReport); const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index d8cd3c3869a5..ad5dd0ba9caa 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -120,7 +120,6 @@ function ReportPreview({ const managerID = iouReport?.managerID ?? 0; const isCurrentUserManager = managerID === session?.accountID; const {totalDisplaySpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport); - const policyType = policy?.type; const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(iouReport, policy); const iouSettled = ReportUtils.isSettled(iouReportID); @@ -208,8 +207,7 @@ function ReportPreview({ const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport); const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport); - const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN; - const isPayer = ReportUtils.isPayer(policy, session, iouReport, isPaidGroupPolicy, isPolicyAdmin); + const isPayer = ReportUtils.isPayer(session, iouReport); const isOnInstantSubmitPolicy = PolicyUtils.isInstantSubmitEnabled(policy); const isOnSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); const shouldShowPayButton = useMemo( diff --git a/src/components/SettlementButton.tsx b/src/components/SettlementButton.tsx index 42d0ab7e7cda..d1c5a9450902 100644 --- a/src/components/SettlementButton.tsx +++ b/src/components/SettlementButton.tsx @@ -137,7 +137,7 @@ function SettlementButton({ const policy = ReportUtils.getPolicy(policyID); const session = useSession(); const chatReport = ReportUtils.getReport(chatReportID); - const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicy(iouReport as OnyxEntry) || ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry); + const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry); const shouldShowPaywithExpensifyOption = !isPaidGroupPolicy || (!shouldHidePaymentOptions && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && policy?.reimburserEmail === session?.email); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5f4e5fa9fbed..5ffcf55339a2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1225,17 +1225,13 @@ function isOneOnOneChat(report: OnyxEntry): boolean { * Checks if the current user is a payer of the request */ -function isPayer( - policy: OnyxEntry | EmptyObject, - session: OnyxEntry, - iouReport: OnyxEntry, - // eslint-disable-next-line @typescript-eslint/no-shadow - isPaidGroupPolicy: boolean, - isAdmin: boolean, -) { +function isPayer(session: OnyxEntry, iouReport: OnyxEntry) { const isApproved = isReportApproved(iouReport); + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`] ?? null; + const policyType = policy?.type; + const isAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN; const isManager = iouReport?.managerID === session?.accountID; - if (isPaidGroupPolicy) { + if (isPaidGroupPolicy(iouReport)) { if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { const isReimburser = session?.email === policy?.reimburserEmail; return isReimburser && (isApproved || isManager); @@ -1630,10 +1626,9 @@ function getIcons( name: personalDetails?.[report?.ownerAccountID ?? -1]?.displayName ?? '', fallbackIcon: personalDetails?.[report?.ownerAccountID ?? -1]?.fallbackIcon, }; - // eslint-disable-next-line @typescript-eslint/no-shadow - const isPayer = currentUserAccountID === report?.managerID; + const isManager = currentUserAccountID === report?.managerID; - return isPayer ? [managerIcon, ownerIcon] : [ownerIcon, managerIcon]; + return isManager ? [managerIcon, ownerIcon] : [ownerIcon, managerIcon]; } return getIconsForParticipants(report?.participantAccountIDs ?? [], personalDetails);