import { createFileRoute, Link, Outlet, useLocation, useNavigate } from '@tanstack/react-router' import { Pencil, Plus, Trash2, UserCog } from 'lucide-react' import { AppContainer, MyButton, p as MyText } from 'web-components' import { trpc } from '../lib/trpc-client' import { ProtectedRoute } from '../components/ProtectedRoute' import { AppShell } from '../components/AppShell' export const Route = createFileRoute('/admins')({ component: () => ( ), }) // This route is the layout for /admins plus its children // (/admins/new and /admins/$id/edit). Render the list only on the exact // /admins path; otherwise hand off to the child route. function Admins() { const location = useLocation() if (location.pathname !== '/admins') { return } return } function AdminsList() { const navigate = useNavigate() const utils = trpc.useUtils() const { data, isLoading, error, refetch } = trpc.superadmin.staffUser.getStaff.useQuery() const deleteStaffUser = trpc.superadmin.staffUser.deleteStaffUser.useMutation({ onSuccess: () => { void utils.superadmin.staffUser.getStaff.invalidate() }, onError: (err) => { window.alert(`Error\n\n${err.message || 'Failed to delete admin'}`) }, }) const staff = data?.staff ?? [] const handleDelete = (id: number, name: string) => { if (!window.confirm(`Delete admin "${name}"? This cannot be undone.`)) return deleteStaffUser.mutate({ id }) } return (
Admins Staff users and the region each one manages.
navigate({ to: '/admins/new' })} className="flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2.5 text-white hover:bg-blue-700" > Add Admin
{isLoading && ( Loading admins... )} {error && (
Error loading admins refetch()} className="rounded-lg bg-blue-500 px-4 py-2 text-white" > Retry
)} {!isLoading && !error && staff.length === 0 && (
No admins yet. Click "Add Admin" to create the first one.
)}
{staff.map((member) => (
{member.name} {member.roleName || 'No role'} ยท {member.regionName || 'No region'}
Edit
))}
) }