-
Confirmação de Exclusão
+
+
Confirmação de Exclusão
-
+
Tem certeza que deseja excluir este médico?
diff --git a/src/pages/PatientCadastroManager.jsx b/src/pages/PatientCadastroManager.jsx
index 8a2fab8..9c5fafb 100644
--- a/src/pages/PatientCadastroManager.jsx
+++ b/src/pages/PatientCadastroManager.jsx
@@ -24,10 +24,10 @@ function PatientCadastroManager( {setCurrentPage} ) {
};
try {
- const response = await fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions);
+ const response = await fetch("https://mock.apidog.com/m1/1053378-0-dault/pacientes", requestOptions);
const result = await response.json();
console.log("Paciente salvo no backend:", result);
- setCurrentPage('table')
+
return result;
} catch (error) {
console.error("Erro ao salvar paciente:", error);
diff --git a/src/pages/Table.jsx b/src/pages/Table.jsx
index 68ca024..ff188fa 100644
--- a/src/pages/Table.jsx
+++ b/src/pages/Table.jsx
@@ -1,6 +1,8 @@
import React, { useState, useEffect } from "react";
function TablePaciente({ setCurrentPage, setPatientID }) {
+ const [showDeleteModal, setShowDeleteModal] = useState(false);
+ const [deleteId, setDeleteId] = useState(null);
const [pacientes, setPacientes] = useState([]);
const [search, setSearch] = useState("");
const [filtroConvenio, setFiltroConvenio] = useState("Todos");
@@ -62,24 +64,31 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
}
}
- const deletePatient = async (id) => {
- DeleteAnexo(id);
+ const handleDeleteClick = (id) => {
+ setDeleteId(id);
+ setShowDeleteModal(true);
+ };
+
+ const confirmDeletePatient = async () => {
+ if (!deleteId) return;
+ await DeleteAnexo(deleteId);
const requestOptionsDelete = { method: "DELETE", redirect: "follow" };
- if (!window.confirm("Tem certeza que deseja excluir este paciente?")) return;
await fetch(
- `https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`,
+ `https://mock.apidog.com/m1/1053378-0-default/pacientes/${deleteId}`,
requestOptionsDelete
)
.then((response) => {
if (!response.ok) {
setShowError404(true);
- setTimeout(() => setShowError404(false), 5000); // Esconde a mensagem após 5 segundos
+ setTimeout(() => setShowError404(false), 5000);
throw new Error('Erro 404');
}
return response.text();
})
.then((mensage) => console.log(mensage))
.catch((error) => console.log("Deu problema", error));
+ setShowDeleteModal(false);
+ setDeleteId(null);
};
const toggleVIP = async (id, atual) => {
@@ -108,33 +117,9 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
.catch((error) => console.log("Erro ao atualizar VIP:", error));
};
- const updateConvenio = async (id, convenio) => {
- await fetch(
- `https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`,
- {
- method: "PUT",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ convenio }),
- }
- )
- .then((response) => {
- if (!response.ok) {
- setShowError404(true);
- setTimeout(() => setShowError404(false), 5000);
- throw new Error('Erro 404');
- }
- return response.json();
- })
- .then(() => {
- setPacientes((prev) =>
- prev.map((p) => (p.id === id ? { ...p, convenio } : p))
- );
- })
- .catch((error) => console.log("Erro ao atualizar convênio:", error));
- };
-
+
useEffect(() => {
- fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes")
+ fetch("https://mock.apidog.com/m1053378-0-det/pacientes")
.then((response) => {
if (!response.ok) {
setShowError404(true);
@@ -173,6 +158,28 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
return (
<>
+ {/* Modal de confirmação de exclusão */}
+ {showDeleteModal && (
+
+
+
+
+
Confirmação de Exclusão
+
+
+
+
+ Tem certeza que deseja excluir este paciente?
+
+
+
+
+
+
+
+
+
+ )}
Lista de Pacientes
@@ -261,7 +268,6 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
CPF |
Email |
Telefone |
-
Status |
Ações |
@@ -317,7 +323,7 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
backgroundColor: "#F8D7DA",
color: "#721C24",
}}
- onClick={() => deletePatient(paciente.id)}
+ onClick={() => handleDeleteClick(paciente.id)}
>
Excluir