diff --git a/src/components/AgendarConsulta/FormNovaConsulta.jsx b/src/components/AgendarConsulta/FormNovaConsulta.jsx index 6723e6c..0ab474d 100644 --- a/src/components/AgendarConsulta/FormNovaConsulta.jsx +++ b/src/components/AgendarConsulta/FormNovaConsulta.jsx @@ -1,8 +1,53 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import InputMask from "react-input-mask"; import "./style/styleagendamentos.css"; -const FormNovaConsulta = ({ onCancel }) => { +const FormNovaConsulta = ({ onCancel, patientID }) => { + const [selectedFile, setSelectedFile] = useState(null); + const [anexos, setAnexos] = useState([]); + const [loadingAnexos, setLoadingAnexos] = useState(false); + useEffect(() => { + if (!patientID) return; + + const fetchAnexos = async () => { + setLoadingAnexos(true); + try { + const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientID}/anexos`); + const data = await res.json(); + setAnexos(data.data || []); + } catch (err) { + console.error("Erro ao buscar anexos:", err); + } finally { + setLoadingAnexos(false); + } + }; + + fetchAnexos(); + }, [patientID]); + + const handleUpload = async () => { + if (!selectedFile) return; + + const formData = new FormData(); + formData.append("file", selectedFile); + + try { + const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientID}/anexos`, { + method: "POST", + body: formData + }); + if (res.ok) { + const novoAnexo = await res.json(); + setAnexos(prev => [...prev, novoAnexo]); + setSelectedFile(null); + } else { + console.error("Erro ao enviar anexo"); + } + } catch (err) { + console.error("Erro ao enviar anexo:", err); + } + }; + const handleSubmit = (e) => { e.preventDefault(); alert("Agendamento salvo!"); @@ -55,7 +100,29 @@ const FormNovaConsulta = ({ onCancel }) => {
Carregando anexos...
+ ) : ( + anexos.map((anexo, index) => ( +{ "-"}
+ {anexos.length > 0 ?( +-
+ )} +