Skip to content

Commit ea7cae9

Browse files
authored
Merge pull request Expensify#76230 from software-mansion-labs/jnowakow/revert-pr-73208
[CP Staging] Revert "Merge pull request Expensify#73208 from software-mansion-labs/jnowakow/556957-remove-unused-params"
2 parents 188cb7d + 1677c3e commit ea7cae9

14 files changed

Lines changed: 32 additions & 105 deletions

src/ONYXKEYS.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ const ONYXKEYS = {
132132
/** Whether the user is a member of a policy other than their personal */
133133
HAS_NON_PERSONAL_POLICY: 'hasNonPersonalPolicy',
134134

135-
/** Key under which selfDM id is stored. Returned by OpenApp */
136-
SELF_DM_REPORT_ID: 'selfDMReportID',
137-
138135
/** NVP keys */
139136

140137
/** This NVP contains list of at most 5 recent attendees */
@@ -1308,7 +1305,6 @@ type OnyxValuesMapping = {
13081305
[ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE]: DistanceExpenseType;
13091306
[ONYXKEYS.NVP_REPORT_LAYOUT_GROUP_BY]: string;
13101307
[ONYXKEYS.HAS_DENIED_CONTACT_IMPORT_PROMPT]: boolean | undefined;
1311-
[ONYXKEYS.SELF_DM_REPORT_ID]: string | undefined;
13121308
};
13131309

13141310
type OnyxDerivedValuesMapping = {

src/libs/ReportUtils.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,17 +1207,6 @@ Onyx.connect({
12071207
},
12081208
});
12091209

1210-
let selfDMReportID: string | undefined;
1211-
Onyx.connectWithoutView({
1212-
key: ONYXKEYS.SELF_DM_REPORT_ID,
1213-
callback: (value) => {
1214-
if (!value) {
1215-
return;
1216-
}
1217-
selfDMReportID = value;
1218-
},
1219-
});
1220-
12211210
function getCurrentUserAvatar(): AvatarSource | undefined {
12221211
return currentUserPersonalDetails?.avatar;
12231212
}
@@ -1868,12 +1857,7 @@ function findSelfDMReportID(): string | undefined {
18681857
return;
18691858
}
18701859

1871-
if (selfDMReportID) {
1872-
return selfDMReportID;
1873-
}
1874-
18751860
const selfDMReport = Object.values(allReports).find((report) => isSelfDM(report) && !isThread(report));
1876-
18771861
return selfDMReport?.reportID;
18781862
}
18791863

@@ -2496,8 +2480,9 @@ function isIOURequest(report: OnyxInputOrEntry<Report>): boolean {
24962480
*/
24972481
function isTrackExpenseReport(report: OnyxInputOrEntry<Report>): boolean {
24982482
if (isThread(report)) {
2483+
const selfDMReportID = findSelfDMReportID();
24992484
const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
2500-
return !isEmptyObject(parentReportAction) && findSelfDMReportID() === report.parentReportID && isTrackExpenseAction(parentReportAction);
2485+
return !isEmptyObject(parentReportAction) && selfDMReportID === report.parentReportID && isTrackExpenseAction(parentReportAction);
25012486
}
25022487
return false;
25032488
}
@@ -6487,7 +6472,7 @@ function buildOptimisticTaskCommentReportAction(
64876472

64886473
function buildOptimisticSelfDMReport(created: string): Report {
64896474
return {
6490-
reportID: findSelfDMReportID() ?? generateReportID(),
6475+
reportID: generateReportID(),
64916476
participants: {
64926477
[currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID]: {
64936478
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE,
@@ -6855,7 +6840,8 @@ function getMovedTransactionMessage(report: OnyxEntry<Report>) {
68556840
}
68566841

68576842
function getUnreportedTransactionMessage() {
6858-
const reportUrl = `${environmentURL}/r/${findSelfDMReportID()}`;
6843+
const selfDMReportID = findSelfDMReportID();
6844+
const reportUrl = `${environmentURL}/r/${selfDMReportID}`;
68596845
// eslint-disable-next-line @typescript-eslint/no-deprecated
68606846
const message = translateLocal('iou.unreportedTransaction', {
68616847
reportUrl,
@@ -11702,7 +11688,8 @@ function prepareOnboardingOnyxData(
1170211688

1170311689
let selfDMParameters: SelfDMParameters = {};
1170411690
if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND || engagementChoice === CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE) {
11705-
let selfDMReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${findSelfDMReportID()}`];
11691+
const selfDMReportID = findSelfDMReportID();
11692+
let selfDMReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`];
1170611693
let createdAction: ReportAction;
1170711694
if (!selfDMReport) {
1170811695
const currentTime = DateUtils.getDBTime();

src/libs/actions/Transaction.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
buildOptimisticUnHoldReportAction,
2323
buildOptimisticUnreportedTransactionAction,
2424
buildTransactionThread,
25+
findSelfDMReportID,
2526
getReportTransactions,
2627
getTransactionDetails,
2728
hasViolations as hasViolationsReportUtils,
@@ -700,7 +701,6 @@ function changeTransactionsReport(
700701
policy?: OnyxEntry<Policy>,
701702
reportNextStep?: OnyxEntry<ReportNextStepDeprecated>,
702703
policyCategories?: OnyxEntry<PolicyCategories>,
703-
selfDMReportIDParam?: string,
704704
) {
705705
const reportID = newReport?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID;
706706

@@ -720,16 +720,15 @@ function changeTransactionsReport(
720720
const failureData: OnyxUpdate[] = [];
721721
const successData: OnyxUpdate[] = [];
722722

723-
let selfDMReportID = selfDMReportIDParam;
724-
let selfDMReport: Report | undefined = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`];
723+
const existingSelfDMReportID = findSelfDMReportID();
724+
let selfDMReport: Report | undefined;
725725
let selfDMCreatedReportAction: ReportAction | undefined;
726726
const currentUserAccountID = getCurrentUserAccountID();
727727

728-
if (!selfDMReport && reportID === CONST.REPORT.UNREPORTED_REPORT_ID) {
728+
if (!existingSelfDMReportID && reportID === CONST.REPORT.UNREPORTED_REPORT_ID) {
729729
const currentTime = DateUtils.getDBTime();
730730
selfDMReport = buildOptimisticSelfDMReport(currentTime);
731731
selfDMCreatedReportAction = buildOptimisticCreatedReportAction(email ?? '', currentTime);
732-
selfDMReportID = selfDMReport.reportID;
733732

734733
// Add optimistic updates for self DM report
735734
optimisticData.push(
@@ -812,6 +811,8 @@ function changeTransactionsReport(
812811
for (const transaction of transactions) {
813812
const isUnreportedExpense = !transaction.reportID || transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
814813

814+
const selfDMReportID = existingSelfDMReportID ?? selfDMReport?.reportID;
815+
815816
const oldIOUAction = getIOUActionForReportID(isUnreportedExpense ? selfDMReportID : transaction.reportID, transaction.transactionID);
816817
if (!transaction.reportID || transaction.reportID === reportID) {
817818
continue;
@@ -1178,11 +1179,11 @@ function changeTransactionsReport(
11781179
: {}),
11791180
};
11801181

1181-
if (reportID === CONST.REPORT.UNREPORTED_REPORT_ID && selfDMReport && selfDMCreatedReportAction) {
1182+
if (!existingSelfDMReportID && reportID === CONST.REPORT.UNREPORTED_REPORT_ID && selfDMReport && selfDMCreatedReportAction) {
11821183
// Add self DM data to transaction data
11831184
transactionIDToReportActionAndThreadData[transaction.transactionID] = {
11841185
...baseTransactionData,
1185-
selfDMReportID,
1186+
selfDMReportID: selfDMReport.reportID,
11861187
selfDMCreatedReportActionID: selfDMCreatedReportAction.reportActionID,
11871188
};
11881189
} else {
@@ -1294,7 +1295,7 @@ function changeTransactionsReport(
12941295
}
12951296

12961297
// 9. Update next step for report
1297-
const destinationReportID = reportID === CONST.REPORT.UNREPORTED_REPORT_ID ? selfDMReportID : reportID;
1298+
const destinationReportID = reportID === CONST.REPORT.UNREPORTED_REPORT_ID ? (existingSelfDMReportID ?? selfDMReport?.reportID) : reportID;
12981299
const destinationReport = destinationReportID
12991300
? (allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${destinationReportID}`] ??
13001301
(destinationReportID === newReport?.reportID ? newReport : undefined) ??

src/pages/AddUnreportedExpense.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
2424
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
2525
import type {AddUnreportedExpensesParamList} from '@libs/Navigation/types';
2626
import {canSubmitPerDiemExpenseFromWorkspace, getPerDiemCustomUnit} from '@libs/PolicyUtils';
27-
import {findSelfDMReportID, getTransactionDetails, isIOUReport} from '@libs/ReportUtils';
27+
import {getTransactionDetails, isIOUReport} from '@libs/ReportUtils';
2828
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
2929
import tokenizedSearch from '@libs/tokenizedSearch';
3030
import {createUnreportedExpenseSections, getAmount, getCurrency, getDescription, getMerchant, isPerDiemRequest} from '@libs/TransactionUtils';
@@ -62,7 +62,6 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
6262
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
6363
const session = useSession();
6464
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
65-
const selfDMReportID = useMemo(() => findSelfDMReportID(), []);
6665
const shouldShowUnreportedTransactionsSkeletons = isLoadingUnreportedTransactions && hasMoreUnreportedTransactionsResults && !isOffline;
6766

6867
const getUnreportedTransactions = useCallback(
@@ -190,7 +189,6 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
190189
policy,
191190
reportNextStep,
192191
policyCategories,
193-
selfDMReportID,
194192
);
195193
}
196194
});

src/pages/NewReportWorkspaceSelectionPage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Navigation from '@libs/Navigation/Navigation';
2525
import type {NewReportWorkspaceSelectionNavigatorParamList} from '@libs/Navigation/types';
2626
import {getHeaderMessageForNonUserList} from '@libs/OptionsListUtils';
2727
import {canSubmitPerDiemExpenseFromWorkspace, isPolicyAdmin, shouldShowPolicy} from '@libs/PolicyUtils';
28-
import {findSelfDMReportID, getDefaultWorkspaceAvatar, getPolicyIDsWithEmptyReportsForAccount, hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils';
28+
import {getDefaultWorkspaceAvatar, getPolicyIDsWithEmptyReportsForAccount, hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils';
2929
import {buildCannedSearchQuery} from '@libs/SearchQueryUtils';
3030
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
3131
import {isPerDiemRequest} from '@libs/TransactionUtils';
@@ -72,7 +72,6 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag
7272
const shouldShowLoadingIndicator = isLoadingApp && !isOffline;
7373
const [pendingPolicySelection, setPendingPolicySelection] = useState<{policy: WorkspaceListItem; shouldShowEmptyReportConfirmation: boolean} | null>(null);
7474
const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: true});
75-
const selfDMReportID = useMemo(() => findSelfDMReportID(), []);
7675

7776
const policiesWithEmptyReportsSelector = useCallback(
7877
(reports: OnyxCollection<OnyxTypes.Report>) => {
@@ -126,7 +125,6 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag
126125
policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`],
127126
reportNextStep,
128127
undefined,
129-
selfDMReportID,
130128
);
131129

132130
// eslint-disable-next-line rulesdir/no-default-id-values

src/pages/ProfilePage.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-restricted-imports */
21
import {Str} from 'expensify-common';
32
import React, {useEffect, useMemo} from 'react';
43
import {View} from 'react-native';
@@ -75,18 +74,17 @@ function ProfilePage({route}: ProfilePageProps) {
7574
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
7675
const [isDebugModeEnabled = false] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true});
7776
const guideCalendarLink = account?.guideDetails?.calendarLink ?? '';
78-
const selfDMReportID = useMemo(() => findSelfDMReportID(), []);
7977

8078
const accountID = Number(route.params?.accountID ?? CONST.DEFAULT_NUMBER_ID);
8179
const isCurrentUser = session?.accountID === accountID;
8280
const reportKey = useMemo(() => {
83-
const reportID = isCurrentUser ? selfDMReportID : getChatByParticipants(session?.accountID ? [accountID, session.accountID] : [], reports)?.reportID;
81+
const reportID = isCurrentUser ? findSelfDMReportID() : getChatByParticipants(session?.accountID ? [accountID, session.accountID] : [], reports)?.reportID;
8482

8583
if (isAnonymousUserSession() || !reportID) {
8684
return `${ONYXKEYS.COLLECTION.REPORT}0` as const;
8785
}
8886
return `${ONYXKEYS.COLLECTION.REPORT}${reportID}` as const;
89-
}, [accountID, selfDMReportID, isCurrentUser, reports, session]);
87+
}, [accountID, isCurrentUser, reports, session]);
9088
const [report] = useOnyx(reportKey, {canBeMissing: true});
9189

9290
const styles = useThemeStyles();

src/pages/Search/SearchTransactionsChangeReport.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {createNewReport} from '@libs/actions/Report';
1212
import {changeTransactionsReport} from '@libs/actions/Transaction';
1313
import setNavigationActionToMicrotaskQueue from '@libs/Navigation/helpers/setNavigationActionToMicrotaskQueue';
1414
import Navigation from '@libs/Navigation/Navigation';
15-
import {findSelfDMReportID, getReportOrDraftReport, hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils';
15+
import {getReportOrDraftReport, hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils';
1616
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
1717
import IOURequestEditReportCommon from '@pages/iou/request/step/IOURequestEditReportCommon';
1818
import CONST from '@src/CONST';
@@ -39,7 +39,6 @@ function SearchTransactionsChangeReport() {
3939
const session = useSession();
4040
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
4141
const policyForMovingExpenses = policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined;
42-
const selfDMReportID = useMemo(() => findSelfDMReportID(), []);
4342

4443
const firstTransactionKey = selectedTransactionsKeys.at(0);
4544
const firstTransactionReportID = firstTransactionKey ? selectedTransactions[firstTransactionKey]?.reportID : undefined;
@@ -85,7 +84,6 @@ function SearchTransactionsChangeReport() {
8584
policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined,
8685
reportNextStep,
8786
undefined,
88-
selfDMReportID,
8987
);
9088
clearSelectedTransactions();
9189
});
@@ -127,7 +125,6 @@ function SearchTransactionsChangeReport() {
127125
allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`],
128126
reportNextStep,
129127
allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${item.policyID}`],
130-
selfDMReportID,
131128
);
132129
// eslint-disable-next-line @typescript-eslint/no-deprecated
133130
InteractionManager.runAfterInteractions(() => {
@@ -141,17 +138,7 @@ function SearchTransactionsChangeReport() {
141138
if (selectedTransactionsKeys.length === 0) {
142139
return;
143140
}
144-
changeTransactionsReport(
145-
selectedTransactionsKeys,
146-
isASAPSubmitBetaEnabled,
147-
session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
148-
session?.email ?? '',
149-
undefined,
150-
undefined,
151-
undefined,
152-
undefined,
153-
selfDMReportID,
154-
);
141+
changeTransactionsReport(selectedTransactionsKeys, isASAPSubmitBetaEnabled, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '');
155142
clearSelectedTransactions();
156143
Navigation.goBack();
157144
};

src/pages/TrackExpensePage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import ScreenWrapper from '@components/ScreenWrapper';
77
import useNetwork from '@hooks/useNetwork';
88
import useOnyx from '@hooks/useOnyx';
99
import useThemeStyles from '@hooks/useThemeStyles';
10+
import {confirmReadyToOpenApp} from '@libs/actions/App';
11+
import {startMoneyRequest} from '@libs/actions/IOU';
1012
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
1113
import Navigation from '@libs/Navigation/Navigation';
1214
import {findSelfDMReportID, generateReportID} from '@libs/ReportUtils';
13-
import {confirmReadyToOpenApp} from '@userActions/App';
14-
import {startMoneyRequest} from '@userActions/IOU';
1515
import CONST from '@src/CONST';
1616
import ONYXKEYS from '@src/ONYXKEYS';
1717
import ROUTES from '@src/ROUTES';

src/pages/iou/request/step/IOURequestEditReport.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
1212
import {changeTransactionsReport} from '@libs/actions/Transaction';
1313
import setNavigationActionToMicrotaskQueue from '@libs/Navigation/helpers/setNavigationActionToMicrotaskQueue';
1414
import Navigation from '@libs/Navigation/Navigation';
15-
import {findSelfDMReportID, hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils';
15+
import {hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils';
1616
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
1717
import {isPerDiemRequest} from '@libs/TransactionUtils';
1818
import {createNewReport} from '@userActions/Report';
@@ -58,7 +58,6 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
5858
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
5959
const hasViolations = hasViolationsReportUtils(undefined, transactionViolations);
6060
const policyForMovingExpenses = policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined;
61-
const selfDMReportID = useMemo(() => findSelfDMReportID(), []);
6261

6362
const selectReport = (item: TransactionGroupListItem, report?: OnyxEntry<Report>) => {
6463
if (selectedTransactionIDs.length === 0 || item.value === reportID) {
@@ -78,7 +77,6 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
7877
allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`],
7978
reportNextStep,
8079
allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${item.policyID}`],
81-
selfDMReportID,
8280
);
8381
turnOffMobileSelectionMode();
8482
clearSelectedTransactions(true);
@@ -91,17 +89,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
9189
if (!selectedReport || selectedTransactionIDs.length === 0) {
9290
return;
9391
}
94-
changeTransactionsReport(
95-
selectedTransactionIDs,
96-
isASAPSubmitBetaEnabled,
97-
session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
98-
session?.email ?? '',
99-
undefined,
100-
undefined,
101-
undefined,
102-
undefined,
103-
selfDMReportID,
104-
);
92+
changeTransactionsReport(selectedTransactionIDs, isASAPSubmitBetaEnabled, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '');
10593
if (shouldTurnOffSelectionMode) {
10694
turnOffMobileSelectionMode();
10795
}

0 commit comments

Comments
 (0)