fix: exception-endpoints

This commit is contained in:
João Gustavo 2025-12-03 15:36:30 -03:00
parent c8607556e0
commit 5251719123
2 changed files with 69 additions and 4 deletions

View File

@ -964,7 +964,14 @@ export default function DoutoresPage() {
{exceptions.map((ex) => (
<div key={String(ex.id)} className="p-2 border rounded flex justify-between items-start">
<div>
<div className="font-medium">{ex.date} {ex.start_time ? `${ex.start_time}` : ''} {ex.end_time ? `${ex.end_time}` : ''}</div>
<div className="font-medium">{(() => {
try {
const [y, m, d] = String(ex.date).split('-');
return `${d}/${m}/${y}`;
} catch (e) {
return ex.date;
}
})()} {ex.start_time ? `${ex.start_time}` : ''} {ex.end_time ? `${ex.end_time}` : ''}</div>
<div className="text-xs text-muted-foreground">Tipo: {ex.kind} Motivo: {ex.reason || '—'}</div>
</div>
<div className="flex gap-2">

View File

@ -6,6 +6,8 @@ import { Button } from '@/components/ui/button'
import { Label } from '@/components/ui/label'
import { Input } from '@/components/ui/input'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import { Calendar as CalendarComponent } from '@/components/ui/calendar'
import { Calendar } from 'lucide-react'
import { criarExcecao, DoctorExceptionCreate } from '@/lib/api'
import { useToast } from '@/hooks/use-toast'
@ -23,6 +25,7 @@ export default function ExceptionForm({ open, onOpenChange, doctorId = null, onS
const [kind, setKind] = useState<'bloqueio'|'liberacao'>('bloqueio')
const [reason, setReason] = useState<string>('')
const [submitting, setSubmitting] = useState(false)
const [showDatePicker, setShowDatePicker] = useState(false)
const { toast } = useToast()
async function handleSubmit(e?: React.FormEvent) {
@ -67,9 +70,64 @@ export default function ExceptionForm({ open, onOpenChange, doctorId = null, onS
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4 py-4">
<div>
<Label>Data</Label>
<Input type="date" value={date} onChange={(e) => setDate(e.target.value)} />
<div className="space-y-2">
<div className="flex items-center gap-2">
<Label className="text-[13px]">Data *</Label>
<button
type="button"
aria-label="Abrir seletor de data"
onClick={() => setShowDatePicker(!showDatePicker)}
className="h-6 w-6 flex items-center justify-center text-muted-foreground hover:text-foreground cursor-pointer"
>
<Calendar className="h-4 w-4" />
</button>
</div>
<div className="relative">
<Input
type="text"
placeholder="DD/MM/AAAA"
className="h-11 w-full rounded-md pl-3 pr-3 text-[13px] transition-colors hover:bg-muted/30"
value={date ? (() => {
try {
const [y, m, d] = String(date).split('-');
return `${d}/${m}/${y}`;
} catch (e) {
return '';
}
})() : ''}
readOnly
/>
{showDatePicker && (
<div className="absolute top-full left-0 mt-1 z-50 bg-card border border-border rounded-md shadow-lg p-3">
<CalendarComponent
mode="single"
selected={date ? (() => {
try {
const [y, m, d] = String(date).split('-').map(Number);
return new Date(y, m - 1, d);
} catch (e) {
return undefined;
}
})() : undefined}
onSelect={(selectedDate) => {
if (selectedDate) {
const y = selectedDate.getFullYear();
const m = String(selectedDate.getMonth() + 1).padStart(2, '0');
const d = String(selectedDate.getDate()).padStart(2, '0');
const dateStr = `${y}-${m}-${d}`;
setDate(dateStr);
setShowDatePicker(false);
}
}}
disabled={(checkDate) => {
const today = new Date();
today.setHours(0, 0, 0, 0);
return checkDate < today;
}}
/>
</div>
)}
</div>
</div>
<div className="grid grid-cols-2 gap-4">