Build an Admin “All Chats” Table View with Sorting & User Lookup in Daryle AI
Context
You need an admin-only page at /admin/chats that lets superadmins see every saved chat, sort and search by user (and other columns), and click into any chat to open a full review panel.
Task
Create a Chats Table component and page that:
- Data Fetch
- Uses Supabase to select from chats joined to profiles:
ts
CopyEdit
supabase
-
-
-
-
-
-
- jsonb_array_length(messages) AS message_count,
-
-
-
-
- .order('updated_at', { ascending: false });
-
- Table View
- Columns:
- Chat Title (truncate ~40 chars)
-
- User (profiles.name || profiles.email)
-
-
-
-
- Sortable by each column (click header to toggle asc/desc)
-
- Searchable by user name/email and by chat title
-
- Paginated (e.g. 20 rows per page with “Next”/“Prev”)
-
- Row Interaction
- Hover highlight + cursor-pointer
-
- Click a row to open a ChatViewer drawer/modal showing the full conversation (just like your existing component).
-
- UI/UX
- Tailwind-styled table with sticky header
-
- Clear sort indicators (↑↓) in the header
-
- A search input above the table to filter rows client-side or via a Supabase ilike query
-
- Pagination controls at bottom
-
- ChatViewer occupies right side or slides over
-
Functional Requirements
- Use React state (or React Query) to manage sort, search, and pagination
- Only fetch the page of data you need (use .range() for Supabase pagination)
- Ensure only currentUser.role === "superadmin" can access this page
- Use your existing ChatViewer to display messages on row click
Constraints
- Next.js page under pages/admin/chats.tsx
- Components in components/admin/ChatsTable.tsx + components/admin/ChatViewer.tsx
- Tailwind CSS only—no additional UI libraries
- Supabase JS client for data access
- TypeScript types for ChatWithProfile and paging
Output Files
- pages/admin/chats.tsx – page shell, role guard, search/sort state
- components/admin/ChatsTable.tsx – table rendering, sorting, pagination, row click
- components/admin/ChatViewer.tsx – full chat panel on the right or modal
- utils/adminChatsService.ts (optional) – encapsulate Supabase calls