feat: add cell formatters and tables for boards, agents, and member invites
This commit is contained in:
@@ -6,12 +6,6 @@ import { useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
|
||||
import { useAuth } from "@/auth/clerk";
|
||||
import {
|
||||
type ColumnDef,
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
useReactTable,
|
||||
} from "@tanstack/react-table";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { ApiError } from "@/api/mutator";
|
||||
@@ -21,19 +15,24 @@ import {
|
||||
useDeleteBoardGroupApiV1BoardGroupsGroupIdDelete,
|
||||
useListBoardGroupsApiV1BoardGroupsGet,
|
||||
} from "@/api/generated/board-groups/board-groups";
|
||||
import { BoardGroupsTable } from "@/components/board-groups/BoardGroupsTable";
|
||||
import type { BoardGroupRead } from "@/api/generated/model";
|
||||
import { createOptimisticListDeleteMutation } from "@/lib/list-delete";
|
||||
import { useUrlSorting } from "@/lib/use-url-sorting";
|
||||
import { DashboardPageLayout } from "@/components/templates/DashboardPageLayout";
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { ConfirmActionDialog } from "@/components/ui/confirm-action-dialog";
|
||||
import { formatTimestamp } from "@/lib/formatters";
|
||||
import {
|
||||
TableEmptyStateRow,
|
||||
TableLoadingRow,
|
||||
} from "@/components/ui/table-state";
|
||||
|
||||
const BOARD_GROUP_SORTABLE_COLUMNS = ["name", "updated_at"];
|
||||
|
||||
export default function BoardGroupsPage() {
|
||||
const { isSignedIn } = useAuth();
|
||||
const queryClient = useQueryClient();
|
||||
const { sorting, onSortingChange } = useUrlSorting({
|
||||
allowedColumnIds: BOARD_GROUP_SORTABLE_COLUMNS,
|
||||
defaultSorting: [{ id: "name", desc: false }],
|
||||
paramPrefix: "board_groups",
|
||||
});
|
||||
const [deleteTarget, setDeleteTarget] = useState<BoardGroupRead | null>(null);
|
||||
|
||||
const groupsKey = getListBoardGroupsApiV1BoardGroupsGetQueryKey();
|
||||
@@ -61,44 +60,20 @@ export default function BoardGroupsPage() {
|
||||
{ previous?: listBoardGroupsApiV1BoardGroupsGetResponse }
|
||||
>(
|
||||
{
|
||||
mutation: {
|
||||
onMutate: async ({ groupId }) => {
|
||||
await queryClient.cancelQueries({ queryKey: groupsKey });
|
||||
const previous =
|
||||
queryClient.getQueryData<listBoardGroupsApiV1BoardGroupsGetResponse>(
|
||||
groupsKey,
|
||||
);
|
||||
if (previous && previous.status === 200) {
|
||||
const nextItems = previous.data.items.filter(
|
||||
(group) => group.id !== groupId,
|
||||
);
|
||||
const removedCount = previous.data.items.length - nextItems.length;
|
||||
queryClient.setQueryData<listBoardGroupsApiV1BoardGroupsGetResponse>(
|
||||
groupsKey,
|
||||
{
|
||||
...previous,
|
||||
data: {
|
||||
...previous.data,
|
||||
items: nextItems,
|
||||
total: Math.max(0, previous.data.total - removedCount),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
return { previous };
|
||||
},
|
||||
onError: (_error, _group, context) => {
|
||||
if (context?.previous) {
|
||||
queryClient.setQueryData(groupsKey, context.previous);
|
||||
}
|
||||
},
|
||||
mutation: createOptimisticListDeleteMutation<
|
||||
BoardGroupRead,
|
||||
listBoardGroupsApiV1BoardGroupsGetResponse,
|
||||
{ groupId: string }
|
||||
>({
|
||||
queryClient,
|
||||
queryKey: groupsKey,
|
||||
getItemId: (group) => group.id,
|
||||
getDeleteId: ({ groupId }) => groupId,
|
||||
onSuccess: () => {
|
||||
setDeleteTarget(null);
|
||||
},
|
||||
onSettled: () => {
|
||||
queryClient.invalidateQueries({ queryKey: groupsKey });
|
||||
},
|
||||
},
|
||||
invalidateQueryKeys: [groupsKey],
|
||||
}),
|
||||
},
|
||||
queryClient,
|
||||
);
|
||||
@@ -108,70 +83,6 @@ export default function BoardGroupsPage() {
|
||||
deleteMutation.mutate({ groupId: deleteTarget.id });
|
||||
};
|
||||
|
||||
const columns = useMemo<ColumnDef<BoardGroupRead>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorKey: "name",
|
||||
header: "Group",
|
||||
cell: ({ row }) => (
|
||||
<Link
|
||||
href={`/board-groups/${row.original.id}`}
|
||||
className="group block"
|
||||
>
|
||||
<p className="text-sm font-medium text-slate-900 group-hover:text-blue-600">
|
||||
{row.original.name}
|
||||
</p>
|
||||
{row.original.description ? (
|
||||
<p className="mt-1 text-xs text-slate-500 line-clamp-2">
|
||||
{row.original.description}
|
||||
</p>
|
||||
) : (
|
||||
<p className="mt-1 text-xs text-slate-400">No description</p>
|
||||
)}
|
||||
</Link>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "updated_at",
|
||||
header: "Updated",
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-slate-700">
|
||||
{formatTimestamp(row.original.updated_at)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Link
|
||||
href={`/board-groups/${row.original.id}/edit`}
|
||||
className={buttonVariants({ variant: "ghost", size: "sm" })}
|
||||
>
|
||||
Edit
|
||||
</Link>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setDeleteTarget(row.original)}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
],
|
||||
[],
|
||||
);
|
||||
|
||||
// eslint-disable-next-line react-hooks/incompatible-library
|
||||
const table = useReactTable({
|
||||
data: groups,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<DashboardPageLayout
|
||||
@@ -192,72 +103,22 @@ export default function BoardGroupsPage() {
|
||||
stickyHeader
|
||||
>
|
||||
<div className="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead className="sticky top-0 z-10 bg-slate-50 text-xs uppercase tracking-wide text-slate-500">
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<tr key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => (
|
||||
<th
|
||||
key={header.id}
|
||||
className="px-6 py-3 text-left font-semibold"
|
||||
>
|
||||
{header.isPlaceholder
|
||||
? null
|
||||
: flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext(),
|
||||
)}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100">
|
||||
{groupsQuery.isLoading ? (
|
||||
<TableLoadingRow colSpan={columns.length} />
|
||||
) : table.getRowModel().rows.length ? (
|
||||
table.getRowModel().rows.map((row) => (
|
||||
<tr key={row.id} className="transition hover:bg-slate-50">
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<td key={cell.id} className="px-6 py-4 align-top">
|
||||
{flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext(),
|
||||
)}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<TableEmptyStateRow
|
||||
colSpan={columns.length}
|
||||
icon={
|
||||
<svg
|
||||
className="h-16 w-16 text-slate-300"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M3 7h8" />
|
||||
<path d="M3 17h8" />
|
||||
<path d="M13 7h8" />
|
||||
<path d="M13 17h8" />
|
||||
<path d="M3 12h18" />
|
||||
</svg>
|
||||
}
|
||||
title="No groups yet"
|
||||
description="Create a board group to increase cross-board visibility for agents."
|
||||
actionHref="/board-groups/new"
|
||||
actionLabel="Create your first group"
|
||||
/>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<BoardGroupsTable
|
||||
groups={groups}
|
||||
isLoading={groupsQuery.isLoading}
|
||||
sorting={sorting}
|
||||
onSortingChange={onSortingChange}
|
||||
showActions
|
||||
stickyHeader
|
||||
onDelete={setDeleteTarget}
|
||||
emptyState={{
|
||||
title: "No groups yet",
|
||||
description:
|
||||
"Create a board group to increase cross-board visibility for agents.",
|
||||
actionHref: "/board-groups/new",
|
||||
actionLabel: "Create your first group",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{groupsQuery.error ? (
|
||||
|
||||
Reference in New Issue
Block a user