diff --git a/src/libs/LocalePhoneNumber.js b/src/libs/LocalePhoneNumber.js index dbe7e39f5941..ac85aa1dbdd0 100644 --- a/src/libs/LocalePhoneNumber.js +++ b/src/libs/LocalePhoneNumber.js @@ -39,6 +39,10 @@ Onyx.connect({ * @returns {String} */ function formatPhoneNumber(number) { + if (!number) { + return ''; + } + const parsedPhoneNumber = parsePhoneNumber(Str.removeSMSDomain(number)); // return the string untouched if it's not a phone number diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index ffed87332ec2..a16d1235bae7 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -185,7 +185,7 @@ function getParticipantsOptions(report, personalDetails) { text: details.displayName, firstName: lodashGet(details, 'firstName', ''), lastName: lodashGet(details, 'lastName', ''), - alternateText: Str.isSMSLogin(details.login) ? LocalePhoneNumber.formatPhoneNumber(details.login) : details.login, + alternateText: Str.isSMSLogin(details.login || '') ? LocalePhoneNumber.formatPhoneNumber(details.login) : details.login, icons: [{ source: ReportUtils.getAvatar(details.avatar, details.login), name: details.login, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 398cd025e598..223f4205f9ad 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -791,7 +791,7 @@ function getDisplayNameForParticipant(login, shouldUseShortForm = false) { function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport) { return _.map(participants, (participant) => { const displayName = getDisplayNameForParticipant(participant.login, isMultipleParticipantReport); - const tooltip = Str.removeSMSDomain(participant.login); + const tooltip = participant.login ? Str.removeSMSDomain(participant.login) : ''; let pronouns = participant.pronouns; if (pronouns && pronouns.startsWith(CONST.PRONOUNS.PREFIX)) { diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index 8e4b9e1bc564..3842f96623e6 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -67,7 +67,7 @@ function extractFirstAndLastNameFromAvailableDetails({ if (firstName || lastName) { return {firstName: firstName || '', lastName: lastName || ''}; } - if (Str.removeSMSDomain(login) === displayName) { + if (login && Str.removeSMSDomain(login) === displayName) { return {firstName: '', lastName: ''}; } diff --git a/src/pages/DetailsPage.js b/src/pages/DetailsPage.js index 003823bc3ca8..f67ba3ddb9f1 100755 --- a/src/pages/DetailsPage.js +++ b/src/pages/DetailsPage.js @@ -80,7 +80,7 @@ const getPhoneNumber = (details) => { } // If the user has set a displayName, get the phone number from the SMS login - return Str.removeSMSDomain(details.login); + return details.login ? Str.removeSMSDomain(details.login) : ''; }; class DetailsPage extends React.PureComponent { @@ -97,7 +97,7 @@ class DetailsPage extends React.PureComponent { }; } - const isSMSLogin = Str.isSMSLogin(details.login); + const isSMSLogin = details.login ? Str.isSMSLogin(details.login) : false; // If we have a reportID param this means that we // arrived here via the ParticipantsPage and should be allowed to navigate back to it diff --git a/src/pages/ReportParticipantsPage.js b/src/pages/ReportParticipantsPage.js index 34189f347ef3..5ef52c49fe25 100755 --- a/src/pages/ReportParticipantsPage.js +++ b/src/pages/ReportParticipantsPage.js @@ -57,25 +57,27 @@ const defaultProps = { const getAllParticipants = (report, personalDetails) => { const {participants} = report; - return _.map(participants, (login) => { - const userLogin = Str.removeSMSDomain(login); - const userPersonalDetail = lodashGet(personalDetails, login, {displayName: userLogin, avatar: ''}); + return _.chain(participants) + .compact() + .map(participants, (login) => { + const userLogin = Str.removeSMSDomain(login); + const userPersonalDetail = lodashGet(personalDetails, login, {displayName: userLogin, avatar: ''}); - return ({ - alternateText: userLogin, - displayName: userPersonalDetail.displayName, - icons: [{ - source: ReportUtils.getAvatar(userPersonalDetail.avatar, login), - name: login, - type: CONST.ICON_TYPE_AVATAR, - }], - keyForList: userLogin, - login, - text: userPersonalDetail.displayName, - tooltipText: userLogin, - participantsList: [{login, displayName: userPersonalDetail.displayName}], - }); - }); + return ({ + alternateText: userLogin, + displayName: userPersonalDetail.displayName, + icons: [{ + source: ReportUtils.getAvatar(userPersonalDetail.avatar, login), + name: login, + type: CONST.ICON_TYPE_AVATAR, + }], + keyForList: userLogin, + login, + text: userPersonalDetail.displayName, + tooltipText: userLogin, + participantsList: [{login, displayName: userPersonalDetail.displayName}], + }); + }).value(); }; const ReportParticipantsPage = (props) => { diff --git a/src/pages/home/report/ReportActionItemSingle.js b/src/pages/home/report/ReportActionItemSingle.js index ed208a7db999..12030f20973f 100644 --- a/src/pages/home/report/ReportActionItemSingle.js +++ b/src/pages/home/report/ReportActionItemSingle.js @@ -64,10 +64,11 @@ const ReportActionItemSingle = (props) => { // Since the display name for a report action message is delivered with the report history as an array of fragments // we'll need to take the displayName from personal details and have it be in the same format for now. Eventually, // we should stop referring to the report history items entirely for this information. + const isSMSLogin = login ? Str.isSMSLogin(login) : false; const personArray = displayName ? [{ type: 'TEXT', - text: Str.isSMSLogin(login) ? props.formatPhoneNumber(displayName) : displayName, + text: isSMSLogin ? props.formatPhoneNumber(displayName) : displayName, }] : props.action.person;