Skip to content

Commit 89ce6eb

Browse files
committed
refactor getReportPreviewMessage to use conciergeReportID from useOnyx
1 parent 0a42bcf commit 89ce6eb

11 files changed

Lines changed: 89 additions & 20 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
@@ -5353,6 +5353,7 @@ function getTransactionReportName({
53535353
*/
53545354
function getReportPreviewMessage(
53555355
reportOrID: OnyxInputOrEntry<Report> | string,
5356+
conciergeReportID: string | undefined,
53565357
iouReportAction: OnyxInputOrEntry<ReportAction> = null,
53575358
shouldConsiderScanningReceiptOrPendingRoute = false,
53585359
isPreviewMessageForParentChatReport = false,
@@ -5365,7 +5366,7 @@ function getReportPreviewMessage(
53655366
const reportActionMessage = getReportActionHtml(iouReportAction);
53665367
if (isCopyAction) {
53675368
if (report) {
5368-
return computeReportName({report, currentUserLogin: ''}) || (originalReportAction?.childReportName ?? '');
5369+
return computeReportName({report, currentUserLogin: '', conciergeReportID}) || (originalReportAction?.childReportName ?? '');
53695370
}
53705371
return originalReportAction?.childReportName ?? '';
53715372
}
@@ -5887,7 +5888,7 @@ function getReportName(reportNameInformation: GetReportNameParams): string {
58875888
const reportPolicy = policy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];
58885889

58895890
// eslint-disable-next-line @typescript-eslint/no-deprecated
5890-
const parentReportActionBasedName = computeReportNameBasedOnReportAction(translateLocal, parentReportAction, report, reportPolicy, parentReport);
5891+
const parentReportActionBasedName = computeReportNameBasedOnReportAction(translateLocal, parentReportAction, report, reportPolicy, parentReport, conciergeReportID);
58915892

58925893
if (parentReportActionBasedName) {
58935894
return parentReportActionBasedName;
@@ -7063,15 +7064,20 @@ function getMovedTransactionMessage(translate: LocalizedTranslate, action: Repor
70637064
return translate('iou.movedTransactionFrom', reportUrl, reportName);
70647065
}
70657066

7066-
function getUnreportedTransactionMessage(translate: LocalizedTranslate, action: ReportAction) {
7067+
function getUnreportedTransactionMessage(
7068+
translate: LocalizedTranslate,
7069+
action: ReportAction,
7070+
// TODO: Make this required when https://github.com/Expensify/App/issues/66411 is done
7071+
conciergeReportID?: string,
7072+
) {
70677073
const movedTransactionOriginalMessage = getOriginalMessage(action) ?? {};
70687074
const {fromReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;
70697075

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

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

70767082
let reportUrl = getReportURLForCurrentContext(fromReportID);
70777083

@@ -7649,7 +7655,8 @@ function buildOptimisticReportPreview(
76497655
reportActionID?: string,
76507656
): ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW> {
76517657
const hasReceipt = hasReceiptTransactionUtils(transaction);
7652-
const message = getReportPreviewMessage(iouReport);
7658+
// TODO: We'll pass the conciergeReportID in the next PR. Ref: https://github.com/Expensify/App/issues/66411
7659+
const message = getReportPreviewMessage(iouReport, undefined);
76537660
const created = DateUtils.getDBTime();
76547661
const reportActorAccountID = (isInvoiceReport(iouReport) || isExpenseReport(iouReport) ? iouReport?.ownerAccountID : iouReport?.managerID) ?? -1;
76557662
const delegateAccountDetails = getPersonalDetailByEmail(delegateEmail);
@@ -7838,7 +7845,8 @@ function updateReportPreview(
78387845
}
78397846
}
78407847

7841-
const message = getReportPreviewMessage(iouReport, reportPreviewAction);
7848+
// TODO: We'll pass the conciergeReportID in the next PR. Ref: https://github.com/Expensify/App/issues/66411
7849+
const message = getReportPreviewMessage(iouReport, undefined, reportPreviewAction);
78427850
const originalMessage = getOriginalMessage(reportPreviewAction);
78437851
return {
78447852
...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
@@ -3484,7 +3484,8 @@ function buildNewReportOptimisticData(
34843484
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
34853485
};
34863486

3487-
const message = getReportPreviewMessage(optimisticReportData);
3487+
// TODO: We'll pass the conciergeReportID in the next PR. Ref: https://github.com/Expensify/App/issues/66411
3488+
const message = getReportPreviewMessage(optimisticReportData, undefined);
34883489
const createReportActionMessage = [
34893490
{
34903491
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/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
});

tests/unit/ReportUtilsTest.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ import {
117117
isArchivedReport,
118118
isChatUsedForOnboarding,
119119
isClosedExpenseReportWithNoExpenses,
120+
isConciergeChatReport,
120121
isDeprecatedGroupDM,
121122
isHarvestCreatedExpenseReport,
122123
isMoneyRequestReportEligibleForMerge,
@@ -12789,7 +12790,7 @@ describe('ReportUtils', () => {
1278912790
};
1279012791

1279112792
// When we call getReportPreviewMessage
12792-
const result = getReportPreviewMessage(report, reportAction, false, false, undefined, false, reportAction);
12793+
const result = getReportPreviewMessage(report, undefined, reportAction, false, false, undefined, false, reportAction);
1279312794

1279412795
// Then it should return the childReportName instead of "payer owes $0"
1279512796
expect(result).toBe('Expense Report 2025-01-15');
@@ -12809,7 +12810,7 @@ describe('ReportUtils', () => {
1280912810
};
1281012811

1281112812
// When we call getReportPreviewMessage
12812-
const result = getReportPreviewMessage(report, reportAction, false, false, undefined, false, reportAction);
12813+
const result = getReportPreviewMessage(report, undefined, reportAction, false, false, undefined, false, reportAction);
1281312814

1281412815
// Then it should return the message from the report action (not the childReportName)
1281512816
expect(result).toBe('payer owes $100');
@@ -12825,11 +12826,56 @@ describe('ReportUtils', () => {
1282512826
};
1282612827

1282712828
// When we call getReportPreviewMessage with isCopyAction = true
12828-
const result = getReportPreviewMessage(report, reportAction, false, false, undefined, false, reportAction, true);
12829+
const result = getReportPreviewMessage(report, undefined, reportAction, false, false, undefined, false, reportAction, true);
1282912830

1283012831
// Then it should return the childReportName instead of "payer owes $0"
1283112832
expect(result).toBe('Expense Report 2025-01-15');
1283212833
});
12834+
12835+
it('should pass conciergeReportID through to computeReportName when isCopyAction is true', async () => {
12836+
const report = LHNTestUtils.getFakeReport();
12837+
const reportAction: ReportAction = {
12838+
...LHNTestUtils.getFakeReportAction(),
12839+
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
12840+
childReportName: 'Expense Report',
12841+
childMoneyRequestCount: 0,
12842+
};
12843+
12844+
// When called with conciergeReportID undefined, the function should not throw
12845+
const result1 = getReportPreviewMessage(report, undefined, reportAction, false, false, undefined, false, reportAction, true);
12846+
expect(typeof result1).toBe('string');
12847+
12848+
// When called with a specific conciergeReportID, the function should not throw
12849+
const result2 = getReportPreviewMessage(report, '12345', reportAction, false, false, undefined, false, reportAction, true);
12850+
expect(typeof result2).toBe('string');
12851+
});
12852+
});
12853+
12854+
describe('isConciergeChatReport', () => {
12855+
it('should return false for null/undefined report', () => {
12856+
expect(isConciergeChatReport(null, '12345')).toBe(false);
12857+
expect(isConciergeChatReport(undefined, '12345')).toBe(false);
12858+
});
12859+
12860+
it('should return false when conciergeReportID is undefined', () => {
12861+
const report = LHNTestUtils.getFakeReport();
12862+
expect(isConciergeChatReport(report, undefined)).toBe(false);
12863+
});
12864+
12865+
it('should return true when report.reportID matches conciergeReportID', () => {
12866+
const report = LHNTestUtils.getFakeReport();
12867+
expect(isConciergeChatReport(report, report.reportID)).toBe(true);
12868+
});
12869+
12870+
it('should return false when report.reportID does not match conciergeReportID', () => {
12871+
const report = LHNTestUtils.getFakeReport();
12872+
expect(isConciergeChatReport(report, 'non-matching-id')).toBe(false);
12873+
});
12874+
12875+
it('should return false for empty string conciergeReportID', () => {
12876+
const report = LHNTestUtils.getFakeReport();
12877+
expect(isConciergeChatReport(report, '')).toBe(false);
12878+
});
1283312879
});
1283412880

1283512881
describe('getAvailableReportFields', () => {

0 commit comments

Comments
 (0)