Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
10ce3fc
chore: add shadcn dependency to package.json
unclesp1d3r Jul 4, 2026
9027f32
chore: add .mcp.json configuration for shadcn server
unclesp1d3r Jul 4, 2026
1bdc4ef
feat: add shared data-table with view controls and roll-up grouping f…
unclesp1d3r Jul 5, 2026
eccff1e
feat: update shared data-table plan to reflect implementation readine…
unclesp1d3r Jul 5, 2026
2afded0
feat(tables): add pure grouping engine and key selectors
unclesp1d3r Jul 5, 2026
544c224
feat(tables): add shared headless DataTable wrapper foundation
unclesp1d3r Jul 5, 2026
5dc2f64
docs(plan): implementation-ready data-table view-controls plan
unclesp1d3r Jul 5, 2026
f964204
feat(tables): add view-state persistence hook with no-flash restore
unclesp1d3r Jul 5, 2026
4e06d46
feat(tables): migrate users table onto shared DataTable; fix React Co…
unclesp1d3r Jul 5, 2026
c2d4101
feat(tables): add grouped table view (collapse, Motion, borrowed sect…
unclesp1d3r Jul 5, 2026
76ae5ba
feat(tables): adopt shadcn data-table; migrate all tables; retire old…
unclesp1d3r Jul 5, 2026
c8e5912
Merge branch 'main' into 36-roll-up-identical-magazine-types-group-by…
unclesp1d3r Jul 5, 2026
14aa2da
fix(tables): deep-merge persisted view state one level, preserving ar…
unclesp1d3r Jul 5, 2026
de44737
fix(ci): activate group expand via keyboard to avoid flaky pointer ac…
unclesp1d3r Jul 5, 2026
4636574
fix(ci): raise table-grouping e2e timeout for slower CI runners
unclesp1d3r Jul 5, 2026
a2dd5c6
fix(tables): drop group-expand height animation to prevent CI main-th…
unclesp1d3r Jul 5, 2026
8a45cb8
fix(tables): use one scroll container for grouped members, not per-ta…
unclesp1d3r Jul 5, 2026
4663a3e
fix(tables): stabilize grouped-view table data to break autoReset ren…
unclesp1d3r Jul 5, 2026
ab113e4
fix(tables): stabilize users columns; reconcile shadcn radius scale
unclesp1d3r Jul 5, 2026
45bbb0f
Address PR review feedback (#48)
unclesp1d3r Jul 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mcpServers": {
"shadcn": {
"command": "npx",
"args": ["shadcn@latest", "mcp"]
}
}
}
142 changes: 99 additions & 43 deletions app/(admin)/users/admin-users.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
"use client";

import { useId, useRef, useState, useTransition } from "react";
import {
useCallback,
useId,
useMemo,
useRef,
useState,
useTransition,
} from "react";
import { Button } from "@/components/ui/button";
import { DataTable } from "@/components/ui/data-table/data-table";
import {
ACTIONS_COLUMN_ID,
type ColumnDef,
createDefaultTableViewState,
} from "@/components/ui/data-table/types";
import { Badge, Callout } from "@/components/ui/feedback";
import { Field } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Card } from "@/components/ui/surface";
import { DataTable, TD, TH, THead, TRow } from "@/components/ui/table";
import { useTableViewState } from "@/hooks/use-table-view-state";
import { createAccountAction, setAccountDisabledAction } from "./actions";

export interface AdminUserRow {
Expand Down Expand Up @@ -45,13 +58,88 @@ export function AdminUsers({ users }: { users: AdminUserRow[] }) {
});
}

function onToggleDisabled(user: AdminUserRow) {
const onToggleDisabled = useCallback((user: AdminUserRow) => {
startTransition(async () => {
const result = await setAccountDisabledAction(user.id, !user.banned);
if (!result.ok)
setFeedback({ tone: "danger", text: result.error ?? "Update failed." });
});
}
}, []);

const columns = useMemo<ColumnDef<AdminUserRow>[]>(
() => [
{
accessorKey: "email",
header: "Email",
meta: { label: "Email" },
cell: ({ getValue }) => (
<span className="font-mono text-xs">{getValue<string>()}</span>
),
},
{
accessorKey: "name",
header: "Name",
meta: { label: "Name" },
},
{
accessorKey: "role",
header: "Role",
meta: { label: "Role" },
cell: ({ getValue }) => {
const role = getValue<string>();
return (
<Badge tone={role === "admin" ? "blaze" : "neutral"}>{role}</Badge>
);
},
},
{
accessorKey: "banned",
id: "status",
header: "Status",
meta: { label: "Status" },
cell: ({ getValue }) =>
getValue<boolean>() ? (
<Badge tone="danger">disabled</Badge>
) : (
<Badge tone="ok">active</Badge>
),
},
{
id: ACTIONS_COLUMN_ID,
header: () => <span className="sr-only">Actions</span>,
enableSorting: false,
enableHiding: false,
cell: ({ row }) => {
const user = row.original;
return (
<div className="flex justify-end">
<Button
variant={user.banned ? "secondary" : "danger"}
size="sm"
disabled={user.role === "admin"}
onClick={() => onToggleDisabled(user)}
>
{user.banned ? "Enable" : "Disable"}
</Button>
</div>
);
},
},
],
// Deliberately NOT depending on `pending`: it flips on every toggle, and a
// fresh `columns` array rebuilds every cell's function identity, which
// makes flexRender remount every cell (tearing down the just-clicked
// button). `onToggleDisabled` is a stable useCallback. The dropped
// `pending` disable was only an invisible re-click guard, and a rapid
// double-toggle is idempotent (both compute `!user.banned` from the same
// row) — same stable-columns rule applied in magazines/firearms views.
[onToggleDisabled],
);

const { viewState, setViewState, mounted } = useTableViewState(
"users",
createDefaultTableViewState(columns),
);

return (
<div className="grid gap-6 lg:grid-cols-[20rem_1fr]">
Expand Down Expand Up @@ -102,45 +190,13 @@ export function AdminUsers({ users }: { users: AdminUserRow[] }) {
</form>
</Card>

<DataTable>
<THead>
<TH>Email</TH>
<TH>Name</TH>
<TH>Role</TH>
<TH>Status</TH>
<TH className="text-right">Actions</TH>
</THead>
<tbody>
{users.map((user) => (
<TRow key={user.id}>
<TD className="font-mono text-xs">{user.email}</TD>
<TD>{user.name}</TD>
<TD>
<Badge tone={user.role === "admin" ? "blaze" : "neutral"}>
{user.role}
</Badge>
</TD>
<TD>
{user.banned ? (
<Badge tone="danger">disabled</Badge>
) : (
<Badge tone="ok">active</Badge>
)}
</TD>
<TD className="text-right">
<Button
variant={user.banned ? "secondary" : "danger"}
size="sm"
disabled={pending || user.role === "admin"}
onClick={() => onToggleDisabled(user)}
>
{user.banned ? "Enable" : "Disable"}
</Button>
</TD>
</TRow>
))}
</tbody>
</DataTable>
<DataTable
columns={columns}
data={users}
viewState={viewState}
onViewStateChange={setViewState}
mounted={mounted}
/>
</div>
);
}
Loading