diff --git a/apps/dispatch/app/_components/left/Chat.tsx b/apps/dispatch/app/_components/left/Chat.tsx
index b62e4842..21b0b177 100644
--- a/apps/dispatch/app/_components/left/Chat.tsx
+++ b/apps/dispatch/app/_components/left/Chat.tsx
@@ -9,6 +9,7 @@ import { useQuery } from "@tanstack/react-query";
import { getConnectedDispatcherAPI } from "_querys/dispatcher";
import { getConnectedAircraftsAPI } from "_querys/aircrafts";
import { useDispatchConnectionStore } from "_store/dispatch/connectionStore";
+import { usePilotConnectionStore } from "_store/pilot/connectionStore";
export const Chat = () => {
const {
@@ -28,6 +29,7 @@ export const Chat = () => {
const [addTabValue, setAddTabValue] = useState
("default");
const [message, setMessage] = useState("");
const dispatcherConnected = useDispatchConnectionStore((state) => state.status === "connected");
+ const pilotConnected = usePilotConnectionStore((state) => state.status === "connected");
const { data: dispatcher } = useQuery({
queryKey: ["dispatcher"],
@@ -51,6 +53,14 @@ export const Chat = () => {
(a) => a.userId !== session.data?.user.id && dispatcherConnected,
);
+ const btnActive = pilotConnected || dispatcherConnected;
+
+ useEffect(() => {
+ if (!btnActive) {
+ setChatOpen(false);
+ }
+ }, [btnActive, setChatOpen]);
+
return (
@@ -58,8 +68,12 @@ export const Chat = () => {
)}