|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { |
| 4 | + Table, |
| 5 | + TableBody, |
| 6 | + TableCell, |
| 7 | + TableHead, |
| 8 | + TableHeader, |
| 9 | + TableRow, |
| 10 | +} from "@/components/ui/table"; |
| 11 | +import { Badge } from "@/components/ui/badge"; |
| 12 | +import { Button } from "@/components/ui/button"; |
| 13 | +import { Lightbulb } from "lucide-react"; |
| 14 | +import { approveIdea, rejectIdea } from "./actions"; |
| 15 | + |
| 16 | +interface ContentIdea { |
| 17 | + _id: string; |
| 18 | + _createdAt: string; |
| 19 | + title: string; |
| 20 | + status: "new" | "approved" | "rejected" | "published"; |
| 21 | + source?: string; |
| 22 | + category?: string; |
| 23 | +} |
| 24 | + |
| 25 | +const statusConfig: Record< |
| 26 | + string, |
| 27 | + { label: string; className: string } |
| 28 | +> = { |
| 29 | + new: { |
| 30 | + label: "New", |
| 31 | + className: "bg-blue-100 text-blue-800 hover:bg-blue-100 dark:bg-blue-900 dark:text-blue-300", |
| 32 | + }, |
| 33 | + approved: { |
| 34 | + label: "Approved", |
| 35 | + className: "bg-green-100 text-green-800 hover:bg-green-100 dark:bg-green-900 dark:text-green-300", |
| 36 | + }, |
| 37 | + rejected: { |
| 38 | + label: "Rejected", |
| 39 | + className: "bg-red-100 text-red-800 hover:bg-red-100 dark:bg-red-900 dark:text-red-300", |
| 40 | + }, |
| 41 | + published: { |
| 42 | + label: "Published", |
| 43 | + className: "bg-purple-100 text-purple-800 hover:bg-purple-100 dark:bg-purple-900 dark:text-purple-300", |
| 44 | + }, |
| 45 | +}; |
| 46 | + |
| 47 | +function StatusBadge({ status }: { status: string }) { |
| 48 | + const config = statusConfig[status] ?? { |
| 49 | + label: status, |
| 50 | + className: "", |
| 51 | + }; |
| 52 | + return ( |
| 53 | + <Badge variant="outline" className={config.className}> |
| 54 | + {config.label} |
| 55 | + </Badge> |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +function formatDate(dateString: string) { |
| 60 | + return new Date(dateString).toLocaleDateString("en-US", { |
| 61 | + month: "short", |
| 62 | + day: "numeric", |
| 63 | + year: "numeric", |
| 64 | + }); |
| 65 | +} |
| 66 | + |
| 67 | +export function ContentIdeasTable({ ideas }: { ideas: ContentIdea[] }) { |
| 68 | + if (ideas.length === 0) { |
| 69 | + return ( |
| 70 | + <div className="flex flex-col items-center justify-center rounded-lg border border-dashed p-12 text-center"> |
| 71 | + <Lightbulb className="h-12 w-12 text-muted-foreground/50" /> |
| 72 | + <h3 className="mt-4 text-lg font-semibold">No content ideas yet</h3> |
| 73 | + <p className="mt-2 text-sm text-muted-foreground"> |
| 74 | + Content ideas will appear here once they're created in Sanity |
| 75 | + or generated by the automation pipeline. |
| 76 | + </p> |
| 77 | + </div> |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + return ( |
| 82 | + <div className="rounded-lg border"> |
| 83 | + <Table> |
| 84 | + <TableHeader> |
| 85 | + <TableRow> |
| 86 | + <TableHead>Title</TableHead> |
| 87 | + <TableHead>Status</TableHead> |
| 88 | + <TableHead>Source</TableHead> |
| 89 | + <TableHead>Category</TableHead> |
| 90 | + <TableHead>Created</TableHead> |
| 91 | + <TableHead className="text-right">Actions</TableHead> |
| 92 | + </TableRow> |
| 93 | + </TableHeader> |
| 94 | + <TableBody> |
| 95 | + {ideas.map((idea) => ( |
| 96 | + <TableRow key={idea._id}> |
| 97 | + <TableCell className="font-medium"> |
| 98 | + {idea.title || "Untitled"} |
| 99 | + </TableCell> |
| 100 | + <TableCell> |
| 101 | + <StatusBadge status={idea.status} /> |
| 102 | + </TableCell> |
| 103 | + <TableCell className="text-muted-foreground"> |
| 104 | + {idea.source || "\u2014"} |
| 105 | + </TableCell> |
| 106 | + <TableCell className="text-muted-foreground"> |
| 107 | + {idea.category || "\u2014"} |
| 108 | + </TableCell> |
| 109 | + <TableCell className="text-muted-foreground"> |
| 110 | + {formatDate(idea._createdAt)} |
| 111 | + </TableCell> |
| 112 | + <TableCell className="text-right"> |
| 113 | + {idea.status === "new" && ( |
| 114 | + <div className="flex justify-end gap-2"> |
| 115 | + <form action={approveIdea.bind(null, idea._id)}> |
| 116 | + <Button size="sm" variant="outline" className="text-green-600 hover:text-green-700"> |
| 117 | + Approve |
| 118 | + </Button> |
| 119 | + </form> |
| 120 | + <form action={rejectIdea.bind(null, idea._id)}> |
| 121 | + <Button size="sm" variant="outline" className="text-red-600 hover:text-red-700"> |
| 122 | + Reject |
| 123 | + </Button> |
| 124 | + </form> |
| 125 | + </div> |
| 126 | + )} |
| 127 | + </TableCell> |
| 128 | + </TableRow> |
| 129 | + ))} |
| 130 | + </TableBody> |
| 131 | + </Table> |
| 132 | + </div> |
| 133 | + ); |
| 134 | +} |
0 commit comments