This commit is contained in:
NotII
2025-03-03 21:20:58 +00:00
parent f5382d82f6
commit 2fafcb868a
7 changed files with 48 additions and 35 deletions

View File

@@ -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);