Update ChatNotifications.tsx

This commit is contained in:
NotII
2025-03-03 21:21:54 +00:00
parent 2fafcb868a
commit 3282051671

View File

@@ -29,12 +29,10 @@ export default function ChatNotifications() {
useEffect(() => { useEffect(() => {
const fetchUnreadCounts = async () => { const fetchUnreadCounts = async () => {
try { try {
// Get auth token from cookies
const authToken = getCookie("Authorization"); const authToken = getCookie("Authorization");
if (!authToken) return; if (!authToken) return;
// Set up axios with the auth token
const authAxios = axios.create({ const authAxios = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL, baseURL: process.env.NEXT_PUBLIC_API_URL,
headers: { headers: {
@@ -42,15 +40,15 @@ export default function ChatNotifications() {
} }
}); });
// Get vendor ID from profile
const vendorResponse = await authAxios.get('/auth/me'); const vendorResponse = await authAxios.get('/auth/me');
console.log(vendorResponse.data.vendor._id);
const vendorId = vendorResponse.data.vendor._id; const vendorId = vendorResponse.data.vendor._id;
const response = await authAxios.get(`/chats/vendor/${vendorId}/unread`); const response = await authAxios.get(`/chats/vendor/${vendorId}/unread`);
setUnreadCounts(response.data); setUnreadCounts(response.data);
// If there are unread messages, fetch chat metadata
if (response.data.totalUnread > 0) { if (response.data.totalUnread > 0) {
const chatIds = Object.keys(response.data.chatCounts); const chatIds = Object.keys(response.data.chatCounts);