diff --git a/src/pages/Encounters/tabs/EncounterNotesTab.tsx b/src/pages/Encounters/tabs/EncounterNotesTab.tsx
index d8a93b592c5..8ee50c6683d 100644
--- a/src/pages/Encounters/tabs/EncounterNotesTab.tsx
+++ b/src/pages/Encounters/tabs/EncounterNotesTab.tsx
@@ -13,6 +13,7 @@ import {
Send,
Users,
} from "lucide-react";
+import { navigate } from "raviger";
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useInView } from "react-intersection-observer";
@@ -47,6 +48,7 @@ import { Avatar } from "@/components/Common/Avatar";
import Loading from "@/components/Common/Loading";
import useAuthUser from "@/hooks/useAuthUser";
+import useSlug from "@/hooks/useSlug";
import routes from "@/Utils/request/api";
import mutate from "@/Utils/request/mutate";
@@ -136,6 +138,11 @@ const ThreadItem = ({
const MessageItem = ({ message }: { message: Message }) => {
const authUser = useAuthUser();
const isCurrentUser = authUser?.external_id === message.created_by.id;
+ const facilityId = useSlug("facility");
+
+ const navigateToUser = () => {
+ navigate(`/facility/${facilityId}/users/${message.created_by.username}`);
+ };
return (
{
-
+
{
isCurrentUser ? "items-end" : "items-start",
)}
>
-
+
{message.created_by.username}
{
const [isThreadsExpanded, setIsThreadsExpanded] = useState(false);
const [showNewThreadDialog, setShowNewThreadDialog] = useState(false);
const [newMessage, setNewMessage] = useState("");
+ const [scrollToBottom, setScrollToBottom] = useState(false);
const messagesEndRef = useRef
(null);
const { ref, inView } = useInView();
@@ -394,6 +408,7 @@ export const EncounterNotesTab = ({ encounter }: EncounterTabProps) => {
setNewMessage("");
setTimeout(() => {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
+ setScrollToBottom(true);
}, 100);
},
onError: () => {
@@ -410,8 +425,14 @@ export const EncounterNotesTab = ({ encounter }: EncounterTabProps) => {
// Scroll to bottom on initial load and thread change
useEffect(() => {
- if (messagesData && !messagesLoading && !isFetchingNextPage) {
+ if (
+ messagesData &&
+ !messagesLoading &&
+ !isFetchingNextPage &&
+ (messagesData.pages.length === 1 || scrollToBottom)
+ ) {
messagesEndRef.current?.scrollIntoView();
+ setScrollToBottom(false);
}
}, [selectedThread, messagesData, messagesLoading, isFetchingNextPage]);
@@ -592,8 +613,16 @@ export const EncounterNotesTab = ({ encounter }: EncounterTabProps) => {
))
)}
{isFetchingNextPage && (
-
-
+
)}
@@ -616,6 +645,7 @@ export const EncounterNotesTab = ({ encounter }: EncounterTabProps) => {
}
}
}}
+ className="max-h-[150px]"
/>