diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx index 48edc09d7a396..a6130522957f5 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx @@ -43,7 +43,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona if (!isEmpty(htmlAttribAccountID) && personalDetails?.[htmlAttribAccountID]) { const user = personalDetails[htmlAttribAccountID]; accountID = parseInt(htmlAttribAccountID, 10); - mentionDisplayText = formatPhoneNumber(user?.login ?? '') || getDisplayNameOrDefault(user); + mentionDisplayText = getDisplayNameOrDefault(user) || formatPhoneNumber(user?.login ?? ''); mentionDisplayText = getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID, currentUserPersonalDetails, user?.login ?? '') ?? ''; navigationRoute = ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute()); } else if ('data' in tnode && !isEmptyObject(tnode.data)) { @@ -56,9 +56,15 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona Str.removeSMSDomain(getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID, currentUserPersonalDetails) ?? ''), ); - accountID = getAccountIDsByLogins([mentionDisplayText])?.at(0) ?? -1; + accountID = getAccountIDsByLogins([mentionDisplayText], false)?.at(0) ?? -1; + if (accountID !== -1) { + const user = personalDetails?.[accountID]; + mentionDisplayText = getDisplayNameOrDefault(user) || formatPhoneNumber(user?.login ?? ''); + mentionDisplayText = getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID, currentUserPersonalDetails, user?.login ?? '') ?? ''; + } else { + mentionDisplayText = Str.removeSMSDomain(mentionDisplayText); + } navigationRoute = ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute(), mentionDisplayText); - mentionDisplayText = Str.removeSMSDomain(mentionDisplayText); } else { // If neither an account ID or email is provided, don't render anything return null; @@ -114,7 +120,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona testID="mention-user" href={`/${navigationRoute}`} > - {htmlAttribAccountID ? `@${mentionDisplayText}` : } + {accountID && accountID !== -1 ? `@${mentionDisplayText}` : } diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 52360cc79d605..ad97c8d8c7a34 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -147,12 +147,12 @@ function getPersonalDetailByEmail(email: string): PersonalDetails | undefined { * @param logins Array of user logins * @returns Array of accountIDs according to passed logins */ -function getAccountIDsByLogins(logins: string[]): number[] { +function getAccountIDsByLogins(logins: string[], shouldGenerateAccountID = true): number[] { return logins.reduce((foundAccountIDs, login) => { const currentDetail = personalDetails.find((detail) => detail?.login === login?.toLowerCase()); if (!currentDetail) { // generate an account ID because in this case the detail is probably new, so we don't have a real accountID yet - foundAccountIDs.push(generateAccountID(login)); + foundAccountIDs.push(shouldGenerateAccountID ? generateAccountID(login) : -1); } else { foundAccountIDs.push(Number(currentDetail.accountID)); }