Skip to content
Merged
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({
key: ONYXKEYS.CONCIERGE_REPORT_ID,

Check warning on line 1055 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
callback: (value) => {
conciergeReportIDOnyxConnect = value;
},
Expand All @@ -1060,7 +1060,7 @@

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({
key: ONYXKEYS.SESSION,

Check warning on line 1063 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
callback: (value) => {
// When signed out, val is undefined
if (!value) {
Expand All @@ -1078,7 +1078,7 @@
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,

Check warning on line 1081 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
callback: (value) => {
if (currentUserAccountID) {
currentUserPersonalDetails = value?.[currentUserAccountID] ?? undefined;
Expand All @@ -1090,7 +1090,7 @@

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,

Check warning on line 1093 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
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
});
Expand All @@ -1098,7 +1098,7 @@
let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,

Check warning on line 1101 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
waitForCollectionCallback: true,
callback: (value) => {
allPolicies = value;
Expand All @@ -1108,7 +1108,7 @@

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,

Check warning on line 1111 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
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
});
Expand All @@ -1116,7 +1116,7 @@
let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,

Check warning on line 1119 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
waitForCollectionCallback: true,
callback: (value) => {
allReports = value;
Expand Down Expand Up @@ -1152,14 +1152,14 @@

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({
key: ONYXKEYS.BETA_CONFIGURATION,

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

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

Check warning on line 1162 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
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
Expand All @@ -1185,7 +1185,7 @@

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,

Check warning on line 1188 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
waitForCollectionCallback: true,
callback: (actions) => {
if (!actions) {
Expand Down Expand Up @@ -11315,7 +11315,6 @@
}

type CreateDraftTransactionParams = {
transactionID: string | undefined;
reportID: string | undefined;
actionName: IOUAction;
reportActionID: string | undefined;
Expand All @@ -11326,10 +11325,10 @@
amountOwed: OnyxEntry<number>;
isRestrictedToPreferredPolicy?: boolean;
preferredPolicyID?: string;
transaction: OnyxEntry<Transaction>;
};

function createDraftTransactionAndNavigateToParticipantSelector({
transactionID,
reportID,
actionName,
reportActionID,
Expand All @@ -11340,15 +11339,16 @@
amountOwed,
isRestrictedToPreferredPolicy = false,
preferredPolicyID,
transaction,
}: CreateDraftTransactionParams): void {
const transactionID = transaction?.transactionID;
if (!transactionID || !reportID) {
return;
}

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

if (!transaction || !reportActions) {
if (!reportActions) {
return;
}

Expand Down
7 changes: 4 additions & 3 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
shouldShowRightIcon: true,
action: () => {
createDraftTransactionAndNavigateToParticipantSelector({
transactionID: iouTransactionID,
reportID: actionReportID,
actionName: CONST.IOU.ACTION.SUBMIT,
reportActionID: actionableWhisperReportActionID,
Expand All @@ -465,6 +464,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
amountOwed,
isRestrictedToPreferredPolicy,
preferredPolicyID,
transaction: iouTransaction,
});
},
});
Expand All @@ -477,7 +477,6 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
shouldShowRightIcon: true,
action: () => {
createDraftTransactionAndNavigateToParticipantSelector({
transactionID: iouTransactionID,
reportID: actionReportID,
actionName: CONST.IOU.ACTION.CATEGORIZE,
reportActionID: actionableWhisperReportActionID,
Expand All @@ -486,6 +485,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
activePolicy,
userBillingGraceEndPeriods,
amountOwed,
transaction: iouTransaction,
});
},
});
Expand All @@ -497,7 +497,6 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
shouldShowRightIcon: true,
action: () => {
createDraftTransactionAndNavigateToParticipantSelector({
transactionID: iouTransactionID,
reportID: actionReportID,
actionName: CONST.IOU.ACTION.SHARE,
reportActionID: actionableWhisperReportActionID,
Expand All @@ -506,6 +505,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
activePolicy,
userBillingGraceEndPeriods,
amountOwed,
transaction: iouTransaction,
});
},
});
Expand Down Expand Up @@ -634,6 +634,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
reportActionsForOriginalReportID,
userBillingGraceEndPeriods,
amountOwed,
iouTransaction,
]);

const displayNamesWithTooltips = useMemo(() => {
Expand Down
10 changes: 6 additions & 4 deletions src/pages/inbox/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@ function PureReportActionItem({

const [childReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(action.childReportID)}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.chatReportID)}`);
const trackExpenseTransactionID = isActionableTrackExpense(action) ? getOriginalMessage(action)?.transactionID : undefined;
const [trackExpenseTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(trackExpenseTransactionID)}`);

const highlightedBackgroundColorIfNeeded = useMemo(
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down Expand Up @@ -933,14 +935,12 @@ function PureReportActionItem({

const reportActionReportID = originalReportID ?? reportID;
if (isActionableTrackExpense(action)) {
const transactionID = getOriginalMessage(action)?.transactionID;
const options = [
{
text: 'actionableMentionTrackExpense.submit',
key: `${action.reportActionID}-actionableMentionTrackExpense-submit`,
onPress: () => {
createDraftTransactionAndNavigateToParticipantSelector({
transactionID,
reportID: reportActionReportID,
actionName: CONST.IOU.ACTION.SUBMIT,
reportActionID: action.reportActionID,
Expand All @@ -951,6 +951,7 @@ function PureReportActionItem({
amountOwed,
isRestrictedToPreferredPolicy,
preferredPolicyID,
transaction: trackExpenseTransaction,
});
},
},
Expand All @@ -963,7 +964,6 @@ function PureReportActionItem({
key: `${action.reportActionID}-actionableMentionTrackExpense-categorize`,
onPress: () => {
createDraftTransactionAndNavigateToParticipantSelector({
transactionID,
reportID: reportActionReportID,
actionName: CONST.IOU.ACTION.CATEGORIZE,
reportActionID: action.reportActionID,
Expand All @@ -972,6 +972,7 @@ function PureReportActionItem({
activePolicy,
userBillingGraceEndPeriods,
amountOwed,
transaction: trackExpenseTransaction,
});
},
},
Expand All @@ -980,7 +981,6 @@ function PureReportActionItem({
key: `${action.reportActionID}-actionableMentionTrackExpense-share`,
onPress: () => {
createDraftTransactionAndNavigateToParticipantSelector({
transactionID,
reportID: reportActionReportID,
actionName: CONST.IOU.ACTION.SHARE,
reportActionID: action.reportActionID,
Expand All @@ -989,6 +989,7 @@ function PureReportActionItem({
activePolicy,
userBillingGraceEndPeriods,
amountOwed,
transaction: trackExpenseTransaction,
});
},
},
Expand Down Expand Up @@ -1135,6 +1136,7 @@ function PureReportActionItem({
personalPolicyID,
userBillingGraceEndPeriods,
amountOwed,
trackExpenseTransaction,
]);

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ describe('actions/IOU', () => {
// When the transaction is saved to draft by selecting a category in the selfDM report
const reportActionableTrackExpense = Object.values(selfDMReportActions ?? {}).find((reportAction) => isActionableTrackExpense(reportAction));
createDraftTransactionAndNavigateToParticipantSelector({
transactionID: transaction?.transactionID,
reportID: selfDMReport.reportID,
actionName: CONST.IOU.ACTION.CATEGORIZE,
reportActionID: reportActionableTrackExpense?.reportActionID,
Expand All @@ -637,6 +636,7 @@ describe('actions/IOU', () => {
activePolicy: undefined,
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
transaction,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1201,7 +1201,6 @@ describe('actions/IOU', () => {

// When a draft is created for categorization
createDraftTransactionAndNavigateToParticipantSelector({
transactionID: createdTransaction?.transactionID,
reportID: selfDMReport.reportID,
actionName: CONST.IOU.ACTION.CATEGORIZE,
reportActionID: actionableWhisper?.reportActionID,
Expand All @@ -1210,6 +1209,7 @@ describe('actions/IOU', () => {
activePolicy: undefined,
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
transaction: createdTransaction,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1843,7 +1843,6 @@ describe('actions/IOU', () => {

// When createDraftTransactionAndNavigateToParticipantSelector is called with draftTransactionIDs
createDraftTransactionAndNavigateToParticipantSelector({
transactionID: transactionToCategorize.transactionID,
reportID: selfDMReport.reportID,
actionName: CONST.IOU.ACTION.CATEGORIZE,
reportActionID,
Expand All @@ -1852,6 +1851,7 @@ describe('actions/IOU', () => {
activePolicy: undefined,
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
transaction: transactionToCategorize,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1891,7 +1891,6 @@ describe('actions/IOU', () => {

// When createDraftTransactionAndNavigateToParticipantSelector is called with empty allTransactionDrafts
createDraftTransactionAndNavigateToParticipantSelector({
transactionID: originalTransaction.transactionID,
reportID: selfDMReport.reportID,
actionName: CONST.IOU.ACTION.CATEGORIZE,
reportActionID,
Expand All @@ -1900,6 +1899,7 @@ describe('actions/IOU', () => {
activePolicy: undefined,
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
transaction: originalTransaction,
});
await waitForBatchedUpdates();

Expand All @@ -1921,14 +1921,13 @@ describe('actions/IOU', () => {
expect(draftTransaction?.linkedTrackedExpenseReportID).toBe(selfDMReport.reportID);
});

it('should not create draft transaction when transactionID is undefined', async () => {
it('should not create draft transaction when transaction is undefined', async () => {
// Given a selfDM report
const selfDMReport = createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport);

// When createDraftTransactionAndNavigateToParticipantSelector is called with undefined transactionID
// When createDraftTransactionAndNavigateToParticipantSelector is called with undefined transaction
createDraftTransactionAndNavigateToParticipantSelector({
transactionID: undefined,
reportID: selfDMReport.reportID,
actionName: CONST.IOU.ACTION.CATEGORIZE,
reportActionID: 'some-report-action-id',
Expand All @@ -1937,6 +1936,7 @@ describe('actions/IOU', () => {
activePolicy: undefined,
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
transaction: undefined,
});
await waitForBatchedUpdates();

Expand All @@ -1960,13 +1960,13 @@ describe('actions/IOU', () => {

// When createDraftTransactionAndNavigateToParticipantSelector is called with undefined reportID
createDraftTransactionAndNavigateToParticipantSelector({
transactionID: transaction.transactionID,
reportID: undefined,
actionName: CONST.IOU.ACTION.CATEGORIZE,
reportActionID: 'some-report-action-id',
introSelected: {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM},
draftTransactionIDs: [],
activePolicy: undefined,
transaction,
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
});
Expand Down
Loading
Loading