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,8 +439,8 @@
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]);

Check warning on line 443 in src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has an unnecessary dependency: 'reportActions'. Either exclude it or remove the dependency array

Check warning on line 443 in src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has an unnecessary dependency: 'reportActions'. Either exclude it or remove the dependency array

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 @@ -88,7 +88,7 @@
const TRANSACTION_VIOLATION_REQUIRED_PROPERTIES: Array<keyof TransactionViolation> = ['type', 'name'] satisfies Array<keyof TransactionViolation>;

let isInFocusMode: OnyxEntry<boolean>;
Onyx.connect({

Check warning on line 91 in src/libs/DebugUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_PRIORITY_MODE,
callback: (priorityMode) => {
isInFocusMode = priorityMode === CONST.PRIORITY_MODE.GSD;
Expand All @@ -96,7 +96,7 @@
});

let transactionViolations: OnyxCollection<TransactionViolation[]>;
Onyx.connect({

Check warning on line 99 in src/libs/DebugUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -105,7 +105,7 @@
});

let betas: OnyxEntry<Beta[]>;
Onyx.connect({

Check warning on line 108 in src/libs/DebugUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETAS,
callback: (value) => {
betas = value;
Expand Down Expand Up @@ -472,6 +472,9 @@
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 @@
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 @@ -890,7 +890,7 @@
const parsedReportActionMessageCache: Record<string, string> = {};

let conciergeReportID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 893 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportID = value;
Expand All @@ -898,7 +898,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 901 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -916,7 +916,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 919 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -928,14 +928,14 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 931 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
});

let allPolicies: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 938 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
Expand All @@ -943,7 +943,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 946 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -10832,7 +10832,13 @@
}
}

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 @@
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 @@
?.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
Loading