This commit is contained in:
NotII
2025-03-03 21:30:36 +00:00
parent 3282051671
commit c70828ddcf
4 changed files with 53 additions and 26 deletions

View File

@@ -54,9 +54,17 @@ export default function ChatList() {
}
});
// First, get vendor info using the /api/auth/me endpoint
// First, get vendor info using the /auth/me endpoint
const vendorResponse = await authAxios.get('/auth/me');
const vendorId = vendorResponse.data._id;
// Access correct property - the vendor ID is in vendor._id
const vendorId = vendorResponse.data.vendor?._id;
if (!vendorId) {
console.error("Vendor ID not found in profile response:", vendorResponse.data);
toast.error("Could not retrieve vendor information");
return;
}
// Fetch vendor's stores using storefront endpoint
const storesResponse = await authAxios.get(`/storefront`);
@@ -99,11 +107,19 @@ export default function ChatList() {
});
// Get vendor ID from profile
const vendorResponse = await authAxios.get('/api/auth/me');
const vendorId = vendorResponse.data._id;
const vendorResponse = await authAxios.get('/auth/me');
// Access correct property - the vendor ID is in vendor._id
const vendorId = vendorResponse.data.vendor?._id;
if (!vendorId) {
console.error("Vendor ID not found in profile response:", vendorResponse.data);
toast.error("Could not retrieve vendor information");
return;
}
// Fetch chats
const chatsResponse = await authAxios.get(`/api/chats/vendor/${vendorId}`);
const chatsResponse = await authAxios.get(`/chats/vendor/${vendorId}`);
// Filter chats by selected store
const filteredChats = chatsResponse.data.filter(
@@ -113,7 +129,7 @@ export default function ChatList() {
setChats(filteredChats);
// Fetch unread counts
const unreadResponse = await authAxios.get(`/api/chats/vendor/${vendorId}/unread`);
const unreadResponse = await authAxios.get(`/chats/vendor/${vendorId}/unread`);
setUnreadCounts(unreadResponse.data);
} catch (error) {
console.error("Error fetching chats:", error);