+
);
}
\ No newline at end of file
diff --git a/app/dashboard/chats/page.tsx b/app/dashboard/chats/page.tsx
index e2fdfe4..d431f38 100644
--- a/app/dashboard/chats/page.tsx
+++ b/app/dashboard/chats/page.tsx
@@ -1,6 +1,7 @@
import React from "react";
import { Metadata } from "next";
import ChatList from "@/components/dashboard/ChatList";
+import Dashboard from "@/components/dashboard/dashboard";
export const metadata: Metadata = {
title: "Customer Chats",
@@ -9,14 +10,16 @@ export const metadata: Metadata = {
export default function ChatsPage() {
return (
-
-
-
Customer Chats
+
+
+
+
Customer Chats
+
+
+
+
+
-
-
-
-
-
+
);
}
\ No newline at end of file
diff --git a/components/dashboard/ChatDetail.tsx b/components/dashboard/ChatDetail.tsx
index 1eb2637..bf69a43 100644
--- a/components/dashboard/ChatDetail.tsx
+++ b/components/dashboard/ChatDetail.tsx
@@ -62,7 +62,7 @@ export default function ChatDetail({ chatId }: { chatId: string }) {
}
});
- const response = await authAxios.get(`/chats/${chatId}`);
+ const response = await authAxios.get(`/api/chats/${chatId}`);
setChat(response.data);
setLoading(false);
} catch (error) {
@@ -111,7 +111,7 @@ export default function ChatDetail({ chatId }: { chatId: string }) {
}
});
- await authAxios.post(`/chats/${chatId}/message`, {
+ await authAxios.post(`/api/chats/${chatId}/message`, {
content: message
});
diff --git a/components/dashboard/ChatList.tsx b/components/dashboard/ChatList.tsx
index 420473b..112482e 100644
--- a/components/dashboard/ChatList.tsx
+++ b/components/dashboard/ChatList.tsx
@@ -54,13 +54,12 @@ export default function ChatList() {
}
});
- // Get vendor ID from token (assuming JWT with vendorId in the payload)
- // If you can't extract from token, you might need a profile endpoint
- // For now, we'll use a placeholder ID until proper JWT decoding is implemented
- const vendorId = "current"; // Replace with actual ID extraction
+ // First, get vendor info using the /api/auth/me endpoint
+ const vendorResponse = await authAxios.get('/auth/me');
+ const vendorId = vendorResponse.data._id;
- // Fetch vendor's stores
- const storesResponse = await authAxios.get(`/stores/vendor/${vendorId}`);
+ // Fetch vendor's stores using storefront endpoint
+ const storesResponse = await authAxios.get(`/storefront`);
setVendorStores(storesResponse.data);
if (storesResponse.data.length > 0) {
@@ -99,11 +98,12 @@ export default function ChatList() {
}
});
- // Get vendor ID (as above, assuming we have a way to get it)
- const vendorId = "current"; // Replace with actual ID extraction
+ // Get vendor ID from profile
+ const vendorResponse = await authAxios.get('/api/auth/me');
+ const vendorId = vendorResponse.data._id;
// Fetch chats
- const chatsResponse = await authAxios.get(`/chats/vendor/${vendorId}`);
+ const chatsResponse = await authAxios.get(`/api/chats/vendor/${vendorId}`);
// Filter chats by selected store
const filteredChats = chatsResponse.data.filter(
@@ -113,7 +113,7 @@ export default function ChatList() {
setChats(filteredChats);
// Fetch unread counts
- const unreadResponse = await authAxios.get(`/chats/vendor/${vendorId}/unread`);
+ const unreadResponse = await authAxios.get(`/api/chats/vendor/${vendorId}/unread`);
setUnreadCounts(unreadResponse.data);
} catch (error) {
console.error("Error fetching chats:", error);
diff --git a/components/dashboard/ChatNotifications.tsx b/components/dashboard/ChatNotifications.tsx
index 074647e..be53b76 100644
--- a/components/dashboard/ChatNotifications.tsx
+++ b/components/dashboard/ChatNotifications.tsx
@@ -42,8 +42,10 @@ export default function ChatNotifications() {
}
});
- // Get vendor ID (placeholder until proper JWT decoding)
- const vendorId = "current"; // Replace with actual ID extraction
+ // Get vendor ID from profile
+ const vendorResponse = await authAxios.get('/auth/me');
+
+ const vendorId = vendorResponse.data.vendor._id;
const response = await authAxios.get(`/chats/vendor/${vendorId}/unread`);
setUnreadCounts(response.data);
@@ -60,7 +62,7 @@ export default function ChatNotifications() {
await Promise.all(
chatIds.map(async (chatId) => {
try {
- const chatResponse = await authAxios.get(`/chats/${chatId}`);
+ const chatResponse = await authAxios.get(`/api/chats/${chatId}`);
metadata[chatId] = {
buyerId: chatResponse.data.buyerId,
};
diff --git a/components/dashboard/NewChatForm.tsx b/components/dashboard/NewChatForm.tsx
index 0d06398..e536e9b 100644
--- a/components/dashboard/NewChatForm.tsx
+++ b/components/dashboard/NewChatForm.tsx
@@ -41,10 +41,12 @@ export default function NewChatForm() {
}
});
- // Get vendor ID (placeholder until proper JWT decoding)
- const vendorId = "current"; // Replace with actual ID extraction
+ // Get vendor ID from profile
+ const vendorResponse = await authAxios.get('/api/auth/me');
+ const vendorId = vendorResponse.data._id;
- const response = await authAxios.get(`/stores/vendor/${vendorId}`);
+ // Fetch vendor's stores using storefront endpoint
+ const response = await authAxios.get(`/api/storefront`);
setVendorStores(response.data);
if (response.data.length > 0) {
@@ -90,7 +92,7 @@ export default function NewChatForm() {
}
});
- const response = await authAxios.post("/chats/create", {
+ const response = await authAxios.post("/api/chats/create", {
buyerId,
storeId: selectedStore,
initialMessage