From 954bfc9a791326c7fd2ef882dde441db1e429242 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 12 Aug 2024 14:02:20 +0200 Subject: [PATCH 01/13] add invoice types --- src/types/onyx/Policy.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 9bac5f2e4de4..4a1cef1886d0 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -1311,6 +1311,15 @@ type PolicyInvoicingDetails = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Stripe Connect company website */ companyWebsite?: string; + + /** Back account */ + bankAccount?: { + /** Account balance */ + stripeConnectAccountBalance?: number; + + /** bankAccountID of selected BBA for payouts */ + transferBankAccountID?: number; + }; }>; /** Names of policy features */ From 987eb3b641e42ef150471b0acab2f67c6b8746a0 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 23 Aug 2024 14:24:07 +0200 Subject: [PATCH 02/13] create hasMissingInvoiceBankAccount --- src/libs/ReportUtils.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 38b73ffc2057..bf14e8cf72a4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7708,6 +7708,17 @@ function getApprovalChain(policy: OnyxEntry, employeeAccountID: number, return approvalChain; } +/** + * Checks if the user has missing bank account for the invoice room. + */ +function hasMissingInvoiceBankAccount(iouReportID: string): boolean { + const invoiceReport = getReport(iouReportID); + const invoiceRoomReport = getReport(invoiceReport?.chatReportID ?? ''); + const policy = getPolicy(invoiceRoomReport?.policyID); + + return invoiceRoomReport?.ownerAccountID === currentUserAccountID && isEmptyObject(policy?.invoice?.bankAccount ?? {}) && isSettled(iouReportID); +} + export { addDomainToShortMention, completeShortMention, @@ -8012,6 +8023,7 @@ export { getArchiveReason, getApprovalChain, isIndividualInvoiceRoom, + hasMissingInvoiceBankAccount, }; export type { From 7541d965d8a5e0c236673e198d34b55537c8dd76 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 23 Aug 2024 14:24:24 +0200 Subject: [PATCH 03/13] use hasMissingInvoiceBankAccount in ReportPreview --- src/components/ReportActionItem/ReportPreview.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 45a06968cefd..2417d8738938 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -305,7 +305,7 @@ function ReportPreview({ const shouldShowSettlementButton = (shouldShowPayButton || shouldShowApproveButton) && !showRTERViolationMessage; - const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID); + const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID) || ReportUtils.hasMissingInvoiceBankAccount(iouReportID); const shouldShowRBR = hasErrors; /* From c44507b3f7115a5a092dead6e559730db6f03026 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 23 Aug 2024 14:38:08 +0200 Subject: [PATCH 04/13] extend requiresAttentionFromCurrentUser --- src/libs/ReportUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index bf14e8cf72a4..076ec9be1ad4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2586,6 +2586,10 @@ function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry | Op return true; } + if (isInvoiceRoom(optionOrReport) && optionOrReport?.ownerAccountID === currentUserAccountID && isEmptyObject(getPolicy(optionOrReport?.policyID)?.invoice?.bankAccount ?? {})) { + return true; + } + return false; } From b4fd0df035663e3deeb71df479d3c303d5183f36 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 23 Aug 2024 14:51:54 +0200 Subject: [PATCH 05/13] use hasMissingInvoiceBankAccount in getIOUReportActionDisplayMessage --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/libs/ReportUtils.ts | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 8a8fc815ddb4..ce0ec2dacacc 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -790,6 +790,7 @@ export default { managerApproved: ({manager}: ManagerApprovedParams) => `${manager} approved:`, managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} approved ${amount}`, payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`, + payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `paid ${amount}. Add a bank account to receive your payment.`, approvedAmount: ({amount}: ApprovedAmountParams) => `approved ${amount}`, forwardedAmount: ({amount}: ForwardedAmountParams) => `approved ${amount}`, waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up. Payment is on hold until ${submitterDisplayName} adds a bank account.`, diff --git a/src/languages/es.ts b/src/languages/es.ts index a51ce1d91bf7..8b225514872d 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -783,6 +783,7 @@ export default { managerApproved: ({manager}: ManagerApprovedParams) => `${manager} aprobó:`, managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} aprobó ${amount}`, payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`, + payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `pagó ${amount}. Agrega una cuenta bancaria para recibir tu pago.`, approvedAmount: ({amount}: ApprovedAmountParams) => `aprobó ${amount}`, forwardedAmount: ({amount}: ForwardedAmountParams) => `aprobó ${amount}`, waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inició el pago, pero no se procesará hasta que ${submitterDisplayName} añada una cuenta bancaria`, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 076ec9be1ad4..fd47e0ec4c00 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6900,7 +6900,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry, const isRequestSettled = isSettled(originalMessage?.IOUReportID); const isApproved = isReportApproved(iouReport); if (isRequestSettled) { - return Localize.translateLocal('iou.payerSettled', { + return Localize.translateLocal(hasMissingInvoiceBankAccount(IOUReportID ?? '') ? 'iou.payerSettledWithMissingBankAccount' : 'iou.payerSettled', { amount: formattedAmount, }); } @@ -7717,6 +7717,11 @@ function getApprovalChain(policy: OnyxEntry, employeeAccountID: number, */ function hasMissingInvoiceBankAccount(iouReportID: string): boolean { const invoiceReport = getReport(iouReportID); + + if (!isInvoiceReport(invoiceReport)) { + return false; + } + const invoiceRoomReport = getReport(invoiceReport?.chatReportID ?? ''); const policy = getPolicy(invoiceRoomReport?.policyID); From 56fd0c71aa7e9fbfcd468052c131ed51e3e19ba5 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 26 Aug 2024 15:17:09 +0200 Subject: [PATCH 06/13] fix paid message --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fd47e0ec4c00..44a147e521ff 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6882,7 +6882,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry, switch (originalMessage.paymentType) { case CONST.IOU.PAYMENT_TYPE.ELSEWHERE: - translationKey = 'iou.paidElsewhereWithAmount'; + translationKey = hasMissingInvoiceBankAccount(IOUReportID ?? '') ? 'iou.payerSettledWithMissingBankAccount' : 'iou.paidElsewhereWithAmount'; break; case CONST.IOU.PAYMENT_TYPE.EXPENSIFY: case CONST.IOU.PAYMENT_TYPE.VBBA: @@ -6900,7 +6900,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry, const isRequestSettled = isSettled(originalMessage?.IOUReportID); const isApproved = isReportApproved(iouReport); if (isRequestSettled) { - return Localize.translateLocal(hasMissingInvoiceBankAccount(IOUReportID ?? '') ? 'iou.payerSettledWithMissingBankAccount' : 'iou.payerSettled', { + return Localize.translateLocal('iou.payerSettled', { amount: formattedAmount, }); } From d35ee9f54ba73b02b1acae19be979b5bbd470eed Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 26 Aug 2024 16:24:14 +0200 Subject: [PATCH 07/13] tweak hasMissingInvoiceBankAccount --- src/libs/ReportUtils.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 44a147e521ff..b8abc6bfe9f2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7722,10 +7722,7 @@ function hasMissingInvoiceBankAccount(iouReportID: string): boolean { return false; } - const invoiceRoomReport = getReport(invoiceReport?.chatReportID ?? ''); - const policy = getPolicy(invoiceRoomReport?.policyID); - - return invoiceRoomReport?.ownerAccountID === currentUserAccountID && isEmptyObject(policy?.invoice?.bankAccount ?? {}) && isSettled(iouReportID); + return invoiceReport?.ownerAccountID === currentUserAccountID && isEmptyObject(getPolicy(invoiceReport?.policyID)?.invoice?.bankAccount ?? {}) && isSettled(iouReportID); } export { From d4af19ebc35cb05293ad5318389b4feb1a058fb2 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 26 Aug 2024 18:02:50 +0200 Subject: [PATCH 08/13] integrate add bank account button --- .../home/report/ReportActionItemFragment.tsx | 46 +++++++++++++++---- .../home/report/ReportActionItemMessage.tsx | 1 + 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/pages/home/report/ReportActionItemFragment.tsx b/src/pages/home/report/ReportActionItemFragment.tsx index 787904d72b81..7500dcfb8e80 100644 --- a/src/pages/home/report/ReportActionItemFragment.tsx +++ b/src/pages/home/report/ReportActionItemFragment.tsx @@ -1,5 +1,6 @@ import React, {memo} from 'react'; import type {StyleProp, TextStyle} from 'react-native'; +import Button from '@components/Button'; import RenderHTML from '@components/RenderHTML'; import Text from '@components/Text'; import UserDetailsTooltip from '@components/UserDetailsTooltip'; @@ -7,8 +8,10 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import convertToLTR from '@libs/convertToLTR'; +import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type {DecisionName, OriginalMessageSource} from '@src/types/onyx/OriginalMessage'; import type {Message} from '@src/types/onyx/ReportAction'; @@ -63,6 +66,9 @@ type ReportActionItemFragmentProps = { actionName?: ReportActionName; moderationDecision?: DecisionName; + + /** IOU report ID */ + iouReportID?: string; }; const MUTED_ACTIONS = [ @@ -92,6 +98,7 @@ function ReportActionItemFragment({ isFragmentContainingDisplayName = false, displayAsGroup = false, moderationDecision, + iouReportID, }: ReportActionItemFragmentProps) { const styles = useThemeStyles(); const {isOffline} = useNetwork(); @@ -125,15 +132,36 @@ function ReportActionItemFragment({ } return ( - + <> + + {!!iouReportID && ReportUtils.hasMissingInvoiceBankAccount(iouReportID) && ( +