From 12edbc6a1b41b52ca3b9f13989f2f37599efce29 Mon Sep 17 00:00:00 2001 From: V3N1TH <152465117+VenithAbey@users.noreply.github.com> Date: Sun, 22 Mar 2026 23:00:37 +0530 Subject: [PATCH 1/2] doctor portal con removal,chat bot ,messaging changes --- .../PatientPortal/FloatingChatbot.jsx | 2 +- .../DoctorMessagingDashboard.jsx | 16 ++++++-- .../DoctorViewComponents/Header.jsx | 39 +------------------ src/pages/DoctorsPage/DocDashboard.jsx | 23 +---------- vite.config.js | 6 +++ 5 files changed, 24 insertions(+), 62 deletions(-) diff --git a/src/components/PatientPortal/FloatingChatbot.jsx b/src/components/PatientPortal/FloatingChatbot.jsx index ca17f27..b027f5b 100644 --- a/src/components/PatientPortal/FloatingChatbot.jsx +++ b/src/components/PatientPortal/FloatingChatbot.jsx @@ -36,7 +36,7 @@ const FloatingChatbot = ({ isFullScreen = false, hideFloatingButton = false }) = setLoading(true); try { - const res = await fetch(`${import.meta.env.VITE_CHATBOT_URL}/api/chat`, { + const res = await fetch(`/chatbot/api/chat`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message: inputMessage }), diff --git a/src/pages/DoctorViewPatient/DoctorViewComponents/DoctorMessagingDashboard.jsx b/src/pages/DoctorViewPatient/DoctorViewComponents/DoctorMessagingDashboard.jsx index f545426..5b3681a 100644 --- a/src/pages/DoctorViewPatient/DoctorViewComponents/DoctorMessagingDashboard.jsx +++ b/src/pages/DoctorViewPatient/DoctorViewComponents/DoctorMessagingDashboard.jsx @@ -23,7 +23,9 @@ import SockJS from "sockjs-client"; /* ===================== Helpers ===================== */ const API_BASE = import.meta.env.VITE_API_URL; -const WS_BASE = import.meta.env.VITE_WS_URL || import.meta.env.VITE_API_URL; +// WebSocket connects directly to mainservice (not via API gateway) +// SockJS doesn't support custom request headers, so token is passed as query param +const WS_BASE = import.meta.env.VITE_WS_URL || "http://localhost:8080"; // Allow 0 as valid ID function safeNumber(v) { @@ -310,7 +312,8 @@ const DoctorMessagingDashboard = () => { const connectWebSocket = () => { if (stompRef.current?.active) return; const stomp = new Client({ - webSocketFactory: () => new SockJS(`${WS_BASE}/ws`), + // Pass token as query param — SockJS cannot send custom HTTP headers + webSocketFactory: () => new SockJS(`${WS_BASE}/ws?token=${encodeURIComponent(token || "")}`), reconnectDelay: 5000, }); @@ -493,6 +496,12 @@ const DoctorMessagingDashboard = () => { if (!messageText.trim()) return; if (userId === null || !selectedChat.participantId) return; + // Block send if WebSocket is not connected + if (!isConnected) { + alert("Not connected. Please wait a moment and try again."); + return; + } + const message = { conversationId: selectedChat.id, senderId: userId, @@ -506,6 +515,7 @@ const DoctorMessagingDashboard = () => { try { stompRef.current.send(message); + // Only show message locally after confirming send was attempted setMessages((prev) => [ ...prev, { id: Date.now(), sender: "self", text: messageText, time: "Just now", read: false, attachments: [] }, @@ -514,7 +524,7 @@ const DoctorMessagingDashboard = () => { if (textareaRef.current) textareaRef.current.style.height = "auto"; } catch (err) { console.error("Error sending message:", err); - alert("Failed to send message."); + alert("Failed to send message. Please check your connection."); } }; diff --git a/src/pages/DoctorViewPatient/DoctorViewComponents/Header.jsx b/src/pages/DoctorViewPatient/DoctorViewComponents/Header.jsx index 80acdc7..05e273b 100644 --- a/src/pages/DoctorViewPatient/DoctorViewComponents/Header.jsx +++ b/src/pages/DoctorViewPatient/DoctorViewComponents/Header.jsx @@ -1,6 +1,5 @@ import React, { useState, useEffect } from "react"; -import { Heart, Bell, ArrowLeft } from "lucide-react"; -import AlertsCard from "../../../components/PatientPortal/AlertsCard"; +import { Heart, ArrowLeft } from "lucide-react"; import { useNavigate, useLocation } from "react-router-dom"; const Header = ({ @@ -10,8 +9,7 @@ const Header = ({ const navigate = useNavigate(); const location = useLocation(); - const [isDarkMode, setIsDarkMode] = useState(false); - const [showAlerts, setShowAlerts] = useState(false); + const [profileName, setProfileName] = useState("Patient"); // where to return (from navigate state) @@ -74,40 +72,7 @@ const Header = ({ )} - {/* DARK MODE UI toggle only */} - - {/* ALERTS */} -
- - - {showAlerts && ( -
- -
- )} -
diff --git a/src/pages/DoctorsPage/DocDashboard.jsx b/src/pages/DoctorsPage/DocDashboard.jsx index 98b9638..1047744 100644 --- a/src/pages/DoctorsPage/DocDashboard.jsx +++ b/src/pages/DoctorsPage/DocDashboard.jsx @@ -10,8 +10,6 @@ import AppointmentsCard from "../../components/PatientPortal/AppointmentsCard"; import { useNavigate } from "react-router-dom"; import { Heart, - Bell, - Settings, Activity, AlertTriangle, FileText, @@ -21,8 +19,8 @@ import { AlertCircle, TrendingUp, Wifi, - MessageSquare, // NEW ICON for Messaging - Calendar, // NEW ICON for Appointments + MessageSquare, + Calendar, } from "lucide-react"; /* ===================== Config ===================== */ @@ -114,7 +112,6 @@ const fetchMyPatients = async () => { }; function DocDashboard() { - const [hasNotification, setHasNotification] = useState(true); const [activeTab, setActiveTab] = useState("patient-overview"); const [searchQuery, setSearchQuery] = useState(""); const navigate = useNavigate(); @@ -309,23 +306,7 @@ function DocDashboard() { {/* Right */}
- -