@@ -5,7 +5,11 @@ import { getNewInboxMailsInfo } from "./service-mail";
55
66export const MAIL_LIMIT_PER_PAGE = 8 ;
77
8- const setInitials = ( first : string , last : string ) => first [ 0 ] ?. toUpperCase ( ) + last [ 0 ] ?. toUpperCase ( ) ;
8+ const setInitials = ( first ?: string , last ?: string ) => {
9+ const firstInitial = first && first . length > 0 ? first [ 0 ] . toUpperCase ( ) : "" ;
10+ const lastInitial = last && last . length > 0 ? last [ 0 ] . toUpperCase ( ) : "" ;
11+ return firstInitial + lastInitial ;
12+ } ;
913
1014export function prepareThreadDisplayData (
1115 thread : InboxMailThread ,
@@ -44,52 +48,52 @@ export function prepareThreadDisplayData(
4448 }
4549 else if ( ! thread . isAdminSupportThread ) {
4650 if ( thread . latestMail . senderId === currentUser . id ) {
47- displayName = thread . latestMail . recipientNames . map ( r => `${ r . first } ${ r . last } ` ) . join ( ", " ) ;
51+ displayName = thread . latestMail . recipientNames . map ( r => `${ r ? .first } ${ r ? .last } ` ) . join ( ", " ) ;
4852 const r = thread . latestMail . recipientNames [ 0 ] ;
49- displayInitials = setInitials ( r . first , r . last ) ;
53+ displayInitials = setInitials ( r ? .first , r ? .last ) ;
5054 setColor ( recipientIds [ 0 ] ) ;
5155 } else {
5256 const s = thread . latestMail . senderName ;
53- const first = s . first ?? "" ;
54- const last = s . last ?? "" ;
57+ const first = s ? .first ?? "" ;
58+ const last = s ? .last ?? "" ;
5559 displayName = `${ first } ${ last } ` . trim ( ) ;
5660 displayInitials = setInitials ( first , last ) ;
5761 setColor ( thread . latestMail . senderId ) ;
5862 }
5963 } else if ( thread . isAdminSupportThread && thread . metaData ?. autoGenerated ) {
6064 if ( thread . latestMail . senderId ) {
61- displayName = thread . latestMail . recipientNames . map ( r => `${ r . first } ${ r . last } ` ) . join ( ", " ) ;
65+ displayName = thread . latestMail . recipientNames . map ( r => `${ r ? .first } ${ r ? .last } ` ) . join ( ", " ) ;
6266 }
6367 else {
64- displayName = `${ thread . latestMail . senderName . first } ${ thread . latestMail . senderName . last } ` ;
68+ displayName = `${ thread . latestMail . senderName ? .first } ${ thread . latestMail . senderName ? .last } ` ;
6569 DisplayIcon = IconBug
6670 background = "#FFE5E5" ;
6771 text = "#A30000" ;
6872 }
6973 } else if ( thread . isAdminSupportThread && isAdmin && thread . latestMail . senderId === currentUser . id ) {
70- displayName = `${ thread . latestMail . senderName . first } ${ thread . latestMail . senderName . last } ` ;
71- displayInitials = setInitials ( thread . latestMail . senderName . first , thread . latestMail . senderName . last ) ;
74+ displayName = `${ thread . latestMail . senderName ? .first } ${ thread . latestMail . senderName ? .last } ` ;
75+ displayInitials = setInitials ( thread . latestMail . senderName ? .first , thread . latestMail . senderName ? .last ) ;
7276 setColor ( thread . latestMail . senderId ) ;
7377
7478 } else if ( thread . isAdminSupportThread && isAdmin ) {
7579 if ( thread . latestMail . senderId === currentUser . id && thread . latestMail . recipientNames . length === 0 ) {
76- displayName = `${ thread . latestMail . senderName . first } ${ thread . latestMail . senderName . last } ` ;
80+ displayName = `${ thread . latestMail . senderName ? .first } ${ thread . latestMail . senderName ? .last } ` ;
7781 } else if ( thread . latestMail . senderId === currentUser . id ) {
78- displayName = thread . latestMail . recipientNames . map ( r => `${ r . first } ${ r . last } ` ) . join ( ", " ) ;
82+ displayName = thread . latestMail . recipientNames . map ( r => `${ r ? .first } ${ r ? .last } ` ) . join ( ", " ) ;
7983 const r = thread . latestMail . recipientNames [ 0 ] ;
80- displayInitials = setInitials ( r . first , r . last ) ;
84+ displayInitials = setInitials ( r ? .first , r ? .last ) ;
8185 setColor ( recipientIds [ 0 ] ) ;
8286 } else {
8387 const s = thread . latestMail . senderName ;
84- displayName = `${ s . first } ${ s . last } ` ;
85- displayInitials = setInitials ( s . first ?? "" , s . last ?? "" ) ;
88+ displayName = `${ s ? .first } ${ s ? .last } ` ;
89+ displayInitials = setInitials ( s ? .first ?? "" , s ? .last ?? "" ) ;
8690 setColor ( thread . latestMail . senderId ?? thread . createdBy ) ;
8791 }
8892 } else {
8993 if ( thread . latestMail . senderId === currentUser . id ) {
90- displayName = thread . latestMail . recipientNames . map ( r => `${ r . first } ${ r . last } ` ) . join ( ", " ) ;
94+ displayName = thread . latestMail . recipientNames . map ( r => `${ r ? .first } ${ r ? .last } ` ) . join ( ", " ) ;
9195 } else {
92- displayName = `${ thread . latestMail . senderName . first } ${ thread . latestMail . senderName . last } ` ;
96+ displayName = `${ thread . latestMail . senderName ? .first } ${ thread . latestMail . senderName ? .last } ` ;
9397 }
9498 }
9599
0 commit comments