Compare commits
2 Commits
613b70654e
...
8e08567bb8
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e08567bb8 | |||
| 26c0f726c3 |
@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import type React from "react"
|
import type React from "react"
|
||||||
import { useState } from "react"
|
import { useState, useEffect, useCallback } from "react"
|
||||||
// Importações de componentes omitidas para brevidade, mas estão no código original
|
// Importações de componentes omitidas para brevidade, mas estão no código original
|
||||||
import PatientLayout from "@/components/patient-layout"
|
import PatientLayout from "@/components/patient-layout"
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
@ -11,6 +11,15 @@ import { Label } from "@/components/ui/label"
|
|||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||||
import { Textarea } from "@/components/ui/textarea"
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
import { Calendar, Clock, User } from "lucide-react"
|
import { Calendar, Clock, User } from "lucide-react"
|
||||||
|
import { doctorsService } from "services/doctorsApi.mjs";
|
||||||
|
|
||||||
|
interface Doctor {
|
||||||
|
id: string;
|
||||||
|
full_name: string;
|
||||||
|
specialty: string;
|
||||||
|
phone_mobile: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Chave do LocalStorage, a mesma usada em secretarypage.tsx
|
// Chave do LocalStorage, a mesma usada em secretarypage.tsx
|
||||||
const APPOINTMENTS_STORAGE_KEY = "clinic-appointments";
|
const APPOINTMENTS_STORAGE_KEY = "clinic-appointments";
|
||||||
@ -20,13 +29,30 @@ export default function ScheduleAppointment() {
|
|||||||
const [selectedDate, setSelectedDate] = useState("")
|
const [selectedDate, setSelectedDate] = useState("")
|
||||||
const [selectedTime, setSelectedTime] = useState("")
|
const [selectedTime, setSelectedTime] = useState("")
|
||||||
const [notes, setNotes] = useState("")
|
const [notes, setNotes] = useState("")
|
||||||
|
const [doctors, setDoctors] = useState<Doctor[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const doctors = [
|
|
||||||
{ id: "1", name: "Dr. João Silva", specialty: "Cardiologia" },
|
const fetchDoctors = useCallback(async () => {
|
||||||
{ id: "2", name: "Dra. Maria Santos", specialty: "Dermatologia" },
|
setLoading(true);
|
||||||
{ id: "3", name: "Dr. Pedro Costa", specialty: "Ortopedia" },
|
setError(null);
|
||||||
{ id: "4", name: "Dra. Ana Lima", specialty: "Ginecologia" },
|
try {
|
||||||
]
|
|
||||||
|
const data: Doctor[] = await doctorsService.list();
|
||||||
|
setDoctors(data || []);
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error("Erro ao carregar lista de médicos:", e);
|
||||||
|
setError("Não foi possível carregar a lista de médicos. Verifique a conexão com a API.");
|
||||||
|
setDoctors([]);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchDoctors();
|
||||||
|
}, [fetchDoctors]);
|
||||||
|
|
||||||
const availableTimes = [
|
const availableTimes = [
|
||||||
"08:00",
|
"08:00",
|
||||||
@ -65,7 +91,7 @@ export default function ScheduleAppointment() {
|
|||||||
const newAppointment = {
|
const newAppointment = {
|
||||||
id: new Date().getTime(), // ID único simples
|
id: new Date().getTime(), // ID único simples
|
||||||
patientName: patientDetails.full_name,
|
patientName: patientDetails.full_name,
|
||||||
doctor: doctorDetails.name, // Nome completo do médico (necessário para a listagem)
|
doctor: doctorDetails.full_name, // Nome completo do médico (necessário para a listagem)
|
||||||
specialty: doctorDetails.specialty,
|
specialty: doctorDetails.specialty,
|
||||||
date: selectedDate,
|
date: selectedDate,
|
||||||
time: selectedTime,
|
time: selectedTime,
|
||||||
@ -83,7 +109,7 @@ export default function ScheduleAppointment() {
|
|||||||
// 3. Salva a lista atualizada no LocalStorage
|
// 3. Salva a lista atualizada no LocalStorage
|
||||||
localStorage.setItem(APPOINTMENTS_STORAGE_KEY, JSON.stringify(updatedAppointments));
|
localStorage.setItem(APPOINTMENTS_STORAGE_KEY, JSON.stringify(updatedAppointments));
|
||||||
|
|
||||||
alert(`Consulta com ${doctorDetails.name} agendada com sucesso!`);
|
alert(`Consulta com ${doctorDetails.full_name} agendada com sucesso!`);
|
||||||
|
|
||||||
// Limpar o formulário após o sucesso (opcional)
|
// Limpar o formulário após o sucesso (opcional)
|
||||||
setSelectedDoctor("");
|
setSelectedDoctor("");
|
||||||
@ -118,7 +144,7 @@ export default function ScheduleAppointment() {
|
|||||||
<SelectContent>
|
<SelectContent>
|
||||||
{doctors.map((doctor) => (
|
{doctors.map((doctor) => (
|
||||||
<SelectItem key={doctor.id} value={doctor.id}>
|
<SelectItem key={doctor.id} value={doctor.id}>
|
||||||
{doctor.name} - {doctor.specialty}
|
{doctor.full_name} - {doctor.specialty}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
@ -185,7 +211,7 @@ export default function ScheduleAppointment() {
|
|||||||
{selectedDoctor && (
|
{selectedDoctor && (
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<User className="h-4 w-4 text-gray-500" />
|
<User className="h-4 w-4 text-gray-500" />
|
||||||
<span className="text-sm">{doctors.find((d) => d.id === selectedDoctor)?.name}</span>
|
<span className="text-sm">{doctors.find((d) => d.id === selectedDoctor)?.full_name}</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user