Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ function MoneyRequestReportPreviewContent({
if (isPaidAnimationRunning) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
}
return getReportPreviewAction(violations, isIouReportArchived || isChatReportArchived, iouReport, policy, transactions, reportActions, invoiceReceiverPolicy);
return getReportPreviewAction(violations, isIouReportArchived || isChatReportArchived, iouReport, policy, transactions, invoiceReceiverPolicy);
}, [isPaidAnimationRunning, violations, iouReport, policy, transactions, isIouReportArchived, reportActions, invoiceReceiverPolicy, isChatReportArchived]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dangrous You forgot to update dependency here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aw shoot, I think I did but I think I must have merge-conflicted it back in at some point. Either way, do you need me to update or did you notice this because you were updating it elsewhere?


const addExpenseDropdownOptions = useMemo(
Expand Down
6 changes: 6 additions & 0 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ function validateReportDraftProperty(key: keyof Report | keyof ReportNameValuePa
case 'isDeletedParentAction':
case 'isWaitingOnBankAccount':
case 'isCancelledIOU':
case 'hasReportBeenReopened':
case 'isExportedToIntegration':
case 'hasExportError':
return validateBoolean(value);
case 'exportFailedTime':
case 'lastReadSequenceNumber':
Expand Down Expand Up @@ -623,6 +626,9 @@ function validateReportDraftProperty(key: keyof Report | keyof ReportNameValuePa
unheldNonReimbursableTotal: CONST.RED_BRICK_ROAD_PENDING_ACTION,
isWaitingOnBankAccount: CONST.RED_BRICK_ROAD_PENDING_ACTION,
isCancelledIOU: CONST.RED_BRICK_ROAD_PENDING_ACTION,
hasReportBeenReopened: CONST.RED_BRICK_ROAD_PENDING_ACTION,
isExportedToIntegration: CONST.RED_BRICK_ROAD_PENDING_ACTION,
hasExportError: CONST.RED_BRICK_ROAD_PENDING_ACTION,
iouReportID: CONST.RED_BRICK_ROAD_PENDING_ACTION,
preexistingReportID: CONST.RED_BRICK_ROAD_PENDING_ACTION,
nonReimbursableTotal: CONST.RED_BRICK_ROAD_PENDING_ACTION,
Expand Down
29 changes: 9 additions & 20 deletions src/libs/ReportPreviewActionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import type {Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation} from '@src/types/onyx';
import type {Policy, Report, Transaction, TransactionViolation} from '@src/types/onyx';
import {getCurrentUserAccountID} from './actions/Report';
import {
arePaymentsEnabled,
Expand All @@ -18,13 +18,10 @@ import {
getParentReport,
getReportTransactions,
hasAnyViolations as hasAnyViolationsUtil,
hasExportError as hasExportErrorUtil,
hasMissingSmartscanFields,
hasReportBeenReopened,
isClosedReport,
isCurrentUserSubmitter,
isExpenseReport,
isExported as isExportedUtil,
isInvoiceReport,
isIOUReport,
isOpenExpenseReport,
Expand All @@ -38,14 +35,7 @@ import {
import {getSession} from './SessionUtils';
import {allHavePendingRTERViolation, isPending, isScanning, shouldShowBrokenConnectionViolationForMultipleTransactions} from './TransactionUtils';

function canSubmit(
report: Report,
violations: OnyxCollection<TransactionViolation[]>,
isReportArchived: boolean,
reportActions?: OnyxEntry<ReportActions> | ReportAction[],
policy?: Policy,
transactions?: Transaction[],
) {
function canSubmit(report: Report, violations: OnyxCollection<TransactionViolation[]>, isReportArchived: boolean, policy?: Policy, transactions?: Transaction[]) {
if (isReportArchived) {
return false;
}
Expand All @@ -55,7 +45,7 @@ function canSubmit(
const isOpen = isOpenReport(report);
const isManager = report.managerID === getCurrentUserAccountID();
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const hasBeenReopened = hasReportBeenReopened(reportActions);
const hasBeenReopened = report.hasReportBeenReopened ?? false;
const isManualSubmitEnabled = getCorrectedAutoReportingFrequency(policy) === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL;

if (!!transactions && transactions?.length > 0 && transactions.every((transaction) => isPending(transaction))) {
Expand Down Expand Up @@ -164,7 +154,7 @@ function canPay(
return invoiceReceiverPolicy?.role === CONST.POLICY.ROLE.ADMIN && reimbursableSpend > 0;
}

function canExport(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy, reportActions?: OnyxEntry<ReportActions> | ReportAction[]) {
function canExport(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy) {
const isExpense = isExpenseReport(report);
const isExporter = policy ? isPreferredExporter(policy) : false;
const isReimbursed = isSettled(report);
Expand All @@ -178,12 +168,12 @@ function canExport(report: Report, violations: OnyxCollection<TransactionViolati
return false;
}

const isExported = isExportedUtil(reportActions);
const isExported = report.isExportedToIntegration ?? false;
if (isExported) {
return false;
}

const hasExportError = hasExportErrorUtil(reportActions);
const hasExportError = report.hasExportError ?? false;
if (syncEnabled && !hasExportError) {
return false;
}
Expand Down Expand Up @@ -234,7 +224,6 @@ function getReportPreviewAction(
report?: Report,
policy?: Policy,
transactions?: Transaction[],
reportActions?: OnyxEntry<ReportActions> | ReportAction[],
invoiceReceiverPolicy?: Policy,
): ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS> {
if (!report) {
Expand All @@ -243,7 +232,7 @@ function getReportPreviewAction(
if (isAddExpenseAction(report, transactions ?? [], isReportArchived)) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE;
}
if (canSubmit(report, violations, isReportArchived, reportActions, policy, transactions)) {
if (canSubmit(report, violations, isReportArchived, policy, transactions)) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT;
}
if (canApprove(report, violations, policy, transactions)) {
Expand All @@ -252,7 +241,7 @@ function getReportPreviewAction(
if (canPay(report, violations, isReportArchived, policy, invoiceReceiverPolicy)) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
}
if (canExport(report, violations, policy, reportActions)) {
if (canExport(report, violations, policy)) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.EXPORT_TO_ACCOUNTING;
}
if (canReview(report, violations, isReportArchived, policy, transactions)) {
Expand Down
24 changes: 21 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10832,7 +10832,13 @@ function getIntegrationNameFromExportMessage(reportActions: OnyxEntry<ReportActi
}
}

function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>): boolean {
// If report object is provided and has the property, use it directly
if (report?.isExportedToIntegration !== undefined) {
return report.isExportedToIntegration;
}

// Fallback to checking actions for backward compatibility
if (!reportActions) {
return false;
}
Expand Down Expand Up @@ -10860,7 +10866,13 @@ function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
return exportIntegrationActionsCount > integrationMessageActionsCount;
}

function hasExportError(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
function hasExportError(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>) {
// If report object is provided and has the property, use it directly
if (report?.hasExportError !== undefined) {
return report.hasExportError;
}

// Fallback to checking actions for backward compatibility
if (!reportActions) {
return false;
}
Expand Down Expand Up @@ -11137,7 +11149,13 @@ function findReportIDForAction(action?: ReportAction): string | undefined {
?.replace(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}`, '');
}

function hasReportBeenReopened(reportActions: OnyxEntry<ReportActions> | ReportAction[]): boolean {
function hasReportBeenReopened(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>): boolean {
// If report object is provided and has the property, use it directly
if (report?.hasReportBeenReopened !== undefined) {
return report.hasReportBeenReopened;
}

// Fallback to checking actions for backward compatibility
if (!reportActions) {
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback<
/** Whether the report is cancelled */
isCancelledIOU?: boolean;

/** Whether the report has been reopened */
hasReportBeenReopened?: boolean;

/** Whether the report has been exported to integration */
isExportedToIntegration?: boolean;

/** Whether the report has any export errors */
hasExportError?: boolean;

/** The ID of the IOU report */
iouReportID?: string;

Expand Down
3 changes: 3 additions & 0 deletions src/types/utils/whitelistedReportKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback<
errors: unknown;
isWaitingOnBankAccount: unknown;
isCancelledIOU: unknown;
hasReportBeenReopened: unknown;
isExportedToIntegration: unknown;
hasExportError: unknown;
iouReportID: unknown;
preexistingReportID: unknown;
nonReimbursableTotal: unknown;
Expand Down
6 changes: 3 additions & 3 deletions tests/actions/ReportPreviewActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ describe('getReportPreviewAction', () => {
} as unknown as Transaction;

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], undefined, invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
});

it('getReportPreviewAction should return VIEW action for zero value invoice', async () => {
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('getReportPreviewAction', () => {

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report.parentReportID));

expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], undefined, invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW);
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW);
});

it('canPay should return false for archived invoice', async () => {
Expand Down Expand Up @@ -364,7 +364,7 @@ describe('getReportPreviewAction', () => {
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], undefined, invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
});

it('getReportPreviewAction should return VIEW action for invoice when the chat report is archived', async () => {
Expand Down