import { Head, usePage } from '@inertiajs/react'; import { Pencil, Plus, Trash2 } from 'lucide-react'; import type { ReactNode } from 'react'; import { ConfirmDelete, FormDialog, FormField, NativeSelect, PageHeader, } from '@/components/admin/form-controls'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { formatDate, optionsOf, roleLabels } from '@/lib/admin-labels'; import { destroy, index, store, update } from '@/routes/admin/users'; import type { UserRole } from '@/types'; type PanelUser = { id: number; name: string; email: string; role: UserRole; created_at: string; }; const roleDescriptions: Record = { admin: 'Semua menu, termasuk kelola pengguna.', editor: 'Konten website dan inbox konsultasi.', }; export default function UsersIndex({ users }: { users: PanelUser[] }) { const { auth } = usePage().props; return ( <>
Tambah Pengguna } /> } />
{users.map((user) => { const isSelf = user.id === auth.user?.id; return ( ); })}
Nama Peran Dibuat
{user.name} {isSelf && ( {' '} (Anda) )} {user.email}
{roleLabels[user.role]} {formatDate(user.created_at)}
} /> {!isSelf && ( } /> )}
{optionsOf(roleLabels).map(({ value, label }) => (
{label}: {' '} {roleDescriptions[value]}
))}
); } function UserDialog({ user, isSelf = false, trigger, }: { user?: PanelUser; isSelf?: boolean; trigger: ReactNode; }) { const id = (field: string) => `user-${user?.id ?? 'new'}-${field}`; return ( {(errors) => ( <> {isSelf && ( <>

Anda tidak dapat mengubah peran akun sendiri.

)}
)}
); } UsersIndex.layout = { breadcrumbs: [{ title: 'Pengguna', href: index() }], };