import InputMask from "react-input-mask"; import "./style/formagendamentos.css"; import { useState, useEffect } from "react"; import { GetPatientByCPF } from "../utils/Functions-Endpoints/Patient"; import { GetDoctorByName } from "../utils/Functions-Endpoints/Doctor"; import { useAuth } from "../utils/AuthProvider"; const FormNovaConsulta = ({ onCancel, onSave, setAgendamento, agendamento }) => { const {getAuthorizationHeader} = useAuth() const [selectedFile, setSelectedFile] = useState(null); const [anexos, setAnexos] = useState([]); const [loadingAnexos, setLoadingAnexos] = useState(false); const [acessibilidade, setAcessibilidade] = useState({cadeirante:false,idoso:false,gravida:false,bebe:false, autista:false }) let authHeader = getAuthorizationHeader() const handleclickAcessibilidade = (id) => { let resultado = acessibilidade[id] if(resultado === false){ setAcessibilidade({...acessibilidade, [id]:true}); console.log('mudou')} else if(resultado === true){ setAcessibilidade({...acessibilidade, [id]:false})} console.log(id) } const FormatCPF = (valor) => { const digits = String(valor).replace(/\D/g, '').slice(0, 11); return digits .replace(/(\d{3})(\d)/, '$1.$2') .replace(/(\d{3})(\d)/, '$1.$2') .replace(/(\d{3})(\d{1,2})$/, '$1-$2'); } const handleChange = (e) => { const {value, name} = e.target; if(name === 'email'){ setAgendamento({...agendamento, contato:{ ...agendamento.contato, email:value }}) }else if(name === 'cpf'){ let cpfFormatted = FormatCPF(value) const fetchPatient = async () => { let patientData = await GetPatientByCPF(cpfFormatted, authHeader); if (patientData) { setAgendamento((prev) => ({ ...prev, nome: patientData.full_name, patient_id: patientData.id })); }} setAgendamento(prev => ({ ...prev, cpf: cpfFormatted })) fetchPatient() }else if(name==='convenio'){ setAgendamento({...agendamento,insurance_provider:value}) }else if(name ==='profissional'){ const fetchDoctor = async () => { let DoctorData = await GetDoctorByName(value, authHeader) if(DoctorData){ setAgendamento((prev) => ({ ...prev, doctor_id:DoctorData.id })) }} fetchDoctor() } else{ setAgendamento({...agendamento,[name]:value}) } } const handleSubmit = (e) => { e.preventDefault(); alert("Agendamento salvo!"); onSave(agendamento) }; return (

Informações do paciente

Informações adicionais

setSelectedFile(e.target.files[0])} /> {selectedFile && ( )}
{loadingAnexos ? (

Carregando anexos...

) : ( anexos.map((anexo, index) => (
{anexo.nome || anexo.fileName}
)) )}

Informações do atendimento

handleclickAcessibilidade(e.currentTarget.id)}> accessible
handleclickAcessibilidade(e.currentTarget.id)}> elderly
handleclickAcessibilidade(e.currentTarget.id)}> pregnant_woman
handleclickAcessibilidade(e.currentTarget.id)}>
handleclickAcessibilidade(e.currentTarget.id)}>
); }; export default FormNovaConsulta;