Skip to content

Commit 27d530a

Browse files
authored
Merge pull request Expensify#88624 from lorretheboy/fix-part-03/73656
(Part 2) Remove Onyx.connect() for the key: ONYXKEYS.PERSONAL_DETAILS_LIST in src/libs/actions/Report.ts
2 parents 66ad67d + f89bee0 commit 27d530a

15 files changed

Lines changed: 293 additions & 74 deletions

File tree

src/components/ReportActionItem/MoneyRequestReceiptView.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {useRoute} from '@react-navigation/native';
22
import {hasSeenTourSelector} from '@selectors/Onboarding';
3+
import {conciergePersonalDetailSelector, personalDetailByAccountIDSelector} from '@selectors/PersonalDetails';
34
import mapValues from 'lodash/mapValues';
45
import React, {useEffect, useMemo, useRef, useState} from 'react';
56
import {View} from 'react-native';
@@ -136,6 +137,11 @@ function MoneyRequestReceiptView({
136137
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
137138
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
138139
const [betas] = useOnyx(ONYXKEYS.BETAS);
140+
const [conciergePersonalDetail] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: conciergePersonalDetailSelector});
141+
const reportOwnerSelector = useMemo(() => personalDetailByAccountIDSelector(report?.ownerAccountID), [report?.ownerAccountID]);
142+
const [reportOwnerPersonalDetail] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: reportOwnerSelector}, [reportOwnerSelector]);
143+
const chatReportOwnerSelector = useMemo(() => personalDetailByAccountIDSelector(chatReport?.ownerAccountID), [chatReport?.ownerAccountID]);
144+
const [chatReportOwnerPersonalDetail] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: chatReportOwnerSelector}, [chatReportOwnerSelector]);
139145
const delegateAccountID = useDelegateAccountID();
140146

141147
const [isLoading, setIsLoading] = useState(true);
@@ -164,7 +170,8 @@ function MoneyRequestReceiptView({
164170
const didReceiptScanSucceed = hasReceipt && didReceiptScanSucceedTransactionUtils(transaction);
165171
const isInvoice = isInvoiceReport(moneyRequestReport);
166172
const isChatReportArchived = useReportIsArchived(moneyRequestReport?.chatReportID);
167-
const {login: currentUserLogin, accountID: currentUserAccountID, timezone: currentUserTimezone} = useCurrentUserPersonalDetails();
173+
const currentUserPersonalDetail = useCurrentUserPersonalDetails();
174+
const {login: currentUserLogin, accountID: currentUserAccountID, timezone: currentUserTimezone} = currentUserPersonalDetail;
168175
const theme = useTheme();
169176
const ancestors = useAncestors(report);
170177
const {hovered, bind: hoverBind} = useHover();
@@ -394,7 +401,19 @@ function MoneyRequestReceiptView({
394401
}
395402
if (transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
396403
if (chatReport?.reportID && getCreationReportErrors(chatReport)) {
397-
navigateToConciergeChatAndDeleteReport(chatReport.reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, betas, true, true);
404+
navigateToConciergeChatAndDeleteReport(
405+
chatReport.reportID,
406+
conciergeReportID,
407+
currentUserAccountID,
408+
introSelected,
409+
isSelfTourViewed,
410+
betas,
411+
chatReportOwnerPersonalDetail,
412+
currentUserPersonalDetail,
413+
conciergePersonalDetail,
414+
true,
415+
true,
416+
);
398417
return;
399418
}
400419
if (parentReportAction) {
@@ -433,7 +452,19 @@ function MoneyRequestReceiptView({
433452
if (isInNarrowPaneModal) {
434453
Navigation.goBack();
435454
}
436-
navigateToConciergeChatAndDeleteReport(report.reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, betas, true, true);
455+
navigateToConciergeChatAndDeleteReport(
456+
report.reportID,
457+
conciergeReportID,
458+
currentUserAccountID,
459+
introSelected,
460+
isSelfTourViewed,
461+
betas,
462+
reportOwnerPersonalDetail,
463+
currentUserPersonalDetail,
464+
conciergePersonalDetail,
465+
true,
466+
true,
467+
);
437468
}
438469
};
439470

src/components/ReportActionItem/TaskView.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,19 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
117117
<OfflineWithFeedback
118118
shouldShowErrorMessages
119119
errors={report?.errorFields?.editTask ?? report?.errorFields?.createTask}
120-
onClose={() => clearTaskErrors(report, conciergeReportID, accountID, introSelected, betas, isSelfTourViewed)}
120+
onClose={() =>
121+
clearTaskErrors(
122+
report,
123+
conciergeReportID,
124+
accountID,
125+
introSelected,
126+
betas,
127+
isSelfTourViewed,
128+
report?.ownerAccountID ? (personalDetails?.[report.ownerAccountID] ?? undefined) : undefined,
129+
currentUserPersonalDetails,
130+
(personalDetails ? Object.values(personalDetails).find((detail) => detail?.login === CONST.EMAIL.CONCIERGE) : undefined) ?? undefined,
131+
)
132+
}
121133
errorRowStyles={styles.ph5}
122134
>
123135
<Hoverable>

src/libs/actions/Report/index.ts

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ import type {
232232
VisibleReportActionsDerivedValue,
233233
} from '@src/types/onyx';
234234
import type {Decision} from '@src/types/onyx/OriginalMessage';
235+
import type PersonalDetails from '@src/types/onyx/PersonalDetails';
235236
import type {CurrentUserPersonalDetails, Timezone} from '@src/types/onyx/PersonalDetails';
236237
import type {ConnectionName} from '@src/types/onyx/Policy';
237238
import type {NotificationPreference, Participants, Participant as ReportParticipant, RoomVisibility, WriteCapability} from '@src/types/onyx/Report';
@@ -482,6 +483,20 @@ Onyx.connect({
482483
},
483484
});
484485

486+
/**
487+
* Builds a partial PersonalDetailsList containing only the records passed in. Skips entries with no accountID.
488+
*/
489+
function buildPersonalDetailsList(details: Array<OnyxEntry<PersonalDetails>>): PersonalDetailsList {
490+
const result: PersonalDetailsList = {};
491+
for (const detail of details) {
492+
if (detail?.accountID == null) {
493+
continue;
494+
}
495+
result[detail.accountID] = detail;
496+
}
497+
return result;
498+
}
499+
485500
const typingWatchTimers: Record<string, NodeJS.Timeout> = {};
486501

487502
// Track subscriptions to conciergeReasoning Pusher events to avoid duplicates.
@@ -2344,8 +2359,7 @@ function navigateToAndOpenReportWithAccountIDs(
23442359
introSelected: OnyxEntry<IntroSelected>,
23452360
isSelfTourViewed: boolean | undefined,
23462361
betas: OnyxEntry<Beta[]>,
2347-
// TODO: personalDetails should be a required field in follow-up PRs https://github.com/Expensify/App/issues/73656
2348-
personalDetails?: OnyxEntry<PersonalDetailsList>,
2362+
personalDetails: OnyxEntry<PersonalDetailsList>,
23492363
shouldRevalidateExistingChat = false,
23502364
) {
23512365
const participants = participantAccountIDs.map((accountID): ParticipantInfo => {
@@ -2372,8 +2386,7 @@ function navigateToAndOpenReportWithAccountIDs(
23722386
newReportObject: fallbackChat,
23732387
parentReportActionID: '0',
23742388
participants,
2375-
// TODO: allPersonalDetails fallback should be removed in follow-up PRs https://github.com/Expensify/App/issues/73656
2376-
personalDetails: personalDetails ?? allPersonalDetails,
2389+
personalDetails,
23772390
betas,
23782391
});
23792392

@@ -2431,9 +2444,8 @@ function navigateToAndOpenChildReport(
24312444
currentUserAccountID: number,
24322445
introSelected: OnyxEntry<IntroSelected>,
24332446
betas: OnyxEntry<Beta[]>,
2447+
personalDetails: OnyxEntry<PersonalDetailsList>,
24342448
isSelfTourViewed: boolean | undefined,
2435-
// TODO: personalDetails should be a required field in follow-up PRs https://github.com/Expensify/App/issues/73656
2436-
personalDetails?: OnyxEntry<PersonalDetailsList>,
24372449
) {
24382450
const report = childReport ?? createChildReport(childReport, parentReportAction, parentReport, currentUserAccountID, introSelected, betas, isSelfTourViewed, personalDetails);
24392451

@@ -3428,9 +3440,8 @@ function toggleSubscribeToChildReport(
34283440
introSelected: OnyxEntry<IntroSelected>,
34293441
isSelfTourViewed: boolean | undefined,
34303442
betas: OnyxEntry<Beta[]>,
3431-
prevNotificationPreference?: NotificationPreference,
3432-
// TODO: personalDetails should be a required field in follow-up PRs https://github.com/Expensify/App/issues/73656
3433-
personalDetails?: OnyxEntry<PersonalDetailsList>,
3443+
prevNotificationPreference: NotificationPreference | undefined,
3444+
personalDetails: OnyxEntry<PersonalDetailsList>,
34343445
) {
34353446
if (childReportID) {
34363447
openReport({reportID: childReportID, introSelected, betas, isSelfTourViewed});
@@ -3474,8 +3485,7 @@ function toggleSubscribeToChildReport(
34743485
reportID: newChat.reportID,
34753486
introSelected,
34763487
participants,
3477-
// TODO: allPersonalDetails fallback should be removed in follow-up PRs https://github.com/Expensify/App/issues/73656
3478-
personalDetails: personalDetails ?? allPersonalDetails,
3488+
personalDetails,
34793489
newReportObject: newChat,
34803490
parentReportActionID: parentReportAction.reportActionID,
34813491
isSelfTourViewed,
@@ -4362,26 +4372,29 @@ function deleteReport(reportID: string | undefined, shouldDeleteChildReports = f
43624372
/**
43634373
* @param reportID The reportID of the policy report (workspace room)
43644374
*/
4375+
// eslint-disable-next-line @typescript-eslint/max-params
43654376
function navigateToConciergeChatAndDeleteReport(
43664377
reportID: string | undefined,
43674378
conciergeReportID: string | undefined,
43684379
currentUserAccountID: number,
43694380
introSelected: OnyxEntry<IntroSelected>,
43704381
isSelfTourViewed: boolean | undefined,
43714382
betas: OnyxEntry<Beta[]>,
4383+
reportOwnerPersonalDetail: OnyxEntry<PersonalDetails>,
4384+
currentUserPersonalDetail: OnyxEntry<PersonalDetails>,
4385+
conciergePersonalDetail: OnyxEntry<PersonalDetails>,
43724386
shouldPopToTop = false,
43734387
shouldDeleteChildReports = false,
4374-
// TODO: personalDetails should be a required field in follow-up PRs https://github.com/Expensify/App/issues/73656
4375-
personalDetails?: OnyxEntry<PersonalDetailsList>,
43764388
) {
43774389
// Dismiss the current report screen and replace it with Concierge Chat
43784390
if (shouldPopToTop) {
43794391
Navigation.popToSidebar();
43804392
} else {
43814393
Navigation.goBack();
43824394
}
4383-
// TODO: allPersonalDetails fallback should be removed in follow-up PRs https://github.com/Expensify/App/issues/73656
4384-
navigateToConciergeChat(conciergeReportID, introSelected, currentUserAccountID, isSelfTourViewed, betas, false, undefined, undefined, undefined, personalDetails ?? allPersonalDetails);
4395+
const personalDetails = buildPersonalDetailsList([reportOwnerPersonalDetail, currentUserPersonalDetail, conciergePersonalDetail]);
4396+
navigateToConciergeChat(conciergeReportID, introSelected, currentUserAccountID, isSelfTourViewed, betas, false, undefined, undefined, undefined, personalDetails);
4397+
// eslint-disable-next-line @typescript-eslint/no-deprecated
43854398
InteractionManager.runAfterInteractions(() => {
43864399
deleteReport(reportID, shouldDeleteChildReports);
43874400
});
@@ -4394,6 +4407,9 @@ function clearCreateChatError(
43944407
currentUserAccountID: number,
43954408
betas: OnyxEntry<Beta[]>,
43964409
isSelfTourViewed: boolean | undefined,
4410+
reportOwnerPersonalDetail: OnyxEntry<PersonalDetails>,
4411+
currentUserPersonalDetail: OnyxEntry<PersonalDetails>,
4412+
conciergePersonalDetail: OnyxEntry<PersonalDetails>,
43974413
) {
43984414
const metaData = getReportMetadata(report?.reportID);
43994415
const isOptimisticReport = metaData?.isOptimisticReport;
@@ -4402,7 +4418,19 @@ function clearCreateChatError(
44024418
return;
44034419
}
44044420

4405-
navigateToConciergeChatAndDeleteReport(report?.reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, betas, undefined, true);
4421+
navigateToConciergeChatAndDeleteReport(
4422+
report?.reportID,
4423+
conciergeReportID,
4424+
currentUserAccountID,
4425+
introSelected,
4426+
isSelfTourViewed,
4427+
betas,
4428+
reportOwnerPersonalDetail,
4429+
currentUserPersonalDetail,
4430+
conciergePersonalDetail,
4431+
undefined,
4432+
true,
4433+
);
44064434
}
44074435

44084436
/**

src/libs/actions/Task.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import ROUTES from '@src/ROUTES';
2626
import type {Route} from '@src/ROUTES';
2727
import type * as OnyxTypes from '@src/types/onyx';
2828
import type {Icon} from '@src/types/onyx/OnyxCommon';
29+
import type PersonalDetails from '@src/types/onyx/PersonalDetails';
2930
import type {ReportActions} from '@src/types/onyx/ReportAction';
3031
import type ReportAction from '@src/types/onyx/ReportAction';
3132
import type {OnyxData} from '@src/types/onyx/Request';
@@ -1432,6 +1433,9 @@ function clearTaskErrors(
14321433
introSelected: OnyxEntry<OnyxTypes.IntroSelected>,
14331434
betas: OnyxEntry<OnyxTypes.Beta[]>,
14341435
isSelfTourViewed: boolean | undefined,
1436+
reportOwnerPersonalDetail: OnyxEntry<PersonalDetails>,
1437+
currentUserPersonalDetail: OnyxEntry<PersonalDetails>,
1438+
conciergePersonalDetail: OnyxEntry<PersonalDetails>,
14351439
) {
14361440
const reportID = report?.reportID;
14371441
if (!reportID) {
@@ -1442,7 +1446,19 @@ function clearTaskErrors(
14421446
if (report?.pendingFields?.createChat === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
14431447
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, report.parentReportActionID ? {[report.parentReportActionID]: null} : {});
14441448

1445-
navigateToConciergeChatAndDeleteReport(reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, betas);
1449+
navigateToConciergeChatAndDeleteReport(
1450+
reportID,
1451+
conciergeReportID,
1452+
currentUserAccountID,
1453+
introSelected,
1454+
isSelfTourViewed,
1455+
betas,
1456+
reportOwnerPersonalDetail,
1457+
currentUserPersonalDetail,
1458+
conciergePersonalDetail,
1459+
undefined,
1460+
undefined,
1461+
);
14461462
return;
14471463
}
14481464

src/pages/Debug/Report/DebugReportPage.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {hasSeenTourSelector} from '@selectors/Onboarding';
2+
import {conciergePersonalDetailSelector, personalDetailByAccountIDSelector} from '@selectors/PersonalDetails';
23
import React, {useCallback, useMemo} from 'react';
34
import {View} from 'react-native';
45
import type {OnyxEntry} from 'react-native-onyx';
@@ -76,7 +77,11 @@ function DebugReportPage({
7677
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
7778
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
7879
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
79-
const {accountID: currentUserAccountID, login: currentUserLogin} = useCurrentUserPersonalDetails();
80+
const currentUserPersonalDetail = useCurrentUserPersonalDetails();
81+
const {accountID: currentUserAccountID, login: currentUserLogin} = currentUserPersonalDetail;
82+
const [conciergePersonalDetail] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: conciergePersonalDetailSelector});
83+
const reportOwnerSelector = useMemo(() => personalDetailByAccountIDSelector(report?.ownerAccountID), [report?.ownerAccountID]);
84+
const [reportOwnerPersonalDetail] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: reportOwnerSelector}, [reportOwnerSelector]);
8085
const transactionID = DebugUtils.getTransactionID(report, reportActions);
8186
const isReportArchived = useReportIsArchived(reportID);
8287

@@ -185,7 +190,19 @@ function DebugReportPage({
185190
Debug.setDebugData(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, data);
186191
}}
187192
onDelete={() => {
188-
navigateToConciergeChatAndDeleteReport(reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, betas, true, true);
193+
navigateToConciergeChatAndDeleteReport(
194+
reportID,
195+
conciergeReportID,
196+
currentUserAccountID,
197+
introSelected,
198+
isSelfTourViewed,
199+
betas,
200+
reportOwnerPersonalDetail,
201+
currentUserPersonalDetail,
202+
conciergePersonalDetail,
203+
true,
204+
true,
205+
);
189206
}}
190207
validate={DebugUtils.validateReportDraftProperty}
191208
>
@@ -251,6 +268,9 @@ function DebugReportPage({
251268
introSelected,
252269
isSelfTourViewed,
253270
betas,
271+
reportOwnerPersonalDetail,
272+
currentUserPersonalDetail,
273+
conciergePersonalDetail,
254274
],
255275
);
256276

src/pages/inbox/report/ContextMenu/BaseReportActionContextMenu.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CompactMenuContext from '@components/CompactMenuContext';
1212
import ContextMenuItem from '@components/ContextMenuItem';
1313
import {useDelegateNoAccessActions, useDelegateNoAccessState} from '@components/DelegateNoAccessModalProvider';
1414
import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal';
15-
import {useSession} from '@components/OnyxListItemProvider';
15+
import {usePersonalDetails, useSession} from '@components/OnyxListItemProvider';
1616
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
1717
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
1818
import useDelegateAccountID from '@hooks/useDelegateAccountID';
@@ -245,6 +245,7 @@ function BaseReportActionContextMenu({
245245
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
246246
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
247247
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
248+
const personalDetails = usePersonalDetails();
248249
const reportAttributes = useReportAttributes();
249250
const delegateAccountID = useDelegateAccountID();
250251

@@ -395,6 +396,7 @@ function BaseReportActionContextMenu({
395396
interceptAnonymousUser,
396397
openOverflowMenu,
397398
setIsEmojiPickerActive,
399+
personalDetails,
398400
isHarvestReport,
399401
moneyRequestAction,
400402
card,

0 commit comments

Comments
 (0)