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
10 changes: 6 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@
};

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

Check warning on line 1058 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) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1063,7 +1063,7 @@
});

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

Check warning on line 1066 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 @@ -1081,7 +1081,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1084 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 (deprecatedCurrentUserAccountID) {
Expand All @@ -1093,7 +1093,7 @@
});

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

Check warning on line 1096 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),
Expand All @@ -1101,7 +1101,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1104 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) => {
Expand All @@ -1111,7 +1111,7 @@
});

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

Check warning on line 1114 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_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1119,7 +1119,7 @@

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

Check warning on line 1122 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 @@ -1155,14 +1155,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1158 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.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1165 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.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1188,7 +1188,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1191 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_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -2684,15 +2684,16 @@
/**
* Checks if a report is a transaction thread associated with a report that has only one transaction
*/
function isOneTransactionThread(report: OnyxEntry<Report>, parentReport: OnyxEntry<Report>, threadParentReportAction: OnyxEntry<ReportAction>) {
// TODO: isOffline will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66407
function isOneTransactionThread(report: OnyxEntry<Report>, parentReport: OnyxEntry<Report>, threadParentReportAction: OnyxEntry<ReportAction>, isOffline?: boolean) {
if (!report || !parentReport) {
return false;
}

const parentReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport?.reportID}`] ?? ([] as ReportAction[]);

const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReport?.chatReportID}`];
const transactionThreadReportID = getOneTransactionThreadReportID(parentReport, chatReport, parentReportActions);
const transactionThreadReportID = getOneTransactionThreadReportID(parentReport, chatReport, parentReportActions, isOffline);
return report?.reportID === transactionThreadReportID && !isSentMoneyReportAction(threadParentReportAction);
}

Expand All @@ -2707,12 +2708,13 @@
/**
* Get displayed report ID, it will be parentReportID if the report is one transaction thread
*/
function getDisplayedReportID(reportID: string): string {
// TODO: isOffline will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66407
function getDisplayedReportID(reportID: string, isOffline?: boolean): string {
const report = getReport(reportID, allReports);
const parentReportID = report?.parentReportID;
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`];
const parentReportAction = getReportAction(parentReportID, report?.parentReportActionID);
return parentReportID && isOneTransactionThread(report, parentReport, parentReportAction) ? parentReportID : reportID;
return parentReportID && isOneTransactionThread(report, parentReport, parentReportAction, isOffline) ? parentReportID : reportID;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/libs/actions/IOU/Hold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {getAllReports, getAllTransactions, getAllTransactionViolations, getCurre
/**
* Put expense on HOLD
*/
function putOnHold(transactionID: string, comment: string, initialReportID: string | undefined, ancestors: Ancestor[] = []) {
function putOnHold(transactionID: string, comment: string, initialReportID: string | undefined, isOffline: boolean, ancestors: Ancestor[] = []) {
const allTransactions = getAllTransactions();
const allTransactionViolations = getAllTransactionViolations();
const allReports = getAllReports();
Expand Down Expand Up @@ -318,14 +318,14 @@ function putOnHold(transactionID: string, comment: string, initialReportID: stri

API.write(WRITE_COMMANDS.HOLD_MONEY_REQUEST, params, {optimisticData, successData, failureData});

const currentReportID = getDisplayedReportID(reportID);
const currentReportID = getDisplayedReportID(reportID, isOffline);
Navigation.setNavigationActionToMicrotaskQueue(() => notifyNewAction(currentReportID, undefined, true));
}

function putTransactionsOnHold(transactionsID: string[], comment: string, reportID: string, ancestors: Ancestor[] = []) {
function putTransactionsOnHold(transactionsID: string[], comment: string, reportID: string, isOffline: boolean, ancestors: Ancestor[] = []) {
for (const transactionID of transactionsID) {
const {childReportID} = getIOUActionForReportID(reportID, transactionID) ?? {};
putOnHold(transactionID, comment, childReportID, ancestors);
putOnHold(transactionID, comment, childReportID, isOffline, ancestors);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/pages/Search/SearchHoldReasonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {useSearchActionsContext, useSearchStateContext} from '@components/Search
import useAncestors from '@hooks/useAncestors';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import {clearErrorFields, clearErrors} from '@libs/actions/FormActions';
import {putTransactionsOnHold} from '@libs/actions/IOU/Hold';
Expand All @@ -30,6 +31,7 @@ function SearchHoldReasonPage({route}: SearchHoldReasonPageProps) {
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const {isOffline} = useNetwork();

const selectedTransactionsList = Object.values(selectedTransactions);
const isSubmitter = report ? report.ownerAccountID === currentUserAccountID : selectedTransactionsList.some((t) => t.ownerAccountID === currentUserAccountID);
Expand All @@ -46,7 +48,7 @@ function SearchHoldReasonPage({route}: SearchHoldReasonPageProps) {
}

if (route.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT_HOLD_TRANSACTIONS) {
putTransactionsOnHold(selectedTransactionIDs, comment, reportID, ancestors);
putTransactionsOnHold(selectedTransactionIDs, comment, reportID, isOffline, ancestors);
clearSelectedTransactions(true);
} else {
holdMoneyRequestOnSearch(currentSearchHash, Object.keys(selectedTransactions), comment, allTransactions, allReportActions);
Expand All @@ -65,6 +67,7 @@ function SearchHoldReasonPage({route}: SearchHoldReasonPageProps) {
allTransactions,
allReportActions,
ancestors,
isOffline,
isDelegateAccessRestricted,
showDelegateNoAccessModal,
],
Expand Down
4 changes: 3 additions & 1 deletion src/pages/iou/HoldReasonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import useAncestors from '@hooks/useAncestors';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import {putOnHold} from '@libs/actions/IOU/Hold';
import {addErrorMessage} from '@libs/ErrorUtils';
Expand All @@ -31,6 +32,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) {
const {transactionID, reportID, backTo} = route.params;

const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const {isOffline} = useNetwork();
const ancestors = useAncestors(report);

const [parentReportOwnerAccountID] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {selector: getReportOwnerAccountID});
Expand All @@ -56,7 +58,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) {
return;
}

putOnHold(transactionID, values.comment, reportID, ancestors);
putOnHold(transactionID, values.comment, reportID, isOffline, ancestors);
Navigation.goBack(backTo);
};

Expand Down
4 changes: 2 additions & 2 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7108,7 +7108,7 @@ describe('actions/IOU', () => {
return waitForBatchedUpdates()
.then(() => Onyx.multiSet({...transactionCollectionDataSet, ...actionCollectionDataSet}))
.then(() => {
putOnHold(transaction1.transactionID, 'comment', iouReport.reportID);
putOnHold(transaction1.transactionID, 'comment', iouReport.reportID, false);
return waitForBatchedUpdates();
})
.then(() => {
Expand Down Expand Up @@ -13245,7 +13245,7 @@ describe('actions/IOU', () => {

// Put the expense on hold
if (originalTransactionID && transactionThreadReportID) {
putOnHold(originalTransactionID, 'Test hold reason', transactionThreadReportID);
putOnHold(originalTransactionID, 'Test hold reason', transactionThreadReportID, false);
}
await waitForBatchedUpdates();

Expand Down
Loading
Loading