Skip to content

Commit 1fc9287

Browse files
committed
Replace getPersonalDetailByEmail with usePersonalDetailByLogin for join request and modified expense actions
1 parent c7d582e commit 1fc9287

13 files changed

Lines changed: 158 additions & 42 deletions

File tree

src/libs/ModifiedExpenseMessage.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import DateUtils from './DateUtils';
1818
import {getEnvironmentURL} from './Environment/Environment';
1919
import {formatList} from './Localize';
2020
import Log from './Log';
21-
import {getPersonalDetailByEmail} from './PersonalDetailsUtils';
2221
import {
2322
arePolicyRulesEnabled,
2423
findVendorByID,
@@ -153,7 +152,7 @@ function getForDistanceRequest(translate: LocalizedTranslate, newMerchant: strin
153152
return translate('iou.updatedTheDistanceMerchant', translatedChangedField, newMerchant, oldMerchant, newAmount, oldAmount);
154153
}
155154

156-
function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destinationReport: OnyxEntry<Report>, currentUserLogin: string, policy: OnyxEntry<Policy>) {
155+
function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destinationReport: OnyxEntry<Report>, currentUserAccountID: number | undefined, policy: OnyxEntry<Policy>) {
157156
const rootParentReport = getRootParentReport({report: destinationReport});
158157
// In OldDot, expenses could be moved to a self-DM. Return the corresponding message for this case.
159158
if (isSelfDM(rootParentReport)) {
@@ -162,7 +161,6 @@ function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destination
162161
// In NewDot, the "Move report" flow only supports moving expenses from self-DM to:
163162
// - A policy expense chat
164163
// - A 1:1 DM
165-
const currentUserAccountID = getPersonalDetailByEmail(currentUserLogin)?.accountID;
166164
const reportName = isPolicyExpenseChat(rootParentReport)
167165
? getPolicyExpenseChatName({report: rootParentReport, translate})
168166
: buildReportNameFromParticipantNames({report: rootParentReport, currentUserAccountID, translate});
@@ -187,12 +185,12 @@ function getMovedFromOrToReportMessage(
187185
translate: LocalizedTranslate,
188186
movedFromReport: OnyxEntry<Report> | undefined,
189187
movedToReport: OnyxEntry<Report> | undefined,
190-
currentUserLogin: string,
188+
currentUserAccountID: number | undefined,
191189
policy: OnyxEntry<Policy>,
192190
reportAttributes?: ReportAttributesDerivedValue['reports'],
193191
): string | undefined {
194192
if (movedToReport) {
195-
return getForExpenseMovedFromSelfDM(translate, movedToReport, currentUserLogin, policy);
193+
return getForExpenseMovedFromSelfDM(translate, movedToReport, currentUserAccountID, policy);
196194
}
197195

198196
if (movedFromReport) {
@@ -276,6 +274,7 @@ function getForReportAction({
276274
movedToReport,
277275
policyTags,
278276
policyCategories,
277+
currentUserAccountID,
279278
currentUserLogin,
280279
reportAttributes,
281280
}: {
@@ -290,14 +289,15 @@ function getForReportAction({
290289
// See https://github.com/Expensify/App/pull/75562
291290
policyTags?: OnyxEntry<PolicyTagLists>;
292291
policyCategories?: OnyxEntry<PolicyCategories>;
292+
currentUserAccountID: number | undefined;
293293
currentUserLogin: string;
294294
reportAttributes?: ReportAttributesDerivedValue['reports'];
295295
}): string {
296296
if (!isModifiedExpenseAction(reportAction)) {
297297
return '';
298298
}
299299

300-
const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translate, movedFromReport, movedToReport, currentUserLogin, policy, reportAttributes);
300+
const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translate, movedFromReport, movedToReport, currentUserAccountID, policy, reportAttributes);
301301
if (movedFromOrToReportMessage) {
302302
return movedFromOrToReportMessage;
303303
}

src/libs/Notification/LocalNotification/BrowserNotifications.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export default {
159159
usesIcon = false,
160160
policyTags,
161161
policy,
162+
currentUserAccountID,
162163
currentUserLogin,
163164
reportAttributes,
164165
}: LocalNotificationModifiedExpensePushParams) {
@@ -172,6 +173,7 @@ export default {
172173
movedFromReport,
173174
movedToReport,
174175
policyTags,
176+
currentUserAccountID,
175177
currentUserLogin,
176178
reportAttributes,
177179
});

src/libs/Notification/LocalNotification/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ function showUpdateAvailableNotification() {
3737
BrowserNotifications.pushUpdateAvailableNotification();
3838
}
3939

40-
function showModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, currentUserLogin, reportAttributes}: LocalNotificationModifiedExpenseParams) {
40+
function showModifiedExpenseNotification({
41+
report,
42+
reportAction,
43+
movedFromReport,
44+
movedToReport,
45+
onClick,
46+
currentUserAccountID,
47+
currentUserLogin,
48+
reportAttributes,
49+
}: LocalNotificationModifiedExpenseParams) {
4150
const policyID = report.policyID;
4251
const policyTags = policyID ? allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] : undefined;
4352
const policy = policyID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] : undefined;
@@ -50,6 +59,7 @@ function showModifiedExpenseNotification({report, reportAction, movedFromReport,
5059
usesIcon: true,
5160
policyTags,
5261
policy,
62+
currentUserAccountID,
5363
currentUserLogin,
5464
reportAttributes,
5565
});

src/libs/Notification/LocalNotification/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type LocalNotificationModifiedExpenseParams = {
2323
onClick: LocalNotificationClickHandler;
2424
movedFromReport?: OnyxEntry<Report>;
2525
movedToReport?: OnyxEntry<Report>;
26+
currentUserAccountID: number | undefined;
2627
currentUserLogin: string;
2728
reportAttributes?: ReportAttributesDerivedValue['reports'];
2829
};

src/libs/OptionsListUtils/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Navigation from '@libs/Navigation/Navigation';
2121
import {getIsOffline} from '@libs/NetworkState';
2222
import Parser from '@libs/Parser';
2323
import type {OptionData as PersonalDetailOptionData} from '@libs/PersonalDetailOptionsListUtils/types';
24-
import {getLoginByAccountID, getPersonalDetailsListByIDs, temporaryGetDisplayNameOrDefault} from '@libs/PersonalDetailsUtils';
24+
import {getLoginByAccountID, getPersonalDetailsByID, getPersonalDetailsListByIDs, temporaryGetDisplayNameOrDefault} from '@libs/PersonalDetailsUtils';
2525
import {addSMSDomainIfPhoneNumber, parsePhoneNumber} from '@libs/PhoneNumber';
2626
import {
2727
canSendInvoiceFromWorkspace,
@@ -825,6 +825,7 @@ function getLastMessageTextForReport({
825825
movedFromReport,
826826
movedToReport,
827827
policyTags,
828+
currentUserAccountID,
828829
currentUserLogin: currentUserLogin ?? '',
829830
});
830831
// Strip HTML tags for plain text display in options list
@@ -901,7 +902,12 @@ function getLastMessageTextForReport({
901902
} else if (lastReportAction?.actionName && isOldDotReportAction(lastReportAction)) {
902903
lastMessageTextFromReport = getMessageOfOldDotReportAction(translate, lastReportAction, false);
903904
} else if (isActionableJoinRequest(lastReportAction)) {
904-
lastMessageTextFromReport = getJoinRequestMessage(translate, policy, lastReportAction);
905+
lastMessageTextFromReport = getJoinRequestMessage(
906+
translate,
907+
policy?.name ?? '',
908+
lastReportAction,
909+
getPersonalDetailsByID(getOriginalMessage(lastReportAction)?.accountID, personalDetails),
910+
);
905911
} else if (
906912
lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.LEAVE_ROOM ||
907913
lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.LEAVE_ROOM

src/libs/ReportActionsUtils.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4680,11 +4680,16 @@ function shouldShowActivateCard(actionName?: ReportActionName, card?: Card, priv
46804680
return (actionName === CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED || actionName === CONST.REPORT.ACTIONS.TYPE.CARD_REPLACED) && isCardPendingActivate(card) && !missingDetails;
46814681
}
46824682

4683-
function getJoinRequestMessage(translate: LocalizedTranslate, policy: OnyxEntry<Policy>, reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_JOIN_REQUEST>) {
4684-
const userDetail = getPersonalDetailByEmail(getOriginalMessage(reportAction)?.email ?? '');
4683+
function getJoinRequestMessage(
4684+
translate: LocalizedTranslate,
4685+
policyName: string,
4686+
reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_JOIN_REQUEST>,
4687+
userDetail: OnyxEntry<PersonalDetails>,
4688+
) {
46854689
const userName = userDetail?.firstName ? `${userDetail.displayName} (${userDetail.login})` : (userDetail?.login ?? getOriginalMessage(reportAction)?.email);
4686-
return translate('workspace.inviteMessage.joinRequest', {user: userName ?? '', workspaceName: policy?.name ?? ''});
4690+
return translate('workspace.inviteMessage.joinRequest', {user: userName ?? '', workspaceName: policyName});
46874691
}
4692+
46884693
function isCardActive(card?: Card): boolean {
46894694
if (!card) {
46904695
return false;

src/libs/ReportNameUtils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {translateLocal} from './Localize';
3333
import {getForReportAction, getMovedReportID} from './ModifiedExpenseMessage';
3434
import {getCurrentUserEmail} from './Network/NetworkStore';
3535
import Parser from './Parser';
36-
import {temporaryGetDisplayNameOrDefault} from './PersonalDetailsUtils';
36+
import {getPersonalDetailsByID, temporaryGetDisplayNameOrDefault} from './PersonalDetailsUtils';
3737
import {getCleanedTagName, isPolicyAdmin, isPolicyFieldListEmpty} from './PolicyUtils';
3838
import {
3939
getActionableCard3DSTransactionApprovalMessage,
@@ -825,7 +825,7 @@ function computeReportNameBasedOnReportAction({
825825
}
826826

827827
if (isActionableJoinRequest(parentReportAction)) {
828-
return getJoinRequestMessage(translate, reportPolicy, parentReportAction);
828+
return getJoinRequestMessage(translate, reportPolicy?.name ?? '', parentReportAction, getPersonalDetailsByID(getOriginalMessage(parentReportAction)?.accountID, personalDetailsList));
829829
}
830830

831831
if (isTaskReport(report) && isCanceledTaskReport(report, parentReportAction)) {
@@ -945,6 +945,7 @@ function computeChatThreadReportName(
945945
isArchived: boolean,
946946
report: Report,
947947
reports: OnyxCollection<Report>,
948+
currentUserAccountID: number | undefined,
948949
currentUserLogin: string,
949950
transactions: OnyxCollection<Transaction>,
950951
parentReportAction?: ReportAction,
@@ -1015,6 +1016,7 @@ function computeChatThreadReportName(
10151016
movedToReport,
10161017
policyTags,
10171018
policy,
1019+
currentUserAccountID,
10181020
currentUserLogin,
10191021
});
10201022
// Strip HTML tags for plain text display in report previews
@@ -1119,6 +1121,7 @@ function computeReportName({
11191121
privateIsArchivedValue,
11201122
report,
11211123
reports ?? {},
1124+
currentUserAccountID,
11221125
currentUserLogin ?? '',
11231126
transactions,
11241127
parentReportAction,

src/libs/actions/Report/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4986,7 +4986,7 @@ function showReportActionNotification(
49864986
if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE) {
49874987
const movedFromReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(reportAction, CONST.REPORT.MOVE_TYPE.FROM)}`];
49884988
const movedToReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(reportAction, CONST.REPORT.MOVE_TYPE.TO)}`];
4989-
LocalNotification.showModifiedExpenseNotification({report, reportAction, onClick, movedFromReport, movedToReport, currentUserLogin, reportAttributes});
4989+
LocalNotification.showModifiedExpenseNotification({report, reportAction, onClick, movedFromReport, movedToReport, currentUserAccountID, currentUserLogin, reportAttributes});
49904990
} else {
49914991
LocalNotification.showCommentNotification(report, reportAction, onClick, reportAttributes);
49924992
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ const ContextMenuActions: ContextMenuAction[] = [
10241024
movedFromReport,
10251025
movedToReport,
10261026
policyTags,
1027+
currentUserAccountID,
10271028
currentUserLogin: currentUserPersonalDetails?.email ?? '',
10281029
});
10291030
// Convert HTML to markdown for clipboard copy to preserve links and formatting
@@ -1379,7 +1380,12 @@ const ContextMenuActions: ContextMenuAction[] = [
13791380
const displayMessage = getPolicyChangeMessage(translate, reportAction);
13801381
Clipboard.setString(displayMessage);
13811382
} else if (isActionableJoinRequest(reportAction)) {
1382-
const displayMessage = getJoinRequestMessage(translate, policy, reportAction);
1383+
const displayMessage = getJoinRequestMessage(
1384+
translate,
1385+
policy?.name ?? '',
1386+
reportAction,
1387+
getPersonalDetailsByID(getOriginalMessage(reportAction)?.accountID, personalDetails),
1388+
);
13831389
Clipboard.setString(displayMessage);
13841390
} else if (
13851391
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.LEAVE_ROOM ||

src/pages/inbox/report/actionContents/JoinRequestContent.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {acceptJoinRequest, declineJoinRequest} from '@userActions/Policy/Member'
1212

1313
import CONST from '@src/CONST';
1414
import ONYXKEYS from '@src/ONYXKEYS';
15+
import {personalDetailsSelector} from '@src/selectors/PersonalDetails';
16+
import {policyNameSelector} from '@src/selectors/Policy';
1517
import type {ReportAction} from '@src/types/onyx';
1618
import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage';
1719

@@ -26,13 +28,16 @@ type JoinRequestContentProps = {
2628

2729
function JoinRequestContent({action, actionOwnerReportID, policyID}: JoinRequestContentProps) {
2830
const {translate} = useLocalize();
29-
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
31+
const [policyName = ''] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {selector: policyNameSelector});
3032

31-
const isJoinRequestUnresolved = getOriginalMessage(action)?.choice === ('' as JoinWorkspaceResolution);
33+
const originalMessage = getOriginalMessage(action);
34+
const [requesterDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsSelector(originalMessage?.accountID)});
35+
36+
const isJoinRequestUnresolved = originalMessage?.choice === ('' as JoinWorkspaceResolution);
3237

3338
return (
3439
<View>
35-
<ReportActionItemBasicMessage message={getJoinRequestMessage(translate, policy, action)} />
40+
<ReportActionItemBasicMessage message={getJoinRequestMessage(translate, policyName, action, requesterDetails)} />
3641
{isJoinRequestUnresolved && (
3742
<ActionableItemButtons layout="horizontal">
3843
<Button

0 commit comments

Comments
 (0)