-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add Privy logins page to admin dashboard #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
beac422
feat: add Privy logins page to admin dashboard
f2c2539
feat: update admin privy page for latest API response shape
sweetmantech 38a3450
refactor: extract getEmail to lib/privy/getEmail.ts (SRP)
sweetmantech 29216da
refactor: use User type from @privy-io/react-auth SDK instead of cust…
sweetmantech 7f0d694
refactor: extract sub-components from PrivyLoginsPage (SRP)
sweetmantech fe1db69
style: use PrivyUser alias instead of inline import
sweetmantech 7ae551b
fix: define PrivyUser matching raw Management API response (snake_case)
sweetmantech 6b7eefb
fix: use intersection type for PrivyLinkedAccount so address resolves…
sweetmantech 78aeb1a
feat: add Last Seen column to privy logins table
sweetmantech ea114fa
fix: remove duplicate total count, keep only new and active
sweetmantech 2aa2d11
fix: remove Privy DID column from logins table
sweetmantech 87ec01c
refactor: switch to DataTable with sortable Created At and Last Seen …
sweetmantech 231fb4f
fix: use TableSkeleton for loading state instead of text
sweetmantech 8d62c3e
feat: add Last Seen line chart using shadcn/recharts
sweetmantech 4c6a069
fix: use ReactNode type for labelFormatter parameter
sweetmantech 115cf60
fix: add explicit payload prop type for Recharts v3 compatibility
sweetmantech 04b3fee
fix: reinstall chart component via shadcn CLI
sweetmantech 5a5aba8
feat: add chart skeleton for loading state
sweetmantech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import type { Metadata } from "next"; | ||
| import PrivyLoginsPage from "@/components/PrivyLogins/PrivyLoginsPage"; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: "Privy Logins — Recoup Admin", | ||
| }; | ||
|
|
||
| export default function Page() { | ||
| return <PrivyLoginsPage />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export default function ChartSkeleton() { | ||
| return ( | ||
| <div className="mb-6 rounded-lg border p-4"> | ||
| <div className="mb-4 h-4 w-32 animate-pulse rounded bg-muted" /> | ||
| <div className="h-[250px] w-full animate-pulse rounded bg-muted" /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| "use client"; | ||
|
|
||
| import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts"; | ||
| import { | ||
| ChartContainer, | ||
| ChartTooltip, | ||
| ChartTooltipContent, | ||
| type ChartConfig, | ||
| } from "@/components/ui/chart"; | ||
| import type { PrivyUser } from "@/types/privy"; | ||
| import { getLastSeenByDate } from "@/lib/privy/getLastSeenByDate"; | ||
|
|
||
| const chartConfig = { | ||
| count: { | ||
| label: "Last Seen", | ||
| color: "#345A5D", | ||
| }, | ||
| } satisfies ChartConfig; | ||
|
|
||
| interface PrivyLastSeenChartProps { | ||
| logins: PrivyUser[]; | ||
| } | ||
|
|
||
| export default function PrivyLastSeenChart({ logins }: PrivyLastSeenChartProps) { | ||
| const data = getLastSeenByDate(logins); | ||
|
|
||
| if (data.length === 0) return null; | ||
|
|
||
| return ( | ||
| <div className="mb-6 rounded-lg border p-4"> | ||
| <h2 className="mb-4 text-sm font-medium text-gray-700 dark:text-gray-300"> | ||
| Last Seen Activity | ||
| </h2> | ||
| <ChartContainer config={chartConfig} className="h-[250px] w-full"> | ||
| <LineChart data={data} accessibilityLayer> | ||
| <CartesianGrid vertical={false} /> | ||
| <XAxis | ||
| dataKey="date" | ||
| tickLine={false} | ||
| axisLine={false} | ||
| tickMargin={8} | ||
| tickFormatter={(value: string) => { | ||
| const d = new Date(value + "T00:00:00"); | ||
| return d.toLocaleDateString("en-US", { month: "short", day: "numeric" }); | ||
| }} | ||
| /> | ||
| <YAxis tickLine={false} axisLine={false} allowDecimals={false} /> | ||
| <ChartTooltip | ||
| content={ | ||
| <ChartTooltipContent | ||
| labelFormatter={(value) => { | ||
| const d = new Date(String(value) + "T00:00:00"); | ||
| return d.toLocaleDateString("en-US", { month: "long", day: "numeric", year: "numeric" }); | ||
| }} | ||
| /> | ||
| } | ||
| /> | ||
| <Line | ||
| dataKey="count" | ||
| type="monotone" | ||
| stroke="var(--color-count)" | ||
| strokeWidth={2} | ||
| dot={{ fill: "var(--color-count)", r: 4 }} | ||
| /> | ||
| </LineChart> | ||
| </ChartContainer> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
| import PageBreadcrumb from "@/components/Sandboxes/PageBreadcrumb"; | ||
| import ApiDocsLink from "@/components/ApiDocsLink"; | ||
| import { usePrivyLogins } from "@/hooks/usePrivyLogins"; | ||
| import PrivyLoginsTable from "@/components/PrivyLogins/PrivyLoginsTable"; | ||
| import PrivyPeriodSelector from "@/components/PrivyLogins/PrivyPeriodSelector"; | ||
| import PrivyLoginsStats from "@/components/PrivyLogins/PrivyLoginsStats"; | ||
| import TableSkeleton from "@/components/Sandboxes/TableSkeleton"; | ||
| import ChartSkeleton from "@/components/PrivyLogins/ChartSkeleton"; | ||
| import PrivyLastSeenChart from "@/components/PrivyLogins/PrivyLastSeenChart"; | ||
| import type { PrivyLoginsPeriod } from "@/types/privy"; | ||
|
|
||
| export default function PrivyLoginsPage() { | ||
| const [period, setPeriod] = useState<PrivyLoginsPeriod>("all"); | ||
| const { data, isLoading, error } = usePrivyLogins(period); | ||
|
|
||
| return ( | ||
| <main className="mx-auto max-w-6xl px-4 py-10"> | ||
| <div className="mb-6 flex items-start justify-between"> | ||
| <div> | ||
| <PageBreadcrumb current="Privy Logins" /> | ||
| <h1 className="text-2xl font-bold tracking-tight text-gray-900 dark:text-gray-100"> | ||
| Privy Logins | ||
| </h1> | ||
| <p className="mt-1 text-sm text-gray-500 dark:text-gray-400"> | ||
| User sign-ins via Privy, grouped by time period. | ||
| </p> | ||
| </div> | ||
| <ApiDocsLink path="admins/privy" /> | ||
| </div> | ||
|
|
||
| <div className="mb-6 flex items-center gap-4"> | ||
| <PrivyPeriodSelector period={period} onPeriodChange={setPeriod} /> | ||
| {data && <PrivyLoginsStats data={data} />} | ||
| </div> | ||
|
|
||
| {isLoading && ( | ||
| <> | ||
| <ChartSkeleton /> | ||
| <TableSkeleton columns={["Email", "Created At", "Last Seen"]} /> | ||
| </> | ||
| )} | ||
|
|
||
| {error && ( | ||
| <div className="rounded-md bg-red-50 p-4 text-sm text-red-700 dark:bg-red-900/20 dark:text-red-400"> | ||
| {error instanceof Error ? error.message : "Failed to load Privy logins"} | ||
| </div> | ||
| )} | ||
|
|
||
| {!isLoading && !error && data && data.logins.length === 0 && ( | ||
| <div className="flex items-center justify-center py-12 text-sm text-gray-400"> | ||
| No logins found for this period. | ||
| </div> | ||
| )} | ||
|
|
||
| {!isLoading && !error && data && data.logins.length > 0 && ( | ||
| <> | ||
| <PrivyLastSeenChart logins={data.logins} /> | ||
| <PrivyLoginsTable logins={data.logins} /> | ||
| </> | ||
| )} | ||
| </main> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { PrivyLoginsResponse } from "@/types/privy"; | ||
|
|
||
| interface PrivyLoginsStatsProps { | ||
| data: PrivyLoginsResponse; | ||
| } | ||
|
|
||
| export default function PrivyLoginsStats({ data }: PrivyLoginsStatsProps) { | ||
| return ( | ||
| <div className="flex gap-4 text-sm text-gray-500 dark:text-gray-400"> | ||
| <span> | ||
| <span className="font-semibold text-gray-900 dark:text-gray-100">{data.total_new}</span> new | ||
| </span> | ||
| <span> | ||
| <span className="font-semibold text-gray-900 dark:text-gray-100">{data.total_active}</span> active | ||
| </span> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| flexRender, | ||
| getCoreRowModel, | ||
| getSortedRowModel, | ||
| useReactTable, | ||
| type SortingState, | ||
| } from "@tanstack/react-table"; | ||
| import { useState } from "react"; | ||
| import { | ||
| Table, | ||
| TableBody, | ||
| TableCell, | ||
| TableHead, | ||
| TableHeader, | ||
| TableRow, | ||
| } from "@/components/ui/table"; | ||
| import { privyLoginsColumns } from "@/components/PrivyLogins/privyLoginsColumns"; | ||
| import type { PrivyUser } from "@/types/privy"; | ||
|
|
||
| interface PrivyLoginsTableProps { | ||
| logins: PrivyUser[]; | ||
| } | ||
|
|
||
| export default function PrivyLoginsTable({ logins }: PrivyLoginsTableProps) { | ||
| const [sorting, setSorting] = useState<SortingState>([ | ||
| { id: "created_at", desc: true }, | ||
| ]); | ||
|
|
||
| const table = useReactTable({ | ||
| data: logins, | ||
| columns: privyLoginsColumns, | ||
| state: { sorting }, | ||
| onSortingChange: setSorting, | ||
| getCoreRowModel: getCoreRowModel(), | ||
| getSortedRowModel: getSortedRowModel(), | ||
| }); | ||
|
|
||
| return ( | ||
| <div className="rounded-lg border"> | ||
| <Table> | ||
| <TableHeader> | ||
| {table.getHeaderGroups().map((headerGroup) => ( | ||
| <TableRow key={headerGroup.id}> | ||
| {headerGroup.headers.map((header) => ( | ||
| <TableHead key={header.id}> | ||
| {header.isPlaceholder | ||
| ? null | ||
| : flexRender(header.column.columnDef.header, header.getContext())} | ||
| </TableHead> | ||
| ))} | ||
| </TableRow> | ||
| ))} | ||
| </TableHeader> | ||
| <TableBody> | ||
| {table.getRowModel().rows.length ? ( | ||
| table.getRowModel().rows.map((row) => ( | ||
| <TableRow key={row.id}> | ||
| {row.getVisibleCells().map((cell) => ( | ||
| <TableCell key={cell.id}> | ||
| {flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
| </TableCell> | ||
| ))} | ||
| </TableRow> | ||
| )) | ||
| ) : ( | ||
| <TableRow> | ||
| <TableCell colSpan={privyLoginsColumns.length} className="h-24 text-center"> | ||
| No results. | ||
| </TableCell> | ||
| </TableRow> | ||
| )} | ||
| </TableBody> | ||
| </Table> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { PrivyLoginsPeriod } from "@/types/privy"; | ||
|
|
||
| const PERIODS: { value: PrivyLoginsPeriod; label: string }[] = [ | ||
| { value: "all", label: "All Time" }, | ||
| { value: "daily", label: "Daily" }, | ||
| { value: "weekly", label: "Weekly" }, | ||
| { value: "monthly", label: "Monthly" }, | ||
| ]; | ||
|
|
||
| interface PrivyPeriodSelectorProps { | ||
| period: PrivyLoginsPeriod; | ||
| onPeriodChange: (period: PrivyLoginsPeriod) => void; | ||
| } | ||
|
|
||
| export default function PrivyPeriodSelector({ period, onPeriodChange }: PrivyPeriodSelectorProps) { | ||
| return ( | ||
| <div className="flex rounded-lg border bg-white dark:bg-gray-900 overflow-hidden"> | ||
| {PERIODS.map(({ value, label }) => ( | ||
| <button | ||
| key={value} | ||
| onClick={() => onPeriodChange(value)} | ||
| className={`px-4 py-2 text-sm font-medium transition-colors ${ | ||
| period === value | ||
| ? "bg-gray-900 text-white dark:bg-white dark:text-gray-900" | ||
| : "text-gray-600 hover:bg-gray-50 dark:text-gray-400 dark:hover:bg-gray-800" | ||
| }`} | ||
| > | ||
| {label} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { type ColumnDef } from "@tanstack/react-table"; | ||
| import { SortableHeader } from "@/components/SandboxOrgs/SortableHeader"; | ||
| import { getEmail } from "@/lib/privy/getEmail"; | ||
| import { getLastSeen } from "@/lib/privy/getLastSeen"; | ||
| import type { PrivyUser } from "@/types/privy"; | ||
|
|
||
| export const privyLoginsColumns: ColumnDef<PrivyUser>[] = [ | ||
| { | ||
| id: "email", | ||
| accessorFn: (row) => getEmail(row), | ||
| header: "Email", | ||
| cell: ({ getValue }) => { | ||
| const email = getValue<string | null>(); | ||
| return email ?? <span className="text-gray-400 italic">No email</span>; | ||
| }, | ||
| }, | ||
| { | ||
| id: "created_at", | ||
| accessorKey: "created_at", | ||
| header: ({ column }) => <SortableHeader column={column} label="Created At" />, | ||
| cell: ({ getValue }) => new Date(getValue<number>() * 1000).toLocaleString(), | ||
| sortingFn: "basic", | ||
| }, | ||
| { | ||
| id: "last_seen", | ||
| accessorFn: (row) => getLastSeen(row), | ||
| header: ({ column }) => <SortableHeader column={column} label="Last Seen" />, | ||
| cell: ({ getValue }) => { | ||
| const ts = getValue<number | null>(); | ||
| return ts ? new Date(ts * 1000).toLocaleString() : <span className="text-gray-400 italic">Never</span>; | ||
| }, | ||
| sortingFn: "basic", | ||
| }, | ||
| ]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.