From 09b52a64a3d5408b18f8940542e7095694312dd8 Mon Sep 17 00:00:00 2001 From: Nar Cuenca Date: Mon, 18 Nov 2024 09:27:39 +0800 Subject: [PATCH] fix: prevent users with no first or last names from crashing the app --- src/shell/components/Comment/MentionList.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/shell/components/Comment/MentionList.tsx b/src/shell/components/Comment/MentionList.tsx index 79dc05062e..c04666059a 100644 --- a/src/shell/components/Comment/MentionList.tsx +++ b/src/shell/components/Comment/MentionList.tsx @@ -40,7 +40,15 @@ export const MentionList = forwardRef( const _filterKeyword = filterKeyword?.toLowerCase(); return [...users] - ?.sort((userA, userB) => userA.firstName.localeCompare(userB.firstName)) + ?.sort((userA, userB) => { + const userAName = userA.firstName || userA.lastName || ""; + const userBName = userB.firstName || userB.lastName || ""; + + if (!userAName) return 1; + if (!userBName) return -1; + + return userAName.localeCompare(userBName); + }) .filter( (user) => user.email?.toLowerCase()?.includes(_filterKeyword) || @@ -178,7 +186,7 @@ export const MentionList = forwardRef( />