|
| 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, ExternalLink } 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"; |
| 21 | + sourceUrl?: string; |
| 22 | + summary?: string; |
| 23 | + topics?: string[]; |
| 24 | + collectedAt?: string; |
| 25 | +} |
| 26 | + |
| 27 | +const statusConfig: Record<string, { label: string; className: string }> = { |
| 28 | + new: { |
| 29 | + label: "New", |
| 30 | + className: |
| 31 | + "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: |
| 36 | + "bg-green-100 text-green-800 hover:bg-green-100 dark:bg-green-900 dark:text-green-300", |
| 37 | + }, |
| 38 | + rejected: { |
| 39 | + label: "Rejected", |
| 40 | + className: |
| 41 | + "bg-red-100 text-red-800 hover:bg-red-100 dark:bg-red-900 dark:text-red-300", |
| 42 | + }, |
| 43 | +}; |
| 44 | + |
| 45 | +function StatusBadge({ status }: { status: string }) { |
| 46 | + const config = statusConfig[status] ?? { label: status, className: "" }; |
| 47 | + return ( |
| 48 | + <Badge variant="outline" className={config.className}> |
| 49 | + {config.label} |
| 50 | + </Badge> |
| 51 | + ); |
| 52 | +} |
| 53 | + |
| 54 | +function formatDate(dateString: string) { |
| 55 | + return new Date(dateString).toLocaleDateString("en-US", { |
| 56 | + month: "short", |
| 57 | + day: "numeric", |
| 58 | + year: "numeric", |
| 59 | + }); |
| 60 | +} |
| 61 | + |
| 62 | +function truncateUrl(url: string, maxLength = 30) { |
| 63 | + try { |
| 64 | + const parsed = new URL(url); |
| 65 | + const display = parsed.hostname + parsed.pathname; |
| 66 | + return display.length > maxLength |
| 67 | + ? display.slice(0, maxLength) + "\u2026" |
| 68 | + : display; |
| 69 | + } catch { |
| 70 | + return url.length > maxLength ? url.slice(0, maxLength) + "\u2026" : url; |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +export function ContentIdeasTable({ ideas }: { ideas: ContentIdea[] }) { |
| 75 | + if (ideas.length === 0) { |
| 76 | + return ( |
| 77 | + <div className="flex flex-col items-center justify-center rounded-lg border border-dashed p-12 text-center"> |
| 78 | + <Lightbulb className="h-12 w-12 text-muted-foreground/50" /> |
| 79 | + <h3 className="mt-4 text-lg font-semibold">No content ideas yet</h3> |
| 80 | + <p className="mt-2 text-sm text-muted-foreground"> |
| 81 | + Content ideas will appear here once the ideation cron starts |
| 82 | + running. |
| 83 | + </p> |
| 84 | + </div> |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + return ( |
| 89 | + <div className="rounded-lg border"> |
| 90 | + <Table> |
| 91 | + <TableHeader> |
| 92 | + <TableRow> |
| 93 | + <TableHead>Title</TableHead> |
| 94 | + <TableHead>Status</TableHead> |
| 95 | + <TableHead>Source</TableHead> |
| 96 | + <TableHead>Topics</TableHead> |
| 97 | + <TableHead>Collected</TableHead> |
| 98 | + <TableHead className="text-right">Actions</TableHead> |
| 99 | + </TableRow> |
| 100 | + </TableHeader> |
| 101 | + <TableBody> |
| 102 | + {ideas.map((idea) => ( |
| 103 | + <TableRow key={idea._id}> |
| 104 | + <TableCell className="font-medium"> |
| 105 | + {idea.title || "Untitled"} |
| 106 | + </TableCell> |
| 107 | + <TableCell> |
| 108 | + <StatusBadge status={idea.status} /> |
| 109 | + </TableCell> |
| 110 | + <TableCell> |
| 111 | + {idea.sourceUrl ? ( |
| 112 | + <a |
| 113 | + href={idea.sourceUrl} |
| 114 | + target="_blank" |
| 115 | + rel="noopener noreferrer" |
| 116 | + className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground" |
| 117 | + > |
| 118 | + {truncateUrl(idea.sourceUrl)} |
| 119 | + <ExternalLink className="h-3 w-3" /> |
| 120 | + </a> |
| 121 | + ) : ( |
| 122 | + <span className="text-muted-foreground">\u2014</span> |
| 123 | + )} |
| 124 | + </TableCell> |
| 125 | + <TableCell> |
| 126 | + {idea.topics && idea.topics.length > 0 ? ( |
| 127 | + <div className="flex flex-wrap gap-1"> |
| 128 | + {idea.topics.slice(0, 3).map((topic) => ( |
| 129 | + <Badge key={topic} variant="secondary" className="text-xs"> |
| 130 | + {topic} |
| 131 | + </Badge> |
| 132 | + ))} |
| 133 | + {idea.topics.length > 3 && ( |
| 134 | + <Badge variant="secondary" className="text-xs"> |
| 135 | + +{idea.topics.length - 3} |
| 136 | + </Badge> |
| 137 | + )} |
| 138 | + </div> |
| 139 | + ) : ( |
| 140 | + <span className="text-muted-foreground">\u2014</span> |
| 141 | + )} |
| 142 | + </TableCell> |
| 143 | + <TableCell className="text-muted-foreground"> |
| 144 | + {formatDate(idea.collectedAt || idea._createdAt)} |
| 145 | + </TableCell> |
| 146 | + <TableCell className="text-right"> |
| 147 | + {idea.status === "new" && ( |
| 148 | + <div className="flex justify-end gap-2"> |
| 149 | + <form action={approveIdea.bind(null, idea._id)}> |
| 150 | + <Button |
| 151 | + size="sm" |
| 152 | + variant="outline" |
| 153 | + className="text-green-600 hover:text-green-700" |
| 154 | + > |
| 155 | + Approve |
| 156 | + </Button> |
| 157 | + </form> |
| 158 | + <form action={rejectIdea.bind(null, idea._id)}> |
| 159 | + <Button |
| 160 | + size="sm" |
| 161 | + variant="outline" |
| 162 | + className="text-red-600 hover:text-red-700" |
| 163 | + > |
| 164 | + Reject |
| 165 | + </Button> |
| 166 | + </form> |
| 167 | + </div> |
| 168 | + )} |
| 169 | + </TableCell> |
| 170 | + </TableRow> |
| 171 | + ))} |
| 172 | + </TableBody> |
| 173 | + </Table> |
| 174 | + </div> |
| 175 | + ); |
| 176 | +} |
0 commit comments