diff --git a/app/secretary/appointments/page.tsx b/app/secretary/appointments/page.tsx new file mode 100644 index 0000000..2687690 --- /dev/null +++ b/app/secretary/appointments/page.tsx @@ -0,0 +1,283 @@ +"use client"; + +import { useState, useEffect } from "react"; +import SecretaryLayout from "@/components/secretary-layout"; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { Button } from "@/components/ui/button"; +import { Badge } from "@/components/ui/badge"; +import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Calendar, Clock, MapPin, Phone, CalendarDays, X, User } from "lucide-react"; +import { toast } from "sonner"; +import Link from "next/link"; + +const APPOINTMENTS_STORAGE_KEY = "clinic-appointments"; + +const initialAppointments = [ + { + id: 1, + patientName: "Carlos Pereira", + doctor: "Dr. João Silva", + specialty: "Cardiologia", + date: "2024-01-15", + time: "14:30", + status: "agendada", + location: "Consultório A - 2º andar", + phone: "(11) 3333-4444", + }, + { + id: 2, + patientName: "Ana Beatriz Costa", + doctor: "Dra. Maria Santos", + specialty: "Dermatologia", + date: "2024-01-22", + time: "10:00", + status: "agendada", + location: "Consultório B - 1º andar", + phone: "(11) 3333-5555", + }, + { + id: 3, + patientName: "Roberto Almeida", + doctor: "Dr. Pedro Costa", + specialty: "Ortopedia", + date: "2024-01-08", + time: "16:00", + status: "realizada", + location: "Consultório C - 3º andar", + phone: "(11) 3333-6666", + }, + { + id: 4, + patientName: "Fernanda Lima", + doctor: "Dra. Ana Lima", + specialty: "Ginecologia", + date: "2024-01-05", + time: "09:30", + status: "realizada", + location: "Consultório D - 2º andar", + phone: "(11) 3333-7777", + }, +]; + +export default function SecretaryAppointments() { + const [appointments, setAppointments] = useState([]); + const [rescheduleModal, setRescheduleModal] = useState(false); + const [cancelModal, setCancelModal] = useState(false); + const [selectedAppointment, setSelectedAppointment] = useState(null); + const [rescheduleData, setRescheduleData] = useState({ date: "", time: "", reason: "" }); + const [cancelReason, setCancelReason] = useState(""); + + useEffect(() => { + const storedAppointments = localStorage.getItem(APPOINTMENTS_STORAGE_KEY); + if (storedAppointments) { + setAppointments(JSON.parse(storedAppointments)); + } else { + setAppointments(initialAppointments); + localStorage.setItem(APPOINTMENTS_STORAGE_KEY, JSON.stringify(initialAppointments)); + } + }, []); + + const updateAppointments = (updatedAppointments: any[]) => { + setAppointments(updatedAppointments); + localStorage.setItem(APPOINTMENTS_STORAGE_KEY, JSON.stringify(updatedAppointments)); + }; + + const handleReschedule = (appointment: any) => { + setSelectedAppointment(appointment); + setRescheduleData({ date: "", time: "", reason: "" }); + setRescheduleModal(true); + }; + + const handleCancel = (appointment: any) => { + setSelectedAppointment(appointment); + setCancelReason(""); + setCancelModal(true); + }; + + const confirmReschedule = () => { + if (!rescheduleData.date || !rescheduleData.time) { + toast.error("Por favor, selecione uma nova data e horário"); + return; + } + const updated = appointments.map((apt) => (apt.id === selectedAppointment.id ? { ...apt, date: rescheduleData.date, time: rescheduleData.time } : apt)); + updateAppointments(updated); + setRescheduleModal(false); + toast.success("Consulta reagendada com sucesso!"); + }; + + const confirmCancel = () => { + if (!cancelReason.trim() || cancelReason.trim().length < 10) { + toast.error("O motivo do cancelamento é obrigatório e deve ter no mínimo 10 caracteres."); + return; + } + const updated = appointments.map((apt) => (apt.id === selectedAppointment.id ? { ...apt, status: "cancelada" } : apt)); + updateAppointments(updated); + setCancelModal(false); + toast.success("Consulta cancelada com sucesso!"); + }; + + const getStatusBadge = (status: string) => { + switch (status) { + case "agendada": + return Agendada; + case "realizada": + return Realizada; + case "cancelada": + return Cancelada; + default: + return {status}; + } + }; + + const timeSlots = ["08:00", "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30"]; + + return ( + +
+
+
+

Consultas Agendadas

+

Gerencie as consultas dos pacientes

+
+ + + +
+ +
+ {appointments.length > 0 ? ( + appointments.map((appointment) => ( + + +
+
+ {appointment.doctor} + {appointment.specialty} +
+ {getStatusBadge(appointment.status)} +
+
+ +
+
+
+ + {appointment.patientName} +
+
+ + {new Date(appointment.date).toLocaleDateString("pt-BR", { timeZone: "UTC" })} +
+
+ + {appointment.time} +
+
+
+
+ + {appointment.location} +
+
+ + {appointment.phone} +
+
+
+ + {appointment.status === "agendada" && ( +
+ + +
+ )} +
+
+ )) + ) : ( +

Nenhuma consulta encontrada.

+ )} +
+
+ + + + + Reagendar Consulta + Reagendar consulta com {selectedAppointment?.doctor} para {selectedAppointment?.patientName} + +
+
+ + setRescheduleData((prev) => ({ ...prev, date: e.target.value }))} min={new Date().toISOString().split("T")[0]} /> +
+
+ + +
+
+ +