diff --git a/components/AppNotifications.tsx b/components/AppNotifications.tsx index 2c39cef..477c715 100644 --- a/components/AppNotifications.tsx +++ b/components/AppNotifications.tsx @@ -47,7 +47,7 @@ export default function AppNotifications(props: AppNotificationsProps) { }, [props.notifications, showMoreClicked]); const hasNewNotifications = useMemo(() => { - if (lastSeenNotification === -1) return true; // if no notification was seen + if (lastSeenNotification === -1) return props.notifications.length > 0; return props.notifications.some(notification => notification.id > lastSeenNotification); }, [lastSeenNotification, props.notifications]); diff --git a/components/inbox-mail/CreateNewMailModal.tsx b/components/inbox-mail/CreateNewMailModal.tsx index 66d07fa..9e1fd02 100644 --- a/components/inbox-mail/CreateNewMailModal.tsx +++ b/components/inbox-mail/CreateNewMailModal.tsx @@ -275,9 +275,9 @@ function UserSelector(props: UserSelectorProps) { setFilteredUsers( props.users.filter( (u) => - u.firstName.toLowerCase().includes(lower) || - u.lastName.toLowerCase().includes(lower) || - u.mail.toLowerCase().includes(lower) + (u.firstName && u.firstName.toLowerCase().includes(lower)) || + (u.lastName && u.lastName.toLowerCase().includes(lower)) || + (u.mail && u.mail.toLowerCase().includes(lower)) ).filter((u) => !props.selectedUsers.some((selected) => selected.id === u.id)) ); } diff --git a/components/inbox-mail/InboxMailAdminPanel.tsx b/components/inbox-mail/InboxMailAdminPanel.tsx index 8425cac..22ca005 100644 --- a/components/inbox-mail/InboxMailAdminPanel.tsx +++ b/components/inbox-mail/InboxMailAdminPanel.tsx @@ -68,8 +68,8 @@ function InboxMailAdminPanel(props: InboxMailAdminPanelProps) { {props.selectedThread.progressState !== InboxMailThreadSupportProgressState.PENDING && props.selectedThread.metaData?.supportOwnerName && (
- {props.selectedThread.metaData.supportOwnerName.first}{" "} - {props.selectedThread.metaData.supportOwnerName.last} + {props.selectedThread.metaData.supportOwnerName?.first}{" "} + {props.selectedThread.metaData.supportOwnerName?.last}
)} diff --git a/components/inbox-mail/InboxMailItem.tsx b/components/inbox-mail/InboxMailItem.tsx index 0da1e04..9e2f1f6 100644 --- a/components/inbox-mail/InboxMailItem.tsx +++ b/components/inbox-mail/InboxMailItem.tsx @@ -38,7 +38,7 @@ export default function ThreadMailItem(props: ThreadMailItemProps) { - {t("inboxMail.to")}: {props.mail.recipientNames.map((name) => `${name.first} ${name.last}`).join(", ")} + {t("inboxMail.to")}: {props.mail.recipientNames.map((name) => `${name?.first} ${name?.last}`).join(", ")} diff --git a/components/inbox-mail/helper.ts b/components/inbox-mail/helper.ts index 778fe7f..05bc625 100644 --- a/components/inbox-mail/helper.ts +++ b/components/inbox-mail/helper.ts @@ -5,7 +5,11 @@ import { getNewInboxMailsInfo } from "./service-mail"; export const MAIL_LIMIT_PER_PAGE = 8; -const setInitials = (first: string, last: string) => first[0]?.toUpperCase() + last[0]?.toUpperCase(); +const setInitials = (first?: string, last?: string) => { + const firstInitial = first && first.length > 0 ? first[0].toUpperCase() : ""; + const lastInitial = last && last.length > 0 ? last[0].toUpperCase() : ""; + return firstInitial + lastInitial; +}; export function prepareThreadDisplayData( thread: InboxMailThread, @@ -44,52 +48,52 @@ export function prepareThreadDisplayData( } else if (!thread.isAdminSupportThread) { if (thread.latestMail.senderId === currentUser.id) { - displayName = thread.latestMail.recipientNames.map(r => `${r.first} ${r.last}`).join(", "); + displayName = thread.latestMail.recipientNames.map(r => `${r?.first} ${r?.last}`).join(", "); const r = thread.latestMail.recipientNames[0]; - displayInitials = setInitials(r.first, r.last); + displayInitials = setInitials(r?.first, r?.last); setColor(recipientIds[0]); } else { const s = thread.latestMail.senderName; - const first = s.first ?? ""; - const last = s.last ?? ""; + const first = s?.first ?? ""; + const last = s?.last ?? ""; displayName = `${first} ${last}`.trim(); displayInitials = setInitials(first, last); setColor(thread.latestMail.senderId); } } else if (thread.isAdminSupportThread && thread.metaData?.autoGenerated) { if (thread.latestMail.senderId) { - displayName = thread.latestMail.recipientNames.map(r => `${r.first} ${r.last}`).join(", "); + displayName = thread.latestMail.recipientNames.map(r => `${r?.first} ${r?.last}`).join(", "); } else { - displayName = `${thread.latestMail.senderName.first} ${thread.latestMail.senderName.last}`; + displayName = `${thread.latestMail.senderName?.first} ${thread.latestMail.senderName?.last}`; DisplayIcon = IconBug background = "#FFE5E5"; text = "#A30000"; } } else if (thread.isAdminSupportThread && isAdmin && thread.latestMail.senderId === currentUser.id) { - displayName = `${thread.latestMail.senderName.first} ${thread.latestMail.senderName.last}`; - displayInitials = setInitials(thread.latestMail.senderName.first, thread.latestMail.senderName.last); + displayName = `${thread.latestMail.senderName?.first} ${thread.latestMail.senderName?.last}`; + displayInitials = setInitials(thread.latestMail.senderName?.first, thread.latestMail.senderName?.last); setColor(thread.latestMail.senderId); } else if (thread.isAdminSupportThread && isAdmin) { if (thread.latestMail.senderId === currentUser.id && thread.latestMail.recipientNames.length === 0) { - displayName = `${thread.latestMail.senderName.first} ${thread.latestMail.senderName.last}`; + displayName = `${thread.latestMail.senderName?.first} ${thread.latestMail.senderName?.last}`; } else if (thread.latestMail.senderId === currentUser.id) { - displayName = thread.latestMail.recipientNames.map(r => `${r.first} ${r.last}`).join(", "); + displayName = thread.latestMail.recipientNames.map(r => `${r?.first} ${r?.last}`).join(", "); const r = thread.latestMail.recipientNames[0]; - displayInitials = setInitials(r.first, r.last); + displayInitials = setInitials(r?.first, r?.last); setColor(recipientIds[0]); } else { const s = thread.latestMail.senderName; - displayName = `${s.first} ${s.last}`; - displayInitials = setInitials(s.first ?? "", s.last ?? ""); + displayName = `${s?.first} ${s?.last}`; + displayInitials = setInitials(s?.first ?? "", s?.last ?? ""); setColor(thread.latestMail.senderId ?? thread.createdBy); } } else { if (thread.latestMail.senderId === currentUser.id) { - displayName = thread.latestMail.recipientNames.map(r => `${r.first} ${r.last}`).join(", "); + displayName = thread.latestMail.recipientNames.map(r => `${r?.first} ${r?.last}`).join(", "); } else { - displayName = `${thread.latestMail.senderName.first} ${thread.latestMail.senderName.last}`; + displayName = `${thread.latestMail.senderName?.first} ${thread.latestMail.senderName?.last}`; } }