Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@
}, [iouTransactionID, requestParentReportAction, transactionThreadReport?.reportID, transactionViolations]);

const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
const targetPolicyTags = defaultExpensePolicy ? (allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${defaultExpensePolicy.id}`] ?? {}) : {};

Check warning on line 771 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

The 'targetPolicyTags' conditional could make the dependencies of useCallback Hook (at line 810) change on every render. Move it inside the useCallback callback. Alternatively, wrap the initialization of 'targetPolicyTags' in its own useMemo() Hook

Check warning on line 771 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

The 'targetPolicyTags' conditional could make the dependencies of useCallback Hook (at line 810) change on every render. Move it inside the useCallback callback. Alternatively, wrap the initialization of 'targetPolicyTags' in its own useMemo() Hook

const duplicateExpenseTransaction = useCallback(
(transactionList: OnyxTypes.Transaction[]) => {
Expand Down Expand Up @@ -939,15 +939,15 @@
setIsHoldEducationalModalVisible(false);
setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !shouldFailAllRequests);
if (requestParentReportAction) {
changeMoneyRequestHoldStatus(requestParentReportAction);
changeMoneyRequestHoldStatus(requestParentReportAction, transaction);
}
};

const dismissRejectModalBasedOnAction = () => {
if (rejectModalAction === CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.HOLD) {
dismissRejectUseExplanation();
if (requestParentReportAction) {
changeMoneyRequestHoldStatus(requestParentReportAction);
changeMoneyRequestHoldStatus(requestParentReportAction, transaction);
}
} else if (rejectModalAction === CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REJECT_BULK) {
dismissRejectUseExplanation();
Expand Down Expand Up @@ -1247,7 +1247,7 @@

if (IOUActions.length) {
for (const action of IOUActions) {
changeMoneyRequestHoldStatus(action);
changeMoneyRequestHoldStatus(action, transaction);
Comment thread
linhvovan29546 marked this conversation as resolved.
Outdated
}
return;
}
Expand All @@ -1257,7 +1257,7 @@
return;
}

changeMoneyRequestHoldStatus(moneyRequestAction);
changeMoneyRequestHoldStatus(moneyRequestAction, transaction);
}}
/>
),
Expand Down Expand Up @@ -1507,7 +1507,7 @@
const isDismissed = isReportSubmitter ? dismissedHoldUseExplanation : dismissedRejectUseExplanation;

if (isDismissed || isChatReportDM) {
changeMoneyRequestHoldStatus(requestParentReportAction);
changeMoneyRequestHoldStatus(requestParentReportAction, transaction);
} else if (isReportSubmitter) {
setIsHoldEducationalModalVisible(true);
} else {
Expand All @@ -1530,7 +1530,7 @@
return;
}

changeMoneyRequestHoldStatus(requestParentReportAction);
changeMoneyRequestHoldStatus(requestParentReportAction, transaction);
},
},
[CONST.REPORT.SECONDARY_ACTIONS.SPLIT]: {
Expand Down
10 changes: 5 additions & 5 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
return;
}

changeMoneyRequestHoldStatus(parentReportAction);
changeMoneyRequestHoldStatus(parentReportAction, transaction);
}}
/>
),
Expand Down Expand Up @@ -432,15 +432,15 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
setIsHoldEducationalModalVisible(false);
setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !shouldFailAllRequests);
if (parentReportAction) {
changeMoneyRequestHoldStatus(parentReportAction);
changeMoneyRequestHoldStatus(parentReportAction, transaction);
}
};

const dismissRejectModalBasedOnAction = () => {
if (rejectModalAction === CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.HOLD) {
dismissRejectUseExplanation();
if (parentReportAction) {
changeMoneyRequestHoldStatus(parentReportAction);
changeMoneyRequestHoldStatus(parentReportAction, transaction);
}
} else {
dismissRejectUseExplanation();
Expand Down Expand Up @@ -470,7 +470,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre

const isDismissed = isReportSubmitter ? dismissedHoldUseExplanation : dismissedRejectUseExplanation;
if (isDismissed || isParentChatReportDM) {
changeMoneyRequestHoldStatus(parentReportAction);
changeMoneyRequestHoldStatus(parentReportAction, transaction);
} else if (isReportSubmitter) {
setIsHoldEducationalModalVisible(true);
} else {
Expand All @@ -492,7 +492,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
return;
}

changeMoneyRequestHoldStatus(parentReportAction);
changeMoneyRequestHoldStatus(parentReportAction, transaction);
},
},
[CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.SPLIT]: {
Expand Down
31 changes: 15 additions & 16 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@
};

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

Check warning on line 1024 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 @@ -1029,7 +1029,7 @@
});

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

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

Check warning on line 1050 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 @@ -1059,7 +1059,7 @@
});

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

Check warning on line 1062 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 @@ -1067,7 +1067,7 @@

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

Check warning on line 1070 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 @@ -1077,7 +1077,7 @@
});

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

Check warning on line 1080 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 @@ -1085,7 +1085,7 @@

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

Check warning on line 1088 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 @@ -1121,23 +1121,23 @@
});

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

Check warning on line 1124 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 allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1131 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) => {
if (!value) {
return;
}
allTransactions = Object.fromEntries(Object.entries(value).filter(([, transaction]) => transaction));
deprecatedAllTransactions = Object.fromEntries(Object.entries(value).filter(([, transaction]) => transaction));

reportsTransactions = Object.values(value).reduce<Record<string, Transaction[]>>((all, transaction) => {
deprecatedReportsTransactions = Object.values(value).reduce<Record<string, Transaction[]>>((all, transaction) => {
const reportsMap = all;
if (!transaction?.reportID) {
return reportsMap;
Expand Down Expand Up @@ -1273,7 +1273,7 @@
return Object.values(transactions).filter((transaction): transaction is Transaction => !!transaction && transaction.reportID === reportID);
}

function getReportTransactions(reportID: string | undefined, allReportsTransactions: Record<string, Transaction[]> = reportsTransactions): Transaction[] {
function getReportTransactions(reportID: string | undefined, allReportsTransactions: Record<string, Transaction[]> = deprecatedReportsTransactions): Transaction[] {
if (!reportID) {
return [];
}
Expand Down Expand Up @@ -2309,7 +2309,7 @@
if (transactions) {
return !!transactions?.find((transaction) => transaction?.reportID === reportID);
}
return !!Object.values(allTransactions ?? {}).find((transaction) => transaction?.reportID === reportID);
return !!Object.values(deprecatedAllTransactions ?? {}).find((transaction) => transaction?.reportID === reportID);
}

/**
Expand Down Expand Up @@ -4356,7 +4356,7 @@
/**
* Checks if the report contains at least one Non-Reimbursable transaction
*/
function hasNonReimbursableTransactions(iouReportID: string | undefined, reportsTransactionsParam: Record<string, Transaction[]> = reportsTransactions): boolean {
function hasNonReimbursableTransactions(iouReportID: string | undefined, reportsTransactionsParam: Record<string, Transaction[]> = deprecatedReportsTransactions): boolean {
const transactions = getReportTransactions(iouReportID, reportsTransactionsParam);
return transactions.filter((transaction) => transaction.reimbursable === false).length > 0;
}
Expand Down Expand Up @@ -4916,7 +4916,7 @@

const iouMessage = getOriginalMessage(reportAction);
const moneyRequestReport = report ?? (iouMessage?.IOUReportID ? (getReport(iouMessage?.IOUReportID, allReports) ?? ({} as Report)) : ({} as Report));
const transaction = linkedTransaction ?? allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${iouMessage?.IOUTransactionID}`] ?? ({} as Transaction);
const transaction = linkedTransaction ?? deprecatedAllTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${iouMessage?.IOUTransactionID}`] ?? ({} as Transaction);

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.BILLABLE && isInvoiceReport(moneyRequestReport) && isReportApproved({report: moneyRequestReport})) {
return false;
Expand Down Expand Up @@ -5110,7 +5110,7 @@
return {canHoldRequest, canUnholdRequest};
}

const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>): void => {
const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>, iouTransaction: OnyxEntry<Transaction>): void => {
if (!isMoneyRequestAction(reportAction)) {
return;
}
Expand All @@ -5128,8 +5128,7 @@
return;
}
Comment thread
linhvovan29546 marked this conversation as resolved.

const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
const isOnHold = isOnHoldTransactionUtils(transaction);
const isOnHold = isOnHoldTransactionUtils(iouTransaction);
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`];

if (isOnHold) {
Expand Down Expand Up @@ -5204,7 +5203,7 @@
transactionID = getOriginalMessage(reportAction)?.IOUTransactionID;
}

return transactions ? transactions.find((transaction) => transaction.transactionID === transactionID) : allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
return transactions ? transactions.find((transaction) => transaction.transactionID === transactionID) : deprecatedAllTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
}

/**
Expand Down Expand Up @@ -8880,7 +8879,7 @@
reports: OnyxCollection<Report> | undefined,
policyID: string | undefined,
accountID?: number,
reportsTransactionsParam: Record<string, Transaction[]> = reportsTransactions,
reportsTransactionsParam: Record<string, Transaction[]> = deprecatedReportsTransactions,
): boolean {
if (!accountID || !policyID) {
return false;
Expand Down Expand Up @@ -8922,7 +8921,7 @@
function getPolicyIDsWithEmptyReportsForAccount(
reports: OnyxCollection<Report> | undefined,
accountID?: number,
reportsTransactionsParam: Record<string, Transaction[]> = reportsTransactions,
reportsTransactionsParam: Record<string, Transaction[]> = deprecatedReportsTransactions,
): Record<string, boolean> {
if (!accountID) {
return {};
Expand Down Expand Up @@ -10652,7 +10651,7 @@
}

const transactionID = isSplitOrTrackAction ? getOriginalMessage(action)?.IOUTransactionID : undefined;
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {};
const transaction = deprecatedAllTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {};
const isTransactionThreadError = isSplitOrTrackAction && hasMissingSmartscanFieldsTransactionUtils(transaction as Transaction, report);

return isTransactionThreadError;
Expand Down Expand Up @@ -11260,7 +11259,7 @@
return;
}

const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
const transaction = deprecatedAllTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? ([] as ReportAction[]);

if (!transaction || !reportActions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ function BaseReportActionContextMenu({
currentUserAccountID: currentUserPersonalDetails?.accountID,
currentUserPersonalDetails,
encryptedAuthToken,
iouTransaction,
};

if ('renderContent' in contextAction) {
Expand Down
13 changes: 7 additions & 6 deletions src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ type ContextMenuActionPayload = {
showDelegateNoAccessModal?: () => void;
currentUserPersonalDetails: ReturnType<typeof useCurrentUserPersonalDetails>;
encryptedAuthToken: string;
iouTransaction: OnyxEntry<Transaction>;
};

type OnPress = (closePopover: boolean, payload: ContextMenuActionPayload, selection?: string, reportID?: string, draftMessage?: string) => void;
Expand Down Expand Up @@ -552,19 +553,19 @@ const ContextMenuActions: ContextMenuAction[] = [
const holdReportAction = getReportAction(moneyRequestAction?.childReportID, `${iouTransaction?.comment?.hold ?? ''}`);
return canHoldUnholdReportAction(moneyRequestReport, moneyRequestAction, holdReportAction, iouTransaction, moneyRequestPolicy).canUnholdRequest;
},
onPress: (closePopover, {moneyRequestAction, isDelegateAccessRestricted, showDelegateNoAccessModal}) => {
onPress: (closePopover, {moneyRequestAction, iouTransaction, isDelegateAccessRestricted, showDelegateNoAccessModal}) => {
if (isDelegateAccessRestricted) {
hideContextMenu(false, showDelegateNoAccessModal);
return;
}

if (closePopover) {
hideContextMenu(false, () => changeMoneyRequestHoldStatus(moneyRequestAction));
hideContextMenu(false, () => changeMoneyRequestHoldStatus(moneyRequestAction, iouTransaction));
return;
}

// No popover to hide, call changeMoneyRequestHoldStatus immediately
changeMoneyRequestHoldStatus(moneyRequestAction);
changeMoneyRequestHoldStatus(moneyRequestAction, iouTransaction);
},
getDescription: () => {},
sentryLabel: CONST.SENTRY_LABEL.CONTEXT_MENU.UNHOLD,
Expand All @@ -580,19 +581,19 @@ const ContextMenuActions: ContextMenuAction[] = [
const holdReportAction = getReportAction(moneyRequestAction?.childReportID, `${iouTransaction?.comment?.hold ?? ''}`);
return canHoldUnholdReportAction(moneyRequestReport, moneyRequestAction, holdReportAction, iouTransaction, moneyRequestPolicy).canHoldRequest;
},
onPress: (closePopover, {moneyRequestAction, isDelegateAccessRestricted, showDelegateNoAccessModal}) => {
onPress: (closePopover, {moneyRequestAction, iouTransaction, isDelegateAccessRestricted, showDelegateNoAccessModal}) => {
if (isDelegateAccessRestricted) {
hideContextMenu(false, showDelegateNoAccessModal);
return;
}

if (closePopover) {
hideContextMenu(false, () => changeMoneyRequestHoldStatus(moneyRequestAction));
hideContextMenu(false, () => changeMoneyRequestHoldStatus(moneyRequestAction, iouTransaction));
return;
}

// No popover to hide, call changeMoneyRequestHoldStatus immediately
changeMoneyRequestHoldStatus(moneyRequestAction);
changeMoneyRequestHoldStatus(moneyRequestAction, iouTransaction);
},
getDescription: () => {},
sentryLabel: CONST.SENTRY_LABEL.CONTEXT_MENU.HOLD,
Expand Down
Loading
Loading