diff --git a/src/components/LBDashboard/Messaging/LBMessaging.jsx b/src/components/LBDashboard/Messaging/LBMessaging.jsx index 7dcf80469d..8ebf0b5328 100644 --- a/src/components/LBDashboard/Messaging/LBMessaging.jsx +++ b/src/components/LBDashboard/Messaging/LBMessaging.jsx @@ -20,6 +20,7 @@ import { markMessagesAsReadViaSocket, } from '../../../utils/messagingSocket'; import logo from '../../../assets/images/logo2.png'; +import Header from '../../Header/Header'; export default function LBMessaging() { const dispatch = useDispatch(); @@ -56,7 +57,7 @@ export default function LBMessaging() { const sidebarContacts = useMemo(() => { const chats = [...existingChats]; const sid = selectedUser?.userId; - if (!sid) return chats; + if (!sid || !selectedUser?.firstName) return chats; const exists = chats.some(c => String(c.userId ?? c._id) === String(sid)); if (!exists) { chats.unshift({ @@ -152,7 +153,7 @@ export default function LBMessaging() { useEffect(() => { const handleClickOutside = event => { if (menuRef.current && !menuRef.current.contains(event.target)) { - setMobileHamMenu(false); // Close the menu if clicked outside + setMobileHamMenu(false); } }; @@ -259,7 +260,6 @@ export default function LBMessaging() { toast.success('Preferences updated successfully!'); setBellDropdownActive(false); - // Refresh preferences after saving dispatch(fetchUserPreferences(currentUserId, selectedUser.userId)).then(response => { if (response?.payload) { setSelectedOption({ @@ -313,6 +313,34 @@ export default function LBMessaging() { return () => window.removeEventListener('resize', handleResize); }, []); + const handleSearchChange = e => { + const query = e.target.value; + setSearchQuery(query); + if (query.trim() === '') { + setSearchResults([]); + } else { + searchUserProfiles(query); + } + }; + + const renderContactButton = (key, user, onClick) => ( + + ); + const renderContacts = () => { if (sidebarContacts.length === 0) { return ( @@ -320,40 +348,21 @@ export default function LBMessaging() { ); } - return sidebarContacts.map(user => ( - - )); + return sidebarContacts.map(user => + renderContactButton(user.userId || user._id, user, () => { + updateSelection(user); + setMobileHamMenu(false); + }), + ); }; const renderChatMessages = () => { if (messagesLoading) { - return

Loading messages...

; + return

Loading messages...

; } if (messages.length === 0) { - return

No messages to display.

; + return

No messages to display.

; } const filteredMessages = messages.filter( @@ -363,12 +372,12 @@ export default function LBMessaging() { ); if (filteredMessages.length === 0) { - return

No messages to display.

; + return

No messages to display.

; } return ( -
-
+
+
{filteredMessages.map(message => (
-

+

{String(message.content ?? '') .split('\n') .map((line, lineIdx) => ( @@ -396,61 +405,63 @@ export default function LBMessaging() { return ( (users?.userProfilesBasicInfo?.length ?? 0) !== 0 && (

-
-
+
+
+
One Community Logo
-
+
{mobileView ? (
-
-
+
+
{mobileHamMenu && ( -
-
+
+
+
+ +
{showContacts ? ( -
+
{ - const query = e.target.value; - setSearchQuery(query); - if (query.trim() === '') { - setSearchResults([]); - } else { - searchUserProfiles(query); - } - }} + onChange={handleSearchChange} />
) : ( -
-

Messages

-
+
+

Messages

+
setShowContacts(prev => !prev)} />
@@ -460,35 +471,12 @@ export default function LBMessaging() { className={`${styles.lbMessagingContactsBody} ${styles.activeInlbMessagingContactsBody}`} > {showContacts - ? safeSearchResults.map(user => ( - - )) + ? safeSearchResults.map(user => + renderContactButton(user.userId, user, () => { + updateSelection(user); + setMobileHamMenu(false); + }), + ) : renderContacts()}
@@ -498,46 +486,38 @@ export default function LBMessaging() {
) : null} -
+
{/* Contacts Section */} {!mobileView && ( -
+
{showContacts ? ( -
+
{ - const query = e.target.value; - setSearchQuery(query); - if (query.trim() === '') { - setSearchResults([]); - } else { - searchUserProfiles(query); - } - }} + onChange={handleSearchChange} />
) : ( -
-

Messages

-
+
+

Messages

+
setShowContacts(prev => !prev)} />
@@ -547,37 +527,18 @@ export default function LBMessaging() { className={`${styles.lbMessagingContactsBody} ${styles.activeInlbMessagingContactsBody}`} > {showContacts - ? safeSearchResults.map(user => ( - - )) + ? safeSearchResults.map(user => + renderContactButton(user._id, user, () => updateSelection(user)), + ) : renderContacts()}
)} {/* Chat Window Section */} -
-
-
+
+
+
{ @@ -586,20 +547,20 @@ export default function LBMessaging() { }} alt="Profile" /> - + {selectedUser.firstName ? `${selectedUser.firstName} ${selectedUser.lastName}` : 'Select a user to chat'}
{selectedUser.userId && ( -
+
{ setBellDropdownActive(prev => !prev); }} - className={`${styles.lgMessagingNotificationBell}`} + className={styles.lgMessagingNotificationBell} /> {bellDropdownActive && (
)}
-
+
{selectedUser.userId ? ( renderChatMessages() ) : ( -

Select a user to start chatting

+

Select a user to start chatting

)}
-
+