From 296fc474a6d8b2be41d2b43d565f454c934a41ec Mon Sep 17 00:00:00 2001 From: joao-luis-jois Date: Fri, 10 Oct 2025 01:58:25 +0000 Subject: [PATCH] Enviar arquivos para "app/manager/usuario" --- app/manager/usuario/page.tsx | 245 +++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 app/manager/usuario/page.tsx diff --git a/app/manager/usuario/page.tsx b/app/manager/usuario/page.tsx new file mode 100644 index 0000000..00c4836 --- /dev/null +++ b/app/manager/usuario/page.tsx @@ -0,0 +1,245 @@ +"use client"; + +import React, { useEffect, useState, useCallback } from "react" +import ManagerLayout from "@/components/manager-layout"; +import Link from "next/link" +import { useRouter } from "next/navigation"; +import { Button } from "@/components/ui/button" +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" +import { Plus, Edit, Trash2, Eye, Filter, Loader2 } from "lucide-react" +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from "@/components/ui/alert-dialog" + +// Mock user service for demonstration. Replace with your actual API service. +const usersService = { + list: async (): Promise => { + console.log("API Call: Fetching users..."); + await new Promise(resolve => setTimeout(resolve, 500)); // Simulate network delay + return [ + { id: 1, full_name: 'Alice Admin', email: 'alice.admin@example.com', phone: '(11) 98765-4321', role: 'user' }, + + ]; + }, + delete: async (id: number): Promise => { + console.log(`API Call: Deleting user with ID ${id}`); + await new Promise(resolve => setTimeout(resolve, 700)); + // In a real app, you'd handle potential errors here + } +}; + +// Interface for a User object +interface User { + id: number; + full_name: string; + email: string; + phone: string | null; + role: 'admin' | 'gestor' | 'medico' | 'secretaria' | 'user'; +} + +// Interface for User Details (can be the same as User for this case) +interface UserDetails extends User {} + +export default function UsersPage() { + const router = useRouter(); + + const [users, setUsers] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [detailsDialogOpen, setDetailsDialogOpen] = useState(false); + const [userDetails, setUserDetails] = useState(null); + const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); + const [userToDeleteId, setUserToDeleteId] = useState(null); + + const fetchUsers = useCallback(async () => { + setLoading(true); + setError(null); + try { + const data: User[] = await usersService.list(); + setUsers(data || []); + } catch (e: any) { + console.error("Erro ao carregar lista de usuários:", e); + setError("Não foi possível carregar a lista de usuários. Tente novamente."); + setUsers([]); + } finally { + setLoading(false); + } + }, []); + + useEffect(() => { + fetchUsers(); + }, [fetchUsers]); + + const openDetailsDialog = (user: User) => { + setUserDetails(user); + setDetailsDialogOpen(true); + }; + + const handleDelete = async () => { + if (userToDeleteId === null) return; + + setLoading(true); + try { + await usersService.delete(userToDeleteId); + console.log(`Usuário com ID ${userToDeleteId} excluído com sucesso!`); + setDeleteDialogOpen(false); + setUserToDeleteId(null); + await fetchUsers(); // Refresh the list after deletion + } catch (e) { + console.error("Erro ao excluir:", e); + alert("Erro ao excluir usuário."); + } finally { + setLoading(false); + } + }; + + const openDeleteDialog = (userId: number) => { + setUserToDeleteId(userId); + setDeleteDialogOpen(true); + }; + + const handleEdit = (userId: number) => { + // Assuming the edit page is at a similar path + router.push(`/manager/usuario/${userId}/editar`); + }; + + return ( + +
+
+
+

Usuários Cadastrados

+

Gerencie todos os usuários do sistema.

+
+ + + +
+ + {/* Filters Section */} +
+ + +
+ + {/* Users Table */} +
+ {loading ? ( +
+ + Carregando usuários... +
+ ) : error ? ( +
+ {error} +
+ ) : users.length === 0 ? ( +
+ Nenhum usuário cadastrado. Adicione um novo. +
+ ) : ( +
+ + + + + + + + + + + + {users.map((user) => ( + + + + + + + + ))} + +
Nome CompletoE-mailTelefonePapelAções
{user.full_name}{user.email}{user.phone || "N/A"}{user.role} +
+ + + +
+
+
+ )} +
+ + {/* Delete Confirmation Dialog */} + + + + Confirma a exclusão? + + Esta ação é irreversível e excluirá permanentemente o registro deste usuário. + + + + Cancelar + + {loading ? : null} + Excluir + + + + + + {/* User Details Dialog */} + + + + {userDetails?.full_name} + + {userDetails && ( +
+
+
E-mail: {userDetails.email}
+
Telefone: {userDetails.phone || 'Não informado'}
+
Papel: {userDetails.role}
+
+
+ )} +
+
+ + Fechar + +
+
+
+
+ ); +} \ No newline at end of file