Skip to content

Commit d3f6ee3

Browse files
author
Daniel Gale-Rosen
committed
first pass
1 parent ceaf183 commit d3f6ee3

3 files changed

Lines changed: 38 additions & 16 deletions

File tree

src/libs/ReportPreviewActionUtils.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
1+
import type {OnyxCollection} from 'react-native-onyx';
22
import type {ValueOf} from 'type-fest';
33
import CONST from '@src/CONST';
4-
import type {Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation} from '@src/types/onyx';
4+
import type {Policy, Report, Transaction, TransactionViolation} from '@src/types/onyx';
55
import {getCurrentUserAccountID} from './actions/Report';
66
import {
77
arePaymentsEnabled,
@@ -17,16 +17,13 @@ import {
1717
getMoneyRequestSpendBreakdown,
1818
getParentReport,
1919
getReportTransactions,
20-
hasExportError as hasExportErrorUtil,
2120
hasMissingSmartscanFields,
2221
hasNoticeTypeViolations,
23-
hasReportBeenReopened,
2422
hasViolations,
2523
hasWarningTypeViolations,
2624
isClosedReport,
2725
isCurrentUserSubmitter,
2826
isExpenseReport,
29-
isExported as isExportedUtil,
3027
isInvoiceReport,
3128
isIOUReport,
3229
isOpenExpenseReport,
@@ -43,7 +40,6 @@ import {allHavePendingRTERViolation, isPending, isScanning, shouldShowBrokenConn
4340
function canSubmit(
4441
report: Report,
4542
violations: OnyxCollection<TransactionViolation[]>,
46-
reportActions?: OnyxEntry<ReportActions> | ReportAction[],
4743
policy?: Policy,
4844
transactions?: Transaction[],
4945
isReportArchived = false,
@@ -57,7 +53,7 @@ function canSubmit(
5753
const isOpen = isOpenReport(report);
5854
const isManager = report.managerID === getCurrentUserAccountID();
5955
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
60-
const hasBeenReopened = hasReportBeenReopened(reportActions);
56+
const hasBeenReopened = report.hasReportBeenReopened ?? false;
6157
const isManualSubmitEnabled = getCorrectedAutoReportingFrequency(policy) === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL;
6258

6359
if (!!transactions && transactions?.length > 0 && transactions.every((transaction) => isPending(transaction))) {
@@ -171,7 +167,7 @@ function canPay(
171167
return invoiceReceiverPolicy?.role === CONST.POLICY.ROLE.ADMIN && reimbursableSpend > 0;
172168
}
173169

174-
function canExport(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy, reportActions?: OnyxEntry<ReportActions> | ReportAction[]) {
170+
function canExport(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy) {
175171
const isExpense = isExpenseReport(report);
176172
const isExporter = policy ? isPreferredExporter(policy) : false;
177173
const isReimbursed = isSettled(report);
@@ -186,12 +182,12 @@ function canExport(report: Report, violations: OnyxCollection<TransactionViolati
186182
return false;
187183
}
188184

189-
const isExported = isExportedUtil(reportActions);
185+
const isExported = report.isExportedToIntegration ?? false;
190186
if (isExported) {
191187
return false;
192188
}
193189

194-
const hasExportError = hasExportErrorUtil(reportActions);
190+
const hasExportError = report.hasExportError ?? false;
195191
if (syncEnabled && !hasExportError) {
196192
return false;
197193
}
@@ -246,7 +242,6 @@ function getReportPreviewAction(
246242
policy?: Policy,
247243
transactions?: Transaction[],
248244
isReportArchived = false,
249-
reportActions?: OnyxEntry<ReportActions> | ReportAction[],
250245
invoiceReceiverPolicy?: Policy,
251246
): ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS> {
252247
if (!report) {
@@ -255,7 +250,7 @@ function getReportPreviewAction(
255250
if (isAddExpenseAction(report, transactions ?? [], isReportArchived)) {
256251
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE;
257252
}
258-
if (canSubmit(report, violations, reportActions, policy, transactions, isReportArchived)) {
253+
if (canSubmit(report, violations, policy, transactions, isReportArchived)) {
259254
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT;
260255
}
261256
if (canApprove(report, violations, policy, transactions)) {
@@ -264,7 +259,7 @@ function getReportPreviewAction(
264259
if (canPay(report, violations, policy, isReportArchived, invoiceReceiverPolicy)) {
265260
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
266261
}
267-
if (canExport(report, violations, policy, reportActions)) {
262+
if (canExport(report, violations, policy)) {
268263
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.EXPORT_TO_ACCOUNTING;
269264
}
270265
if (canReview(report, violations, policy, transactions, isReportArchived)) {

src/libs/ReportUtils.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10771,7 +10771,13 @@ function getIntegrationNameFromExportMessage(reportActions: OnyxEntry<ReportActi
1077110771
}
1077210772
}
1077310773

10774-
function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
10774+
function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>): boolean {
10775+
// If report object is provided and has the property, use it directly
10776+
if (report?.isExportedToIntegration !== undefined) {
10777+
return report.isExportedToIntegration;
10778+
}
10779+
10780+
// Fallback to checking actions for backward compatibility
1077510781
if (!reportActions) {
1077610782
return false;
1077710783
}
@@ -10799,7 +10805,13 @@ function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
1079910805
return exportIntegrationActionsCount > integrationMessageActionsCount;
1080010806
}
1080110807

10802-
function hasExportError(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
10808+
function hasExportError(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>) {
10809+
// If report object is provided and has the property, use it directly
10810+
if (report?.hasExportError !== undefined) {
10811+
return report.hasExportError;
10812+
}
10813+
10814+
// Fallback to checking actions for backward compatibility
1080310815
if (!reportActions) {
1080410816
return false;
1080510817
}
@@ -11076,7 +11088,13 @@ function findReportIDForAction(action?: ReportAction): string | undefined {
1107611088
?.replace(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}`, '');
1107711089
}
1107811090

11079-
function hasReportBeenReopened(reportActions: OnyxEntry<ReportActions> | ReportAction[]): boolean {
11091+
function hasReportBeenReopened(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>): boolean {
11092+
// If report object is provided and has the property, use it directly
11093+
if (report?.hasReportBeenReopened !== undefined) {
11094+
return report.hasReportBeenReopened;
11095+
}
11096+
11097+
// Fallback to checking actions for backward compatibility
1108011098
if (!reportActions) {
1108111099
return false;
1108211100
}

src/types/onyx/Report.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback<
194194
/** Whether the report is cancelled */
195195
isCancelledIOU?: boolean;
196196

197+
/** Whether the report has been reopened */
198+
hasReportBeenReopened?: boolean;
199+
200+
/** Whether the report has been exported to integration */
201+
isExportedToIntegration?: boolean;
202+
203+
/** Whether the report has any export errors */
204+
hasExportError?: boolean;
205+
197206
/** The ID of the IOU report */
198207
iouReportID?: string;
199208

0 commit comments

Comments
 (0)