{/* DADOS PESSOAIS */}
@@ -326,7 +367,7 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) {
-
+
diff --git a/src/pages/DoctorCadastroManager.jsx b/src/pages/DoctorCadastroManager.jsx
index 3a928c4..3976e53 100644
--- a/src/pages/DoctorCadastroManager.jsx
+++ b/src/pages/DoctorCadastroManager.jsx
@@ -12,6 +12,10 @@ function DoctorCadastroManager( ) {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
+ // Estado do modal de sucesso
+ const [showModal, setShowModal] = useState(false);
+ const [modalMsg, setModalMsg] = useState('');
+
// Função que será chamada para "salvar" o paciente
const handleSavePatient = (patientData) => {
console.log('Salvando médico:', patientData);
@@ -23,32 +27,45 @@ function DoctorCadastroManager( ) {
header: myHeaders,
body:raw,
redirect:'follow'
-
}
+ fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions)
+ .then(response => response.text())
+ .then(result => console.log(result))
+ .catch(error => console.log('error', error));
- fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions)
- .then(response => response.text())
- .then(result => console.log(result))
- .catch(error => console.log('error', error));
-
- alert(`Médico "${patientData.nome}" salvo com sucesso!`); //altere isso para integração com backend
- // Após salvar, voltamos para a tela de lista
+ setModalMsg(`Médico "${patientData.nome}" salvo com sucesso!`);
+ setShowModal(true);
setView('list');
};
return (
<>
+ {/* Modal de feedback */}
+ {showModal && (
+
+
+
+
+
Sucesso
+
+
+
+
{modalMsg}
+
+
+
+
+
+
+
+ )}
Cadastro de Médicos
- {/* Aqui está a lógica principal: */}
- {/* Se a view for 'list', mostramos a lista com o botão. */}
- {/* Se for 'form', mostramos o formulário de cadastro. */}
-
{view === 'list' ? (
setView('form')} />
) : (
@@ -56,7 +73,6 @@ function DoctorCadastroManager( ) {
onSave={handleSavePatient}
onCancel={() => setView('list')}
PatientDict={{}}
-
/>
)}
diff --git a/src/pages/EditPage.jsx b/src/pages/EditPage.jsx
index b204fd9..b706ef9 100644
--- a/src/pages/EditPage.jsx
+++ b/src/pages/EditPage.jsx
@@ -23,30 +23,41 @@ fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`, requestOpt
.catch(error => console.log('error', error));
}, [])
+const HandlePutPatient = async () => {
+ //alert(`Atualizando paciente "${PatientToPUT.nome}" com sucesso`);
-const HandlePutPatient = () => {
- alert(`Atualizando paciente "${PatientToPUT.nome}" com sucesso`)
- var myHeaders = new Headers();
-myHeaders.append("Authorization", "Bearer ");
-myHeaders.append("Content-Type", "application/json");
+ var myHeaders = new Headers();
+ myHeaders.append("Authorization", "Bearer ");
+ myHeaders.append("Content-Type", "application/json");
-var raw = JSON.stringify(PatientToPUT)
+ var raw = JSON.stringify(PatientToPUT);
-console.log(PatientToPUT)
+ console.log("Enviando paciente para atualização:", PatientToPUT);
-var requestOptions = {
- method: 'PUT',
- headers: myHeaders,
- body: raw,
- redirect: 'follow'
+ var requestOptions = {
+ method: 'PUT',
+ headers: myHeaders,
+ body: raw,
+ redirect: 'follow'
+ };
+
+ try {
+ const response = await fetch(
+ "https://mock.apidog.com/m1/1053378-0-default/pacientes/" + PatientToPUT.id,
+ requestOptions
+ );
+
+ // se o backend retorna JSON
+ const result = await response.json();
+ console.log("ATUALIZADO COM SUCESSO", result);
+
+ return result; // <- importante!
+ } catch (error) {
+ console.error("Erro ao atualizar paciente:", error);
+ throw error;
+ }
};
-fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/", requestOptions)
- .then(response => response.text())
- .then(result => console.log('ATUALIZADO COM SUCESSO',result))
- .catch(error => console.log('error', error));
-
- }
return (
diff --git a/src/pages/PatientCadastroManager.jsx b/src/pages/PatientCadastroManager.jsx
index 7653975..e33e7d4 100644
--- a/src/pages/PatientCadastroManager.jsx
+++ b/src/pages/PatientCadastroManager.jsx
@@ -13,29 +13,32 @@ function PatientCadastroManager( {setCurrentPage} ) {
myHeaders.append("Content-Type", "application/json");
// Função que será chamada para "salvar" o paciente
- const handleSavePatient = (patientData) => {
- console.log('Salvando paciente:', patientData);
+ const handleSavePatient = async (patientData) => {
+ console.log('Salvando paciente:', patientData);
- var raw = JSON.stringify(patientData)
+ var raw = JSON.stringify(patientData);
- var requestOptions = {
- method:'POST',
- header: myHeaders,
- body:raw,
- redirect:'follow'
- }
-
-
- fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions)
- .then(response => response.text())
- .then(result => console.log(result))
- .catch(error => console.log('error', error));
-
- alert(`Paciente "${patientData.nome}" salvo com sucesso!`); //altere isso para integração com backend
- // Após salvar, voltamos para a tela de lista
-
+ var requestOptions = {
+ method: 'POST',
+ headers: {
+ "Content-Type": "application/json"
+ },
+ body: raw,
+ redirect: 'follow'
};
+ try {
+ const response = await fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions);
+ const result = await response.json();
+ console.log("Paciente salvo no backend:", result);
+ return result;
+ } catch (error) {
+ console.error("Erro ao salvar paciente:", error);
+ throw error;
+ }
+};
+
+
return (
<>