|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useState } from "react"; |
| 4 | +import PageBreadcrumb from "@/components/Sandboxes/PageBreadcrumb"; |
| 5 | +import ApiDocsLink from "@/components/ApiDocs/ApiDocsLink"; |
| 6 | +import { useContentSlackTags } from "@/hooks/useContentSlackTags"; |
| 7 | +import ContentSlackTable from "@/components/ContentSlack/ContentSlackTable"; |
| 8 | +import ContentSlackStats from "@/components/ContentSlack/ContentSlackStats"; |
| 9 | +import PeriodSelector from "@/components/Admin/PeriodSelector"; |
| 10 | +import AdminLineChart from "@/components/Admin/AdminLineChart"; |
| 11 | +import TableSkeleton from "@/components/Sandboxes/TableSkeleton"; |
| 12 | +import ChartSkeleton from "@/components/PrivyLogins/ChartSkeleton"; |
| 13 | +import { getTagsByDate } from "@/lib/coding-agent/getTagsByDate"; |
| 14 | +import type { AdminPeriod } from "@/types/admin"; |
| 15 | + |
| 16 | +export default function ContentSlackPage() { |
| 17 | + const [period, setPeriod] = useState<AdminPeriod>("all"); |
| 18 | + const { data, isLoading, error } = useContentSlackTags(period); |
| 19 | + |
| 20 | + const tagsByDate = data |
| 21 | + ? getTagsByDate( |
| 22 | + data.tags.map((t) => ({ |
| 23 | + ...t, |
| 24 | + pull_requests: t.video_links, |
| 25 | + })), |
| 26 | + ) |
| 27 | + : []; |
| 28 | + |
| 29 | + return ( |
| 30 | + <main className="mx-auto max-w-6xl px-4 py-10"> |
| 31 | + <div className="mb-6 flex items-start justify-between"> |
| 32 | + <div> |
| 33 | + <PageBreadcrumb current="Content Agent" /> |
| 34 | + <h1 className="text-2xl font-bold tracking-tight text-gray-900 dark:text-gray-100"> |
| 35 | + Content Agent Usage |
| 36 | + </h1> |
| 37 | + <p className="mt-1 text-sm text-gray-500 dark:text-gray-400"> |
| 38 | + Slack tags to the Content Agent, grouped by time period. |
| 39 | + </p> |
| 40 | + </div> |
| 41 | + <ApiDocsLink path="admins/content-slack-tags" /> |
| 42 | + </div> |
| 43 | + |
| 44 | + <div className="mb-6 flex items-center gap-4"> |
| 45 | + <PeriodSelector period={period} onPeriodChange={setPeriod} /> |
| 46 | + {data && <ContentSlackStats data={data} />} |
| 47 | + </div> |
| 48 | + |
| 49 | + {isLoading && ( |
| 50 | + <> |
| 51 | + <ChartSkeleton /> |
| 52 | + <TableSkeleton columns={["User", "Timestamp", "Prompt", "Video Links"]} /> |
| 53 | + </> |
| 54 | + )} |
| 55 | + |
| 56 | + {error && ( |
| 57 | + <div className="rounded-md bg-red-50 p-4 text-sm text-red-700 dark:bg-red-900/20 dark:text-red-400"> |
| 58 | + {error instanceof Error ? error.message : "Failed to load Content Agent tags"} |
| 59 | + </div> |
| 60 | + )} |
| 61 | + |
| 62 | + {!isLoading && !error && data && data.tags.length === 0 && ( |
| 63 | + <div className="flex items-center justify-center py-12 text-sm text-gray-400"> |
| 64 | + No tags found for this period. |
| 65 | + </div> |
| 66 | + )} |
| 67 | + |
| 68 | + {!isLoading && !error && data && data.tags.length > 0 && ( |
| 69 | + <> |
| 70 | + <AdminLineChart |
| 71 | + title="Tags & Videos Over Time" |
| 72 | + data={tagsByDate.map((d) => ({ date: d.date, count: d.count }))} |
| 73 | + label="Tags" |
| 74 | + secondLine={{ |
| 75 | + data: tagsByDate.map((d) => ({ date: d.date, count: d.pull_request_count })), |
| 76 | + label: "Tags with Videos", |
| 77 | + }} |
| 78 | + /> |
| 79 | + <ContentSlackTable tags={data.tags} /> |
| 80 | + </> |
| 81 | + )} |
| 82 | + </main> |
| 83 | + ); |
| 84 | +} |
0 commit comments