diff --git a/src/CONST.ts b/src/CONST.ts index ac42732f2325..23dea990a7a5 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2842,6 +2842,7 @@ const CONST = { SHORT_MENTION: new RegExp(`@[\\w\\-\\+\\'#@]+(?:\\.[\\w\\-\\'\\+]+)*(?![^\`]*\`)`, 'gim'), REPORT_ID_FROM_PATH: /\/r\/(\d+)/, DISTANCE_MERCHANT: /^[0-9.]+ \w+ @ (-|-\()?[^0-9.\s]{1,3} ?[0-9.]+\)? \/ \w+$/, + WHITESPACE: /\s+/g, get EXPENSIFY_POLICY_DOMAIN_NAME() { return new RegExp(`${EXPENSIFY_POLICY_DOMAIN}([a-zA-Z0-9]+)\\${EXPENSIFY_POLICY_DOMAIN_EXTENSION}`); diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 14fb727e4d7b..e7399a6d3982 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -79,6 +79,10 @@ type MiniReport = { lastVisibleActionCreated?: string; }; +function ensureSingleSpacing(text: string) { + return text.replace(CONST.REGEX.WHITESPACE, ' ').trim(); +} + /** * @returns An array of reportIDs sorted in the proper order */ @@ -549,9 +553,11 @@ function getWelcomeMessage(report: OnyxEntry, policy: OnyxEntry) welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne'); welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo'); welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree'); - welcomeMessage.messageText = `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName( - report, - )} ${welcomeMessage.phrase3}`; + welcomeMessage.messageText = ensureSingleSpacing( + `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName(report)} ${ + welcomeMessage.phrase3 + }`, + ); } return welcomeMessage; } @@ -593,7 +599,7 @@ function getWelcomeMessage(report: OnyxEntry, policy: OnyxEntry) }) .join(' '); - welcomeMessage.messageText = displayNamesWithTooltips.length ? `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}` : ''; + welcomeMessage.messageText = displayNamesWithTooltips.length ? ensureSingleSpacing(`${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`) : ''; return welcomeMessage; } @@ -641,7 +647,7 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartOne'); welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartTwo'); } - welcomeMessage.messageText = `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; + welcomeMessage.messageText = ensureSingleSpacing(`${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`); return welcomeMessage; }