|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import React, { use, useContext, useEffect, useState } from "react"; |
| 4 | +import { |
| 5 | + Table, |
| 6 | + TableBody, |
| 7 | + TableCell, |
| 8 | + TableHead, |
| 9 | + TableHeader, |
| 10 | + TableRow, |
| 11 | +} from "@/components/ui/table"; |
| 12 | +import { Archive, Delete, MoreHorizontal } from "lucide-react"; |
| 13 | +import { FileListContext } from "@/app/_context/FileListContext"; |
| 14 | +import moment from "moment"; |
| 15 | +import { |
| 16 | + DropdownMenu, |
| 17 | + DropdownMenuContent, |
| 18 | + DropdownMenuItem, |
| 19 | + DropdownMenuSeparator, |
| 20 | + DropdownMenuTrigger, |
| 21 | +} from "@/components/ui/dropdown-menu"; |
| 22 | +import { useKindeBrowserClient } from "@kinde-oss/kinde-auth-nextjs"; |
| 23 | +import { useRouter } from "next/navigation"; |
| 24 | + |
| 25 | +export interface FILE { |
| 26 | + _id: string; |
| 27 | + fileName: string; |
| 28 | + createdBy: string; |
| 29 | + _creationTime: string; |
| 30 | + archieved: boolean; |
| 31 | + teamId: string; |
| 32 | + document: string; |
| 33 | + whiteboard: string; |
| 34 | +} |
| 35 | + |
| 36 | +const DashboardTable = () => { |
| 37 | + const { fileList, setFileList } = useContext(FileListContext); |
| 38 | + const [fileList_, setFileList_] = useState([] as FILE[]); |
| 39 | + const { user } = useKindeBrowserClient(); |
| 40 | + useEffect(() => { |
| 41 | + fileList && setFileList_(fileList); |
| 42 | + console.log(fileList); |
| 43 | + }, [fileList]); |
| 44 | + |
| 45 | + const handleArchive = (id: string) => { |
| 46 | + console.log("archived", id); |
| 47 | + }; |
| 48 | + |
| 49 | + const handleDelete = (id: string) => { |
| 50 | + console.log("deleted", id); |
| 51 | + }; |
| 52 | + |
| 53 | + const router = useRouter(); |
| 54 | + |
| 55 | + return ( |
| 56 | + <div className="mt-8 pl-2 pr-2"> |
| 57 | + <Table className="border-none "> |
| 58 | + <TableHeader className=""> |
| 59 | + <TableRow className="border-white/40 mx-16 hover:bg-transparent"> |
| 60 | + <TableHead className="pl-20 w-[300px]">Name</TableHead> |
| 61 | + <TableHead className="">Location</TableHead> |
| 62 | + <TableHead className="">Author</TableHead> |
| 63 | + <TableHead className="pr-2 w-[100px]">Created</TableHead> |
| 64 | + </TableRow> |
| 65 | + </TableHeader> |
| 66 | + <TableBody> |
| 67 | + {fileList_ && |
| 68 | + fileList_.map((file) => ( |
| 69 | + <TableRow |
| 70 | + onClick={() => { |
| 71 | + router.push(`/workspace/${file._id}`); |
| 72 | + }} |
| 73 | + key={file._id} |
| 74 | + className="mx-16 hover:bg-white/10 cursor-pointer border-neutral-700 hover:text-white" |
| 75 | + > |
| 76 | + <TableCell className="font-medium pl-20"> |
| 77 | + {file.fileName} |
| 78 | + </TableCell> |
| 79 | + <TableCell className=""></TableCell> |
| 80 | + <TableCell className="w-[150px] text-sm"> |
| 81 | + <div> |
| 82 | + <img |
| 83 | + src={ |
| 84 | + user?.picture ?? |
| 85 | + "https://img.freepik.com/free-vector/graphic-designer-man_78370-159.jpg?size=626&ext=jpg&ga=GA1.1.1395880969.1709251200&semt=ais" |
| 86 | + } |
| 87 | + alt="logo" |
| 88 | + className="w-8 h-8 rounded-full object-cover cursor-pointer" |
| 89 | + /> |
| 90 | + </div> |
| 91 | + </TableCell> |
| 92 | + <TableCell className="w-[150px] text-sm"> |
| 93 | + {moment(file._creationTime).format("DD MMM YYYY")} |
| 94 | + </TableCell> |
| 95 | + <TableCell className="pr-2"> |
| 96 | + <DropdownMenu> |
| 97 | + <DropdownMenuTrigger asChild className="outline-none"> |
| 98 | + <div className="p-1 hover:bg-neutral-600 w-fit rounded-sm cursor-pointer"> |
| 99 | + <MoreHorizontal size={16} /> |
| 100 | + </div> |
| 101 | + </DropdownMenuTrigger> |
| 102 | + <DropdownMenuContent className="bg-neutral-800 gap-1 rounded-lg text-white border-neutral-700 w-48 ml-4 mt-2"> |
| 103 | + <DropdownMenuItem |
| 104 | + className="cursor-pointer focus:bg-neutral-700 focus:text-white" |
| 105 | + onClick={() => { |
| 106 | + console.log("clicked"); |
| 107 | + }} |
| 108 | + > |
| 109 | + <Archive size={16} className="mr-2" /> |
| 110 | + Archive |
| 111 | + </DropdownMenuItem> |
| 112 | + <DropdownMenuItem |
| 113 | + className="cursor-pointer focus:bg-red-500 focus:text-white hover:bg-red-500 hover:text-white" |
| 114 | + onClick={() => { |
| 115 | + console.log("clicked"); |
| 116 | + }} |
| 117 | + > |
| 118 | + <Delete size={16} className="mr-2" /> |
| 119 | + Delete |
| 120 | + </DropdownMenuItem> |
| 121 | + </DropdownMenuContent> |
| 122 | + </DropdownMenu> |
| 123 | + </TableCell> |
| 124 | + </TableRow> |
| 125 | + ))} |
| 126 | + </TableBody> |
| 127 | + </Table> |
| 128 | + </div> |
| 129 | + ); |
| 130 | +}; |
| 131 | + |
| 132 | +export default DashboardTable; |
0 commit comments