@@ -1722,6 +1722,13 @@ function isBusinessInvoiceRoom(reportOrID: OnyxEntry<Report> | string): boolean
17221722 return !isEmptyObject(report) && isInvoiceRoom(report) && report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS;
17231723}
17241724
1725+ /**
1726+ * Returns the policyID of the invoice receiver when the receiver is a business, otherwise undefined.
1727+ */
1728+ function getInvoiceReceiverPolicyID(report: OnyxEntry<Report>): string | undefined {
1729+ return report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS ? report.invoiceReceiver.policyID : undefined;
1730+ }
1731+
17251732function isCurrentUserInvoiceReceiver(report: OnyxEntry<Report>): boolean {
17261733 if (report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL) {
17271734 return deprecatedCurrentUserAccountID === report.invoiceReceiver.accountID;
@@ -1798,14 +1805,13 @@ function isPublicAnnounceRoom(report: OnyxEntry<Report>): boolean {
17981805 * If the report is a policy expense, the route should be for adding bank account for that policy
17991806 * else since the report is a personal IOU, the route should be for personal bank account.
18001807 */
1801- function getBankAccountRoute(report: OnyxEntry<Report>): Route {
1808+ function getBankAccountRoute(report: OnyxEntry<Report>, areInvoicesEnabled: boolean | undefined ): Route {
18021809 if (isPolicyExpenseChat(report)) {
18031810 return ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute({policyID: report?.policyID, backTo: Navigation.getActiveRoute()});
18041811 }
18051812
18061813 if (isInvoiceRoom(report) && report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS) {
1807- const invoiceReceiverPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver?.policyID}`];
1808- if (invoiceReceiverPolicy?.areInvoicesEnabled) {
1814+ if (areInvoicesEnabled) {
18091815 return ROUTES.WORKSPACE_INVOICES.getRoute(report?.invoiceReceiver?.policyID);
18101816 }
18111817 }
@@ -5925,7 +5931,7 @@ function getReportName(reportNameInformation: GetReportNameParams): string {
59255931 }
59265932
59275933 if (isInvoiceRoom(report)) {
5928- const invoiceReceiverPolicyID = report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS ? report?.invoiceReceiver?.policyID : undefined ;
5934+ const invoiceReceiverPolicyID = getInvoiceReceiverPolicyID( report) ;
59295935 formattedName = getInvoicesChatName({
59305936 report,
59315937 // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
@@ -6142,7 +6148,7 @@ function getParentNavigationSubtitle(
61426148
61436149 if (isInvoiceReport(report) || isInvoiceRoom(parentReport)) {
61446150 const senderWorkspaceName = getPolicyName({report: parentReport, policy});
6145- const invoiceReceiverPolicyID = parentReport?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS ? parentReport.invoiceReceiver.policyID : undefined ;
6151+ const invoiceReceiverPolicyID = getInvoiceReceiverPolicyID( parentReport) ;
61466152 const invoiceReceiverPolicy = invoiceReceiverPolicyID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiverPolicyID}`] : undefined;
61476153 const isCurrentUserReceiver = isCurrentUserInvoiceReceiver(parentReport);
61486154 const invoicePayerName = getInvoicePayerName(parentReport, invoiceReceiverPolicy);
@@ -13334,6 +13340,7 @@ export {
1333413340 getAllWorkspaceReports,
1333513341 getAvailableReportFields,
1333613342 getBankAccountRoute,
13343+ getInvoiceReceiverPolicyID,
1333713344 getChatByParticipants,
1333813345 getChatRoomSubtitle,
1333913346 getChildReportNotificationPreference,
0 commit comments