whoop
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React from "react";
|
||||
import { Metadata } from "next";
|
||||
import ChatDetail from "@/components/dashboard/ChatDetail";
|
||||
import Dashboard from "@/components/dashboard/dashboard";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Chat Conversation",
|
||||
@@ -9,10 +10,12 @@ export const metadata: Metadata = {
|
||||
|
||||
export default function ChatDetailPage({ params }: { params: { id: string } }) {
|
||||
return (
|
||||
<Dashboard>
|
||||
<div className="container mx-auto py-6 space-y-6">
|
||||
<div className="grid grid-cols-1 gap-6">
|
||||
<ChatDetail chatId={params.id} />
|
||||
</div>
|
||||
</div>
|
||||
</Dashboard>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import React from "react";
|
||||
import { Metadata } from "next";
|
||||
import NewChatForm from "@/components/dashboard/NewChatForm";
|
||||
import Dashboard from "@/components/dashboard/dashboard";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Start New Chat",
|
||||
@@ -9,10 +10,12 @@ export const metadata: Metadata = {
|
||||
|
||||
export default function NewChatPage() {
|
||||
return (
|
||||
<Dashboard>
|
||||
<div className="container mx-auto py-6 space-y-6">
|
||||
<div className="grid grid-cols-1 gap-6">
|
||||
<NewChatForm />
|
||||
</div>
|
||||
</div>
|
||||
</Dashboard>
|
||||
);
|
||||
}
|
||||
@@ -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,6 +10,7 @@ export const metadata: Metadata = {
|
||||
|
||||
export default function ChatsPage() {
|
||||
return (
|
||||
<Dashboard>
|
||||
<div className="container mx-auto py-6 space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-3xl font-bold tracking-tight">Customer Chats</h1>
|
||||
@@ -18,5 +20,6 @@ export default function ChatsPage() {
|
||||
<ChatList />
|
||||
</div>
|
||||
</div>
|
||||
</Dashboard>
|
||||
);
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user