whoop
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
import ChatDetail from "@/components/dashboard/ChatDetail";
|
import ChatDetail from "@/components/dashboard/ChatDetail";
|
||||||
|
import Dashboard from "@/components/dashboard/dashboard";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Chat Conversation",
|
title: "Chat Conversation",
|
||||||
@@ -9,10 +10,12 @@ export const metadata: Metadata = {
|
|||||||
|
|
||||||
export default function ChatDetailPage({ params }: { params: { id: string } }) {
|
export default function ChatDetailPage({ params }: { params: { id: string } }) {
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto py-6 space-y-6">
|
<Dashboard>
|
||||||
<div className="grid grid-cols-1 gap-6">
|
<div className="container mx-auto py-6 space-y-6">
|
||||||
<ChatDetail chatId={params.id} />
|
<div className="grid grid-cols-1 gap-6">
|
||||||
|
<ChatDetail chatId={params.id} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Dashboard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
import NewChatForm from "@/components/dashboard/NewChatForm";
|
import NewChatForm from "@/components/dashboard/NewChatForm";
|
||||||
|
import Dashboard from "@/components/dashboard/dashboard";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Start New Chat",
|
title: "Start New Chat",
|
||||||
@@ -9,10 +10,12 @@ export const metadata: Metadata = {
|
|||||||
|
|
||||||
export default function NewChatPage() {
|
export default function NewChatPage() {
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto py-6 space-y-6">
|
<Dashboard>
|
||||||
<div className="grid grid-cols-1 gap-6">
|
<div className="container mx-auto py-6 space-y-6">
|
||||||
<NewChatForm />
|
<div className="grid grid-cols-1 gap-6">
|
||||||
|
<NewChatForm />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Dashboard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
import ChatList from "@/components/dashboard/ChatList";
|
import ChatList from "@/components/dashboard/ChatList";
|
||||||
|
import Dashboard from "@/components/dashboard/dashboard";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Customer Chats",
|
title: "Customer Chats",
|
||||||
@@ -9,14 +10,16 @@ export const metadata: Metadata = {
|
|||||||
|
|
||||||
export default function ChatsPage() {
|
export default function ChatsPage() {
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto py-6 space-y-6">
|
<Dashboard>
|
||||||
<div className="flex items-center justify-between">
|
<div className="container mx-auto py-6 space-y-6">
|
||||||
<h1 className="text-3xl font-bold tracking-tight">Customer Chats</h1>
|
<div className="flex items-center justify-between">
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">Customer Chats</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 gap-6">
|
||||||
|
<ChatList />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</Dashboard>
|
||||||
<div className="grid grid-cols-1 gap-6">
|
|
||||||
<ChatList />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -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);
|
setChat(response.data);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error) {
|
} 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
|
content: message
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -54,13 +54,12 @@ export default function ChatList() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get vendor ID from token (assuming JWT with vendorId in the payload)
|
// First, get vendor info using the /api/auth/me endpoint
|
||||||
// If you can't extract from token, you might need a profile endpoint
|
const vendorResponse = await authAxios.get('/auth/me');
|
||||||
// For now, we'll use a placeholder ID until proper JWT decoding is implemented
|
const vendorId = vendorResponse.data._id;
|
||||||
const vendorId = "current"; // Replace with actual ID extraction
|
|
||||||
|
|
||||||
// Fetch vendor's stores
|
// Fetch vendor's stores using storefront endpoint
|
||||||
const storesResponse = await authAxios.get(`/stores/vendor/${vendorId}`);
|
const storesResponse = await authAxios.get(`/storefront`);
|
||||||
setVendorStores(storesResponse.data);
|
setVendorStores(storesResponse.data);
|
||||||
|
|
||||||
if (storesResponse.data.length > 0) {
|
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)
|
// Get vendor ID from profile
|
||||||
const vendorId = "current"; // Replace with actual ID extraction
|
const vendorResponse = await authAxios.get('/api/auth/me');
|
||||||
|
const vendorId = vendorResponse.data._id;
|
||||||
|
|
||||||
// Fetch chats
|
// Fetch chats
|
||||||
const chatsResponse = await authAxios.get(`/chats/vendor/${vendorId}`);
|
const chatsResponse = await authAxios.get(`/api/chats/vendor/${vendorId}`);
|
||||||
|
|
||||||
// Filter chats by selected store
|
// Filter chats by selected store
|
||||||
const filteredChats = chatsResponse.data.filter(
|
const filteredChats = chatsResponse.data.filter(
|
||||||
@@ -113,7 +113,7 @@ export default function ChatList() {
|
|||||||
setChats(filteredChats);
|
setChats(filteredChats);
|
||||||
|
|
||||||
// Fetch unread counts
|
// 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);
|
setUnreadCounts(unreadResponse.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching chats:", error);
|
console.error("Error fetching chats:", error);
|
||||||
|
|||||||
@@ -42,8 +42,10 @@ export default function ChatNotifications() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get vendor ID (placeholder until proper JWT decoding)
|
// Get vendor ID from profile
|
||||||
const vendorId = "current"; // Replace with actual ID extraction
|
const vendorResponse = await authAxios.get('/auth/me');
|
||||||
|
|
||||||
|
const vendorId = vendorResponse.data.vendor._id;
|
||||||
|
|
||||||
const response = await authAxios.get(`/chats/vendor/${vendorId}/unread`);
|
const response = await authAxios.get(`/chats/vendor/${vendorId}/unread`);
|
||||||
setUnreadCounts(response.data);
|
setUnreadCounts(response.data);
|
||||||
@@ -60,7 +62,7 @@ export default function ChatNotifications() {
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
chatIds.map(async (chatId) => {
|
chatIds.map(async (chatId) => {
|
||||||
try {
|
try {
|
||||||
const chatResponse = await authAxios.get(`/chats/${chatId}`);
|
const chatResponse = await authAxios.get(`/api/chats/${chatId}`);
|
||||||
metadata[chatId] = {
|
metadata[chatId] = {
|
||||||
buyerId: chatResponse.data.buyerId,
|
buyerId: chatResponse.data.buyerId,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,10 +41,12 @@ export default function NewChatForm() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get vendor ID (placeholder until proper JWT decoding)
|
// Get vendor ID from profile
|
||||||
const vendorId = "current"; // Replace with actual ID extraction
|
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);
|
setVendorStores(response.data);
|
||||||
|
|
||||||
if (response.data.length > 0) {
|
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,
|
buyerId,
|
||||||
storeId: selectedStore,
|
storeId: selectedStore,
|
||||||
initialMessage
|
initialMessage
|
||||||
|
|||||||
Reference in New Issue
Block a user