Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ function MoneyReportHeader({
const activePolicy = usePolicy(activePolicyID);
const [integrationsExportTemplates] = useOnyx(ONYXKEYS.NVP_INTEGRATION_SERVER_EXPORT_TEMPLATES, {canBeMissing: true});
const [csvExportLayouts] = useOnyx(ONYXKEYS.NVP_CSV_EXPORT_LAYOUTS, {canBeMissing: true});
const [selfDMReportID] = useOnyx(ONYXKEYS.SELF_DM_REPORT_ID, {canBeMissing: true});
const [selfDMReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`, {canBeMissing: true});
const personalDetails = usePersonalDetails();
const expensifyIcons = useMemoizedLazyExpensifyIcons([
'Buildings',
Expand Down Expand Up @@ -1505,7 +1507,7 @@ function MoneyReportHeader({
Navigation.goBack(backToRoute);
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
deleteAppReport(moneyRequestReport?.reportID, email ?? '', accountID, reportTransactions, allTransactionViolations, bankAccountList);
deleteAppReport(moneyRequestReport, selfDMReport, email ?? '', accountID, reportTransactions, allTransactionViolations, bankAccountList);
});
});
},
Expand Down
36 changes: 17 additions & 19 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
/** @deprecated This value is deprecated and will be removed soon after migration. Use the email from useCurrentUserPersonalDetails hook instead. */
let deprecatedCurrentUserLogin: string | undefined;

Onyx.connect({

Check warning on line 290 in src/libs/actions/Report/index.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 @@ -301,7 +301,7 @@
},
});

Onyx.connect({

Check warning on line 304 in src/libs/actions/Report/index.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 @@ -309,7 +309,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 312 in src/libs/actions/Report/index.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,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -321,7 +321,7 @@
});

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

Check warning on line 324 in src/libs/actions/Report/index.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 All @@ -330,7 +330,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 333 in src/libs/actions/Report/index.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) => {
allPersonalDetails = value ?? {};
Expand All @@ -345,7 +345,7 @@
});

let onboarding: OnyxEntry<Onboarding>;
Onyx.connect({

Check warning on line 348 in src/libs/actions/Report/index.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_ONBOARDING,
callback: (val) => {
if (Array.isArray(val)) {
Expand All @@ -356,7 +356,7 @@
});

let introSelected: OnyxEntry<IntroSelected> = {};
Onyx.connect({

Check warning on line 359 in src/libs/actions/Report/index.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_INTRO_SELECTED,
callback: (val) => (introSelected = val),
});
Expand Down Expand Up @@ -5084,17 +5084,19 @@

/** Deletes a report and un-reports all transactions on the report along with its reportActions, any linked reports and any linked IOU report actions. */
function deleteAppReport(
reportID: string | undefined,
report: OnyxEntry<Report>,
selfDMReport: OnyxEntry<Report>,
currentUserEmailParam: string,
currentUserAccountIDParam: number,
reportTransactions: Record<string, Transaction>,
allTransactionViolations: OnyxCollection<TransactionViolations>,
bankAccountList: OnyxEntry<BankAccountList>,
) {
if (!reportID) {
Log.warn('[Report] deleteReport called with no reportID');
if (!report?.reportID) {
Log.warn('[Report] deleteAppReport called with no reportID');
return;
}
const reportID = report.reportID;
const optimisticData: Array<
OnyxUpdate<
| typeof ONYXKEYS.COLLECTION.REPORT
Expand All @@ -5110,25 +5112,22 @@
OnyxUpdate<typeof ONYXKEYS.COLLECTION.TRANSACTION | typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT>
> = [];

const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];

let selfDMReportID = findSelfDMReportID();
let selfDMReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`];
let selfDMReportID = selfDMReport?.reportID;
let createdAction: ReportAction;
let selfDMParameters: SelfDMParameters = {};

if (!selfDMReport) {
if (!selfDMReportID) {
const currentTime = DateUtils.getDBTime();
selfDMReport = buildOptimisticSelfDMReport(currentTime);
selfDMReportID = selfDMReport.reportID;
const optimisticSelfDMReport = buildOptimisticSelfDMReport(currentTime);
selfDMReportID = optimisticSelfDMReport.reportID;
createdAction = buildOptimisticCreatedReportAction(currentUserEmailParam ?? '', currentTime);
selfDMParameters = {reportID: selfDMReport.reportID, createdReportActionID: createdAction.reportActionID};
selfDMParameters = {reportID: optimisticSelfDMReport.reportID, createdReportActionID: createdAction.reportActionID};
optimisticData.push(
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`,
value: {
...selfDMReport,
...optimisticSelfDMReport,
pendingFields: {
createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
Expand All @@ -5141,14 +5140,14 @@
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${selfDMReport.reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${selfDMReportID}`,
value: {
isOptimisticReport: true,
},
},
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReport.reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReportID}`,
value: {
[createdAction.reportActionID]: createdAction,
},
Expand All @@ -5158,7 +5157,7 @@
successData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`,
value: {
pendingFields: {
createChat: null,
Expand All @@ -5167,14 +5166,14 @@
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${selfDMReport.reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${selfDMReportID}`,
value: {
isOptimisticReport: false,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReport.reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReportID}`,
value: {
[createdAction.reportActionID]: {
pendingAction: null,
Expand Down Expand Up @@ -5383,7 +5382,6 @@
value: null,
});

// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
failureData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ function PopoverReportActionContextMenu({ref}: PopoverReportActionContextMenuPro
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDRef.current}`, {
canBeMissing: true,
});
const [childReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportActionRef.current?.childReportID}`, {
canBeMissing: true,
});
const [selfDMReportID] = useOnyx(ONYXKEYS.SELF_DM_REPORT_ID, {canBeMissing: true});
const [selfDMReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`, {canBeMissing: true});
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: true});
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
const {currentSearchHash} = useSearchContext();
Expand Down Expand Up @@ -369,7 +374,7 @@ function PopoverReportActionContextMenu({ref}: PopoverReportActionContextMenuPro
deleteTransactions([originalMessage.IOUTransactionID], duplicateTransactions, duplicateTransactionViolations, currentSearchHash);
}
} else if (isReportPreviewAction(reportAction)) {
deleteAppReport(reportAction.childReportID, email ?? '', currentUserAccountID, reportTransactions, allTransactionViolations, bankAccountList);
deleteAppReport(childReport, selfDMReport, email ?? '', currentUserAccountID, reportTransactions, allTransactionViolations, bankAccountList);
} else if (reportAction) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
Expand All @@ -381,6 +386,8 @@ function PopoverReportActionContextMenu({ref}: PopoverReportActionContextMenuPro
setIsDeleteCommentConfirmModalVisible(false);
}, [
report,
childReport,
selfDMReport,
iouReport,
chatReport,
duplicateTransactions,
Expand Down
14 changes: 12 additions & 2 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,15 @@ describe('actions/Report', () => {
it('should only moves CREATE or TRACK type of IOU action to self DM', async () => {
// Given an expense report with CREATE, TRACK, and PAY of IOU actions
const reportID = '1';
const expenseReport: OnyxTypes.Report = {
...createRandomReport(1, undefined),
type: CONST.REPORT.TYPE.EXPENSE,
managerID: currentUserAccountID,
ownerAccountID: currentUserAccountID,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, expenseReport);
const firstIOUAction: OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> = {
reportActionID: '1',
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
Expand Down Expand Up @@ -2348,7 +2357,7 @@ describe('actions/Report', () => {
});

// When deleting the expense report
Report.deleteAppReport(reportID, '', currentUserAccountID, {}, {}, {});
Report.deleteAppReport(expenseReport, undefined, '', currentUserAccountID, {}, {}, {});
await waitForBatchedUpdates();

// Then only the IOU action with type of CREATE and TRACK is moved to the self DM
Expand Down Expand Up @@ -2444,7 +2453,8 @@ describe('actions/Report', () => {

// When deleting the first expense report
Report.deleteAppReport(
expenseReport1.reportID,
expenseReport1,
undefined,
'',
currentUserAccountID,
{
Expand Down
Loading