Skip to content

Commit ca2cdf6

Browse files
authored
Merge pull request Expensify#86826 from dukenv0307/fix/66411-part-17
refactor getReportPreviewMessage to use conciergeReportID from useOnyx
2 parents 5c3eebb + 1381dd8 commit ca2cdf6

12 files changed

Lines changed: 170 additions & 21 deletions

File tree

src/components/KYCWall/BaseKYCWall.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function KYCWall({
6565
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
6666
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
6767
const [betas] = useOnyx(ONYXKEYS.BETAS);
68+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
6869

6970
const {formatPhoneNumber} = useLocalize();
7071
const currentUserDetails = useCurrentUserPersonalDetails();
@@ -165,7 +166,7 @@ function KYCWall({
165166
}
166167

167168
const {policyID, workspaceChatReportID, reportPreviewReportActionID, adminsChatReportID} =
168-
createWorkspaceFromIOUPayment(iouReport, reportPreviewAction, currentUserEmail, employeeEmail) ?? {};
169+
createWorkspaceFromIOUPayment(iouReport, reportPreviewAction, currentUserEmail, employeeEmail, conciergeReportID) ?? {};
169170
if (policyID && iouReport?.policyID) {
170171
savePreferredPaymentMethod(iouReport.policyID, policyID, CONST.LAST_PAYMENT_METHOD.IOU, lastPaymentMethod?.[iouReport?.policyID]);
171172
}
@@ -216,6 +217,7 @@ function KYCWall({
216217
lastPaymentMethod,
217218
isSelfTourViewed,
218219
betas,
220+
conciergeReportID,
219221
],
220222
);
221223

src/libs/OptionsListUtils/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ function getLastMessageTextForReport({
698698
}
699699
}
700700
} else if (isMoneyRequestAction(lastReportAction)) {
701-
const properSchemaForMoneyRequestMessage = getReportPreviewMessage(report, lastReportAction, true, false, null, true);
701+
const properSchemaForMoneyRequestMessage = getReportPreviewMessage(report, conciergeReportID, lastReportAction, true, false, null, true);
702702
lastMessageTextFromReport = formatReportLastMessageText(Parser.htmlToText(properSchemaForMoneyRequestMessage));
703703
} else if (isReportPreviewAction(lastReportAction)) {
704704
const iouReport = getReportOrDraftReport(getIOUReportIDFromReportActionPreview(lastReportAction));
@@ -725,6 +725,7 @@ function getLastMessageTextForReport({
725725
} else {
726726
const reportPreviewMessage = getReportPreviewMessage(
727727
!isEmptyObject(iouReport) ? iouReport : null,
728+
conciergeReportID,
728729
lastIOUMoneyReportAction ?? lastReportAction,
729730
true,
730731
reportUtilsIsChatReport(report),
@@ -852,7 +853,7 @@ function getLastMessageTextForReport({
852853
} else if (isMovedAction(lastReportAction)) {
853854
lastMessageTextFromReport = Parser.htmlToText(getMovedActionMessage(translate, lastReportAction, report));
854855
} else if (isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.UNREPORTED_TRANSACTION)) {
855-
lastMessageTextFromReport = Parser.htmlToText(getUnreportedTransactionMessage(translate, lastReportAction));
856+
lastMessageTextFromReport = Parser.htmlToText(getUnreportedTransactionMessage(translate, lastReportAction, conciergeReportID));
856857
} else if (isActionableMentionWhisper(lastReportAction)) {
857858
lastMessageTextFromReport = Parser.htmlToText(getActionableMentionWhisperMessage(translate, lastReportAction));
858859
} else if (isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.DYNAMIC_EXTERNAL_WORKFLOW_ROUTED)) {

src/libs/ReportNameUtils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ type ComputeReportName = {
165165
reportActions?: OnyxCollection<ReportActions>;
166166
currentUserAccountID?: number;
167167
currentUserLogin: string;
168+
// TODO: Make this required when https://github.com/Expensify/App/issues/66411 is done
169+
conciergeReportID?: string;
168170
};
169171

170172
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
@@ -413,6 +415,8 @@ function computeReportNameBasedOnReportAction(
413415
report: Report | undefined,
414416
reportPolicy: Policy | undefined,
415417
parentReport: Report | undefined,
418+
// TODO: Make this required when https://github.com/Expensify/App/issues/66411 is done
419+
conciergeReportID?: string,
416420
): string | undefined {
417421
if (!parentReportAction) {
418422
return undefined;
@@ -492,7 +496,7 @@ function computeReportNameBasedOnReportAction(
492496
}
493497

494498
if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.UNREPORTED_TRANSACTION)) {
495-
return Parser.htmlToText(getUnreportedTransactionMessage(translate, parentReportAction));
499+
return Parser.htmlToText(getUnreportedTransactionMessage(translate, parentReportAction, conciergeReportID));
496500
}
497501

498502
if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION)) {
@@ -831,6 +835,7 @@ function computeReportName({
831835
currentUserAccountID,
832836
currentUserLogin,
833837
allPolicyTags,
838+
conciergeReportID,
834839
}: ComputeReportName): string {
835840
if (!report || !report.reportID) {
836841
return '';
@@ -841,7 +846,7 @@ function computeReportName({
841846
const parentReportAction = isThread(report) ? reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report.parentReportActionID] : undefined;
842847

843848
// eslint-disable-next-line @typescript-eslint/no-deprecated
844-
const parentReportActionBasedName = computeReportNameBasedOnReportAction(translateLocal, parentReportAction, report, reportPolicy, parentReport);
849+
const parentReportActionBasedName = computeReportNameBasedOnReportAction(translateLocal, parentReportAction, report, reportPolicy, parentReport, conciergeReportID);
845850

846851
if (parentReportActionBasedName) {
847852
return parentReportActionBasedName;
@@ -864,6 +869,7 @@ function computeReportName({
864869
reportActions,
865870
currentUserAccountID,
866871
currentUserLogin,
872+
conciergeReportID,
867873
});
868874
// eslint-disable-next-line @typescript-eslint/no-deprecated
869875
return getCreatedReportForUnapprovedTransactionsMessage(originalID, reportName, isOriginalReportDeleted(parentReportAction, originalReport), translateLocal);

src/libs/ReportUtils.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5346,6 +5346,7 @@ function getTransactionReportName({
53465346
*/
53475347
function getReportPreviewMessage(
53485348
reportOrID: OnyxInputOrEntry<Report> | string,
5349+
conciergeReportID: string | undefined,
53495350
iouReportAction: OnyxInputOrEntry<ReportAction> = null,
53505351
shouldConsiderScanningReceiptOrPendingRoute = false,
53515352
isPreviewMessageForParentChatReport = false,
@@ -5358,7 +5359,7 @@ function getReportPreviewMessage(
53585359
const reportActionMessage = getReportActionHtml(iouReportAction);
53595360
if (isCopyAction) {
53605361
if (report) {
5361-
return computeReportName({report, currentUserLogin: ''}) || (originalReportAction?.childReportName ?? '');
5362+
return computeReportName({report, currentUserLogin: '', conciergeReportID}) || (originalReportAction?.childReportName ?? '');
53625363
}
53635364
return originalReportAction?.childReportName ?? '';
53645365
}
@@ -5880,7 +5881,7 @@ function getReportName(reportNameInformation: GetReportNameParams): string {
58805881
const reportPolicy = policy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];
58815882

58825883
// eslint-disable-next-line @typescript-eslint/no-deprecated
5883-
const parentReportActionBasedName = computeReportNameBasedOnReportAction(translateLocal, parentReportAction, report, reportPolicy, parentReport);
5884+
const parentReportActionBasedName = computeReportNameBasedOnReportAction(translateLocal, parentReportAction, report, reportPolicy, parentReport, conciergeReportID);
58845885

58855886
if (parentReportActionBasedName) {
58865887
return parentReportActionBasedName;
@@ -7057,15 +7058,20 @@ function getMovedTransactionMessage(translate: LocalizedTranslate, action: Repor
70577058
return translate('iou.movedTransactionFrom', reportUrl, reportName);
70587059
}
70597060

7060-
function getUnreportedTransactionMessage(translate: LocalizedTranslate, action: ReportAction) {
7061+
function getUnreportedTransactionMessage(
7062+
translate: LocalizedTranslate,
7063+
action: ReportAction,
7064+
// TODO: Make this required when https://github.com/Expensify/App/issues/66411 is done
7065+
conciergeReportID?: string,
7066+
) {
70617067
const movedTransactionOriginalMessage = getOriginalMessage(action) ?? {};
70627068
const {fromReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;
70637069

70647070
const fromReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${fromReportID}`];
70657071

70667072
// This will be fixed as follow up https://github.com/Expensify/App/pull/75357
70677073
// eslint-disable-next-line @typescript-eslint/no-deprecated
7068-
const reportName = Parser.htmlToText(getReportName({report: fromReport}) ?? fromReport?.reportName ?? '');
7074+
const reportName = Parser.htmlToText(getReportName({report: fromReport, conciergeReportID}) ?? fromReport?.reportName ?? '');
70697075

70707076
let reportUrl = getReportURLForCurrentContext(fromReportID);
70717077

@@ -7643,7 +7649,8 @@ function buildOptimisticReportPreview(
76437649
reportActionID?: string,
76447650
): ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW> {
76457651
const hasReceipt = hasReceiptTransactionUtils(transaction);
7646-
const message = getReportPreviewMessage(iouReport);
7652+
// TODO: We'll pass the conciergeReportID in the next PR. Ref: https://github.com/Expensify/App/issues/66411
7653+
const message = getReportPreviewMessage(iouReport, undefined);
76477654
const created = DateUtils.getDBTime();
76487655
const reportActorAccountID = (isInvoiceReport(iouReport) || isExpenseReport(iouReport) ? iouReport?.ownerAccountID : iouReport?.managerID) ?? -1;
76497656
const delegateAccountDetails = getPersonalDetailByEmail(delegateEmail);
@@ -7832,7 +7839,8 @@ function updateReportPreview(
78327839
}
78337840
}
78347841

7835-
const message = getReportPreviewMessage(iouReport, reportPreviewAction);
7842+
// TODO: We'll pass the conciergeReportID in the next PR. Ref: https://github.com/Expensify/App/issues/66411
7843+
const message = getReportPreviewMessage(iouReport, undefined, reportPreviewAction);
78367844
const originalMessage = getOriginalMessage(reportPreviewAction);
78377845
return {
78387846
...reportPreviewAction,

src/libs/actions/Policy/Policy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3910,6 +3910,7 @@ function createWorkspaceFromIOUPayment(
39103910
reportPreviewAction: ReportAction | undefined,
39113911
currentUserEmail: string,
39123912
iouReportOwnerEmail: string,
3913+
conciergeReportID: string | undefined,
39133914
): WorkspaceFromIOUCreationData | undefined {
39143915
// This flow only works for IOU reports
39153916
if (!iouReport || !ReportUtils.isIOUReportUsingReport(iouReport)) {
@@ -4286,7 +4287,7 @@ function createWorkspaceFromIOUPayment(
42864287
message: [
42874288
{
42884289
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
4289-
text: ReportUtils.getReportPreviewMessage(expenseReport, null, false, false, newWorkspace),
4290+
text: ReportUtils.getReportPreviewMessage(expenseReport, conciergeReportID, null, false, false, newWorkspace),
42904291
},
42914292
],
42924293
created: DateUtils.getDBTime(),

src/libs/actions/Report/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3483,7 +3483,8 @@ function buildNewReportOptimisticData(
34833483
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
34843484
};
34853485

3486-
const message = getReportPreviewMessage(optimisticReportData);
3486+
// TODO: We'll pass the conciergeReportID in the next PR. Ref: https://github.com/Expensify/App/issues/66411
3487+
const message = getReportPreviewMessage(optimisticReportData, undefined);
34873488
const createReportActionMessage = [
34883489
{
34893490
html: message,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ function BaseReportActionContextMenu({
243243
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
244244
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
245245
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
246+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
246247

247248
const isTryNewDotNVPDismissed = !!tryNewDot?.classicRedirect?.dismissed;
248249
const session = useSession();
@@ -414,6 +415,7 @@ function BaseReportActionContextMenu({
414415
iouTransaction,
415416
bankAccountList,
416417
isOffline,
418+
conciergeReportID,
417419
};
418420

419421
if ('renderContent' in contextAction) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ type ContextMenuActionPayload = {
306306
iouTransaction: OnyxEntry<Transaction>;
307307
bankAccountList: OnyxEntry<BankAccountList>;
308308
isOffline: boolean;
309+
conciergeReportID: string | undefined;
309310
};
310311

311312
type OnPress = (closePopover: boolean, payload: ContextMenuActionPayload, selection?: string, reportID?: string, draftMessage?: string) => void;
@@ -806,6 +807,7 @@ const ContextMenuActions: ContextMenuAction[] = [
806807
harvestReport,
807808
currentUserPersonalDetails,
808809
bankAccountList,
810+
conciergeReportID,
809811
},
810812
) => {
811813
const isReportPreviewAction = isReportPreviewActionReportActionsUtils(reportAction);
@@ -817,7 +819,7 @@ const ContextMenuActions: ContextMenuAction[] = [
817819
const content = selection || messageHtml;
818820
if (isReportPreviewAction) {
819821
const iouReportID = getIOUReportIDFromReportActionPreview(reportAction);
820-
const displayMessage = getReportPreviewMessage(iouReportID, reportAction, undefined, undefined, undefined, undefined, undefined, true);
822+
const displayMessage = getReportPreviewMessage(iouReportID, conciergeReportID, reportAction, undefined, undefined, undefined, undefined, undefined, true);
821823
Clipboard.setString(displayMessage);
822824
} else if (isTaskActionReportActionsUtils(reportAction)) {
823825
const {text, html} = getTaskReportActionMessage(translate, reportAction);

tests/perf-test/ReportUtils.perf-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe('ReportUtils', () => {
147147
const isPreviewMessageForParentChatReport = true;
148148

149149
await waitForBatchedUpdates();
150-
await measureFunction(() => getReportPreviewMessage(report, reportAction, shouldConsiderReceiptBeingScanned, isPreviewMessageForParentChatReport, policy));
150+
await measureFunction(() => getReportPreviewMessage(report, undefined, reportAction, shouldConsiderReceiptBeingScanned, isPreviewMessageForParentChatReport, policy));
151151
});
152152

153153
test('[ReportUtils] getReportName on 1k participants', async () => {

tests/unit/OptionsListUtilsTest.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4053,7 +4053,7 @@ describe('OptionsListUtils', () => {
40534053
[iouAction.reportActionID]: iouAction,
40544054
});
40554055
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction);
4056-
const reportPreviewMessage = getReportPreviewMessage(iouReport, iouAction, true, false, null, true, reportPreviewAction);
4056+
const reportPreviewMessage = getReportPreviewMessage(iouReport, undefined, iouAction, true, false, null, true, reportPreviewAction);
40574057
const formattedMessage = formatReportLastMessageText(Parser.htmlToText(reportPreviewMessage));
40584058
expect(formattedMessage).toBe('$1.00 for A A A');
40594059
});

0 commit comments

Comments
 (0)