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

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

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

View File

@@ -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,
};

View File

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