Update Disponibilidade e agendamento
This commit is contained in:
parent
da35ebbff5
commit
945ec9d7e7
@ -31,7 +31,7 @@ interface EnrichedAppointment {
|
||||
}
|
||||
|
||||
export default function DoctorAppointmentsPage() {
|
||||
const { user, isLoading: isAuthLoading } = useAuthLayout({ requiredRole: 'medico' });
|
||||
const { user, isLoading: isAuthLoading } = useAuthLayout({ requiredRole: "medico" });
|
||||
|
||||
const [allAppointments, setAllAppointments] = useState<EnrichedAppointment[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
@ -111,13 +111,22 @@ export default function DoctorAppointmentsPage() {
|
||||
return format(date, "EEEE, dd 'de' MMMM", { locale: ptBR });
|
||||
};
|
||||
|
||||
const statusPT: Record<string, string> = {
|
||||
confirmed: "Confirmada",
|
||||
completed: "Concluída",
|
||||
cancelled: "Cancelada",
|
||||
requested: "Solicitada",
|
||||
no_show: "oculta",
|
||||
checked_in: "Aguardando",
|
||||
};
|
||||
|
||||
const getStatusVariant = (status: EnrichedAppointment['status']) => {
|
||||
switch (status) {
|
||||
case "confirmed": case "checked_in": return "default";
|
||||
case "completed": return "secondary";
|
||||
case "cancelled": case "no_show": return "destructive";
|
||||
case "requested": return "outline";
|
||||
default: return "outline";
|
||||
case "confirmed": case "checked_in": return "text-foreground bg-blue-100 hover:bg-blue-150";
|
||||
case "completed": return "text-foreground bg-green-100 hover:bg-green-150";
|
||||
case "cancelled": case "no_show": return "text-foreground bg-red-200 hover:bg-red-250";
|
||||
case "requested": return "text-foreground bg-yellow-100 hover:bg-yellow-150";
|
||||
default: return "border-gray bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90";
|
||||
}
|
||||
};
|
||||
|
||||
@ -191,7 +200,7 @@ export default function DoctorAppointmentsPage() {
|
||||
|
||||
{/* Coluna 2: Status e Telefone */}
|
||||
<div className="col-span-1 flex flex-col items-center gap-2">
|
||||
<Badge variant={getStatusVariant(appointment.status)} className="capitalize text-xs">{appointment.status.replace('_', ' ')}</Badge>
|
||||
<Badge variant="outline" className={getStatusVariant(appointment.status)}>{statusPT[appointment.status].replace('_', ' ')}</Badge>
|
||||
<div className="flex items-center text-sm text-muted-foreground">
|
||||
<Phone className="mr-2 h-4 w-4" />
|
||||
{appointment.patientPhone}
|
||||
|
||||
@ -183,25 +183,25 @@ export default function AvailabilityPage() {
|
||||
saturday: "Sábado",
|
||||
};
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const loggedUser = await usersService.getMe();
|
||||
const doctorList = await doctorsService.list();
|
||||
setUserData(loggedUser);
|
||||
const doctor = findDoctorById(loggedUser.user.id, doctorList);
|
||||
setDoctorId(doctor?.id);
|
||||
console.log(doctor);
|
||||
// Busca disponibilidade
|
||||
const availabilityList = await AvailabilityService.list();
|
||||
|
||||
// Filtra já com a variável local
|
||||
const filteredAvail = availabilityList.filter(
|
||||
(disp: { doctor_id: string }) => disp.doctor_id === doctor?.id
|
||||
);
|
||||
setAvailability(filteredAvail);
|
||||
} catch (e: any) {
|
||||
alert(`${e?.error} ${e?.message}`);
|
||||
}
|
||||
};
|
||||
try {
|
||||
const loggedUser = await usersService.getMe();
|
||||
const doctorList = await doctorsService.list();
|
||||
setUserData(loggedUser);
|
||||
const doctor = findDoctorById(loggedUser.user.id, doctorList);
|
||||
setDoctorId(doctor?.id);
|
||||
console.log(doctor);
|
||||
// Busca disponibilidade
|
||||
const availabilityList = await AvailabilityService.list();
|
||||
|
||||
// Filtra já com a variável local
|
||||
const filteredAvail = availabilityList.filter(
|
||||
(disp: { doctor_id: string }) => disp.doctor_id === doctor?.id
|
||||
);
|
||||
setAvailability(filteredAvail);
|
||||
} catch (e: any) {
|
||||
alert(`${e?.error} ${e?.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
@ -284,6 +284,7 @@ export default function AvailabilityPage() {
|
||||
description: err?.message || "Não foi possível criar a disponibilidade",
|
||||
});
|
||||
} finally {
|
||||
fetchData()
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
@ -318,6 +319,7 @@ export default function AvailabilityPage() {
|
||||
description: e?.message || "Não foi possível deletar a disponibilidade",
|
||||
});
|
||||
}
|
||||
fetchData()
|
||||
setDeleteDialogOpen(false);
|
||||
setSelectedAvailability(null);
|
||||
};
|
||||
@ -453,7 +455,7 @@ export default function AvailabilityPage() {
|
||||
<div key={i}>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<p className="text-sm text-gray-600 cursor-pointer p-1 rounded hover:text-accent-foreground hover:bg-gray-200 transition-colors duration-150">
|
||||
<p className="text-sm text-gray-600 cursor-pointer rounded hover:text-accent-foreground hover:bg-gray-200 transition-colors duration-150">
|
||||
{formatTime(t.start)} - {formatTime(t.end)}
|
||||
</p>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user