diff --git a/app/dashboard/chats/page.tsx b/app/dashboard/chats/page.tsx index d431f38..b42434e 100644 --- a/app/dashboard/chats/page.tsx +++ b/app/dashboard/chats/page.tsx @@ -1,24 +1,36 @@ -import React from "react"; -import { Metadata } from "next"; +"use client"; + +import { useEffect } from "react"; +import { useRouter } from "next/navigation"; import ChatList from "@/components/dashboard/ChatList"; import Dashboard from "@/components/dashboard/dashboard"; - -export const metadata: Metadata = { - title: "Customer Chats", - description: "Manage conversations with your customers", -}; +import { MessageCircle } from "lucide-react"; export default function ChatsPage() { + const router = useRouter(); + + useEffect(() => { + const authToken = document.cookie + .split("; ") + .find((row) => row.startsWith("Authorization=")) + ?.split("=")[1]; + + if (!authToken) { + router.push("/login"); + } + }, [router]); + return ( -
+
-

Customer Chats

+

+ + Customer Chats +

-
- -
+
); diff --git a/components/dashboard/ChatList.tsx b/components/dashboard/ChatList.tsx index 5037abc..8deb307 100644 --- a/components/dashboard/ChatList.tsx +++ b/components/dashboard/ChatList.tsx @@ -2,11 +2,33 @@ import React, { useState, useEffect, useRef } from "react"; import { useRouter } from "next/navigation"; -import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { formatDistanceToNow } from "date-fns"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { + Plus, + MessageCircle, + Loader2, + RefreshCw, + ChevronLeft, + ChevronRight +} from "lucide-react"; import axios from "axios"; import { toast } from "sonner"; import { getCookie } from "@/lib/client-utils"; @@ -260,91 +282,127 @@ export default function ChatList() { } return ( - - - - Customer Chats - - - {vendorStores.length === 0 ? ( -
- No store available. Please create a store first. -
- ) : vendorStores.length === 1 ? ( -
- {vendorStores[0].name} -
- ) : ( -
- - setSelectedStore(value)} + > + + + + + All Stores {vendorStores.map((store) => ( - + ))} - -
- )} -
- - {chats.length === 0 ? ( -
-
- - - -
-

No chats available

-

- There are no customer conversations for this store yet. -

- -
- ) : ( -
- {chats.map((chat) => ( -
handleChatClick(chat._id)} - > -
- - - {chat.buyerId.slice(0, 2).toUpperCase()} - - -
-

Customer {chat.buyerId.slice(-4)}

-

- {formatDistanceToNow(new Date(chat.lastUpdated), { addSuffix: true })} -

+ + + + +
+ + +
+ +
+ + + + Customer + Last Activity + Status + Actions + + + + {loading ? ( + + + + + + ) : chats.length === 0 ? ( + + +
+ +

No chats found

- - {unreadCounts.chatCounts[chat._id] > 0 && ( - - {unreadCounts.chatCounts[chat._id]} unread - - )} - - ))} - - )} - - +
+
+ ) : ( + chats.map((chat) => ( + handleChatClick(chat._id)} + > + +
+ + + {chat.buyerId?.slice(0, 2).toUpperCase() || 'CU'} + + +
+
Customer {chat.buyerId.slice(0, 4)}
+ {chat.orderId && ( +
+ Order #{chat.orderId} +
+ )} +
+
+
+ + {formatDistanceToNow(new Date(chat.lastUpdated), { addSuffix: true })} + + + {unreadCounts.chatCounts[chat._id] > 0 ? ( + + {unreadCounts.chatCounts[chat._id]} new + + ) : ( + Read + )} + + + + +
+ )) + )} +
+
+
+
); } \ No newline at end of file