This commit is contained in:
NotII
2025-03-23 23:08:09 +00:00
parent 259898cef0
commit 64ee9b842e
4 changed files with 46 additions and 71 deletions

View File

@@ -22,7 +22,7 @@ import {
Eye,
User
} from "lucide-react";
import axios from "axios";
import { clientFetch } from "@/lib/client-utils";
import { toast } from "sonner";
import { getCookie } from "@/lib/client-utils";
@@ -106,17 +106,12 @@ export default function ChatTable() {
const fetchUnreadCounts = async () => {
try {
// Get the vendor ID from the auth token
const { vendorId, authToken } = getVendorIdFromToken();
const { vendorId } = getVendorIdFromToken();
// Fetch unread counts for this vendor
const response = await axios.get(`${process.env.NEXT_PUBLIC_API_URL}/chats/vendor/${vendorId}/unread`, {
headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json",
},
});
// Fetch unread counts for this vendor using clientFetch
const response = await clientFetch(`/chats/vendor/${vendorId}/unread`);
const newUnreadCounts = response.data;
const newUnreadCounts = response;
// Play sound if there are new messages
if (newUnreadCounts.totalUnread > unreadCounts.totalUnread) {
@@ -135,17 +130,12 @@ export default function ChatTable() {
try {
// Get the vendor ID from the auth token
const { vendorId, authToken } = getVendorIdFromToken();
const { vendorId } = getVendorIdFromToken();
// Now fetch chats for this vendor
const response = await axios.get(`${process.env.NEXT_PUBLIC_API_URL}/chats/vendor/${vendorId}`, {
headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json",
},
});
// Now fetch chats for this vendor using clientFetch
const response = await clientFetch(`/chats/vendor/${vendorId}`);
setChats(Array.isArray(response.data) ? response.data : []);
setChats(Array.isArray(response) ? response : []);
await fetchUnreadCounts();
} catch (error) {
console.error("Failed to fetch chats:", error);