forked from RiseUP/riseup_squad_03
fix(principal): integra auth, agenda e laudos com a api
This commit is contained in:
@@ -16,30 +16,38 @@ const viewFilters = ['Dia', 'Semana', 'Mês']
|
||||
|
||||
export function AgendaPage({ navigate }) {
|
||||
const [patients, setPatients] = useState([])
|
||||
const professionals = professionalRepository.getAll()
|
||||
const [professionals, setProfessionals] = useState([])
|
||||
const queue = appointmentRepository.getPredictiveQueueSummary()
|
||||
const timeline = appointmentRepository.getTodayTimeline()
|
||||
const weekDays = appointmentRepository.getWeekDays()
|
||||
const [activeView, setActiveView] = useState('Dia')
|
||||
const [status, setStatus] = useState('Todos')
|
||||
const [modalOpen, setModalOpen] = useState(false)
|
||||
const [localAppointments, setLocalAppointments] = useState(() => appointmentRepository.getAll())
|
||||
const [localAppointments, setLocalAppointments] = useState([])
|
||||
const [form, setForm] = useState({
|
||||
patientId: '',
|
||||
professional: professionals[0]?.name || '',
|
||||
professionalId: '',
|
||||
type: 'Retorno',
|
||||
time: '15:30',
|
||||
mode: 'Teleconsulta',
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
patientRepository.getAll().then((data) => {
|
||||
setPatients(data)
|
||||
Promise.all([
|
||||
patientRepository.getAll(),
|
||||
appointmentRepository.getAll(),
|
||||
professionalRepository.getAll()
|
||||
]).then(([patientsData, appointmentsData, professionalsData]) => {
|
||||
setPatients(patientsData)
|
||||
setLocalAppointments(appointmentsData || [])
|
||||
setProfessionals(professionalsData || [])
|
||||
|
||||
setForm((current) => ({
|
||||
...current,
|
||||
patientId: data[0]?.id || '',
|
||||
patientId: patientsData?.length ? patientsData[0].id : '',
|
||||
professionalId: professionalsData?.length ? professionalsData[0].id : '',
|
||||
}))
|
||||
})
|
||||
}).catch(e => console.error(e))
|
||||
}, [])
|
||||
|
||||
const visibleAppointments = useMemo(() => {
|
||||
@@ -54,26 +62,28 @@ useEffect(() => {
|
||||
setForm((current) => ({ ...current, [field]: value }))
|
||||
}
|
||||
|
||||
function handleCreate(event) {
|
||||
async function handleCreate(event) {
|
||||
event.preventDefault()
|
||||
const patient = patients.find((item) => item.id === form.patientId) || patients[0]
|
||||
|
||||
setLocalAppointments((current) => [
|
||||
...current,
|
||||
{
|
||||
id: `apt-local-${current.length + 1}`,
|
||||
date: '2026-04-07',
|
||||
patient: patient.name,
|
||||
patientId: patient.id,
|
||||
professional: form.professional,
|
||||
room: form.mode === 'Teleconsulta' ? 'Sala virtual 3' : 'Sala 02',
|
||||
status: 'Confirmada',
|
||||
|
||||
// Fallback date and time
|
||||
const today = new Date().toISOString().split('T')[0]
|
||||
|
||||
try {
|
||||
const created = await appointmentRepository.create({
|
||||
patientId: form.patientId,
|
||||
date: today,
|
||||
time: form.time,
|
||||
type: form.type,
|
||||
mode: form.mode,
|
||||
},
|
||||
])
|
||||
setModalOpen(false)
|
||||
room: form.mode === 'Teleconsulta' ? 'Virtual' : 'Consultório 1',
|
||||
professionalId: form.professionalId,
|
||||
})
|
||||
|
||||
setLocalAppointments((current) => [...current, created])
|
||||
setModalOpen(false)
|
||||
} catch(err) {
|
||||
alert(err.message || 'Erro ao criar agendamento.')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -244,7 +254,7 @@ useEffect(() => {
|
||||
>
|
||||
{patients.map((patient) => (
|
||||
<option key={patient.id} value={patient.id}>
|
||||
{patient.name}
|
||||
{patient.name || patient.full_name || patient.nome}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
@@ -274,11 +284,11 @@ useEffect(() => {
|
||||
<DarkField label="Profissional">
|
||||
<select
|
||||
className="h-11 rounded-md border border-[#404040] bg-[#303030] px-3 text-sm text-[#e5e5e5] outline-none focus:border-[#3b82f6]"
|
||||
onChange={(event) => updateForm('professional', event.target.value)}
|
||||
value={form.professional}
|
||||
onChange={(event) => updateForm('professionalId', event.target.value)}
|
||||
value={form.professionalId}
|
||||
>
|
||||
{professionals.map((professional) => (
|
||||
<option key={professional.id}>{professional.name}</option>
|
||||
<option key={professional.id} value={professional.id}>{professional.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</DarkField>
|
||||
|
||||
Reference in New Issue
Block a user