'use client' import { useState } from 'react' import { Button } from '@/components/ui/button' import { deleteUser, updateUserRole } from '@/app/actions/admin' import { toast } from 'sonner' import { Trash2, Shield, ShieldOff } from 'lucide-react' import { format } from 'date-fns' export function UserList({ initialUsers }: { initialUsers: any[] }) { // Optimistic update could be implemented here, but standard is fine for admin const handleDelete = async (id: string) => { if (!confirm('Are you sure? This action cannot be undone.')) return try { await deleteUser(id) toast.success('User deleted') } catch (e) { toast.error('Failed to delete') } } const handleRoleToggle = async (user: any) => { const newRole = user.role === 'ADMIN' ? 'USER' : 'ADMIN' try { await updateUserRole(user.id, newRole) toast.success(`User role updated to ${newRole}`) } catch (e) { toast.error('Failed to update role') } } return (
| Name | Role | Created At | Actions | |
|---|---|---|---|---|
| {user.name || 'N/A'} | {user.email} | {user.role} | {format(new Date(user.createdAt), 'PP')} |
|