From 54625235d5a93f215e4219126c36a81faafecc67 Mon Sep 17 00:00:00 2001 From: jp-lima Date: Thu, 25 Sep 2025 10:47:18 -0300 Subject: [PATCH] =?UTF-8?q?melhorar=20organiza=C3=A7=C3=A3o=20e=20adi?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20modal=20para=20excluir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 6 +- src/components/doctors/DoctorList.jsx | 20 -- src/components/patients/PatientForm.jsx | 4 +- src/components/patients/PatientList.jsx | 20 -- src/pages/DoctorCadastroManager.jsx | 14 +- src/pages/DoctorTable.jsx | 87 +++++-- src/pages/EditPage.jsx | 22 +- src/pages/PatientCadastroManager.jsx | 6 +- src/pages/Table.jsx | 295 ------------------------ 9 files changed, 95 insertions(+), 379 deletions(-) delete mode 100644 src/components/doctors/DoctorList.jsx delete mode 100644 src/components/patients/PatientList.jsx delete mode 100644 src/pages/Table.jsx diff --git a/src/App.js b/src/App.js index 3d45098..8d5862b 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import Sidebar from './components/Sidebar'; //import Header from './components/Header'; -import Table from "./pages/Table"; +import TablePaciente from "./pages/TablePaciente"; import Inicio from './pages/Inicio'; import PatientCadastroManager from './pages/PatientCadastroManager'; @@ -34,7 +34,7 @@ function App() { case 'doctor-form-layout': return ; case 'table': - return ; + return ; case 'doctor-table': return ; case 'details-page-paciente': @@ -42,7 +42,7 @@ function App() { case 'details-page-doctor': return ; case 'edit-page-paciente': - return ; + return ; case 'edit-page-doctor': return ; case 'laudo-manager': diff --git a/src/components/doctors/DoctorList.jsx b/src/components/doctors/DoctorList.jsx deleted file mode 100644 index 570e598..0000000 --- a/src/components/doctors/DoctorList.jsx +++ /dev/null @@ -1,20 +0,0 @@ -import React from 'react'; - -// Este componente recebe uma função 'onAddDoctor' para avisar que o botão foi clicado -function DoctorList({ onAddPatient }) { - return ( -
-
-

Médicos

-
-
-

Gerencie os médicos cadastrados no sistema.

- -
-
- ); -} - -export default DoctorList; \ No newline at end of file diff --git a/src/components/patients/PatientForm.jsx b/src/components/patients/PatientForm.jsx index 04cf897..6f23523 100644 --- a/src/components/patients/PatientForm.jsx +++ b/src/components/patients/PatientForm.jsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; -function PatientForm({ onSave, onCancel,formData, setFormData }) { +function PatientForm({ onSave, onCancel,formData, setFormData,setCurrentPage }) { // Estado para controlar modal de feedback const [showMessage, setShowMessage] = useState(false); @@ -296,7 +296,7 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { {message}
-
diff --git a/src/components/patients/PatientList.jsx b/src/components/patients/PatientList.jsx deleted file mode 100644 index 1619828..0000000 --- a/src/components/patients/PatientList.jsx +++ /dev/null @@ -1,20 +0,0 @@ -import React from 'react'; - -// Este componente recebe uma função 'onAddPatient' para avisar que o botão foi clicado -function PatientList({ onAddPatient }) { - return ( -
-
-

Pacientes

-
-
-

Gerencie os pacientes cadastrados no sistema.

- -
-
- ); -} - -export default PatientList; \ No newline at end of file diff --git a/src/pages/DoctorCadastroManager.jsx b/src/pages/DoctorCadastroManager.jsx index 3976e53..5c9d802 100644 --- a/src/pages/DoctorCadastroManager.jsx +++ b/src/pages/DoctorCadastroManager.jsx @@ -1,12 +1,12 @@ import React, { useState } from 'react'; // Importamos os dois novos componentes que criamos -import DoctorList from '../components/doctors/DoctorList'; + import DoctorForm from '../components/doctors/DoctorForm'; function DoctorCadastroManager( ) { // Este estado vai controlar qual "tela" mostrar: 'list' (lista) ou 'form' (formulário) - const [view, setView] = useState('form'); + var myHeaders = new Headers(); @@ -36,7 +36,7 @@ function DoctorCadastroManager( ) { setModalMsg(`Médico "${patientData.nome}" salvo com sucesso!`); setShowModal(true); - setView('list'); + }; return ( @@ -66,15 +66,13 @@ function DoctorCadastroManager( ) {
- {view === 'list' ? ( - setView('form')} /> - ) : ( + setView('list')} + onCancel={console.log('hsh')} PatientDict={{}} /> - )} +
diff --git a/src/pages/DoctorTable.jsx b/src/pages/DoctorTable.jsx index b834137..80774b9 100644 --- a/src/pages/DoctorTable.jsx +++ b/src/pages/DoctorTable.jsx @@ -5,19 +5,25 @@ function TableDoctor({ setCurrentPage, setPatientID }) { const [search, setSearch] = useState(""); const [filtroAniversariante, setFiltroAniversariante] = useState(false); + // estados do modal + const [showDeleteModal, setShowDeleteModal] = useState(false); + const [selectedDoctorId, setSelectedDoctorId] = useState(null); + // Função para excluir médicos const deleteDoctor = async (id) => { const requestOptionsDelete = { method: "DELETE", redirect: "follow" }; - if (!window.confirm("Tem certeza que deseja excluir este médico?")) return; - - await fetch( - `https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`, - requestOptionsDelete - ) - .then((response) => response.text()) - .then((mensage) => console.log(mensage)) - .catch((error) => console.log("Deu problema", error)); + try { + await fetch( + `https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`, + requestOptionsDelete + ); + setMedicos((prev) => prev.filter((m) => m.id !== id)); + } catch (error) { + console.log("Deu problema", error); + } finally { + setShowDeleteModal(false); + } }; // Função para verificar se hoje é aniversário @@ -60,7 +66,6 @@ function TableDoctor({ setCurrentPage, setPatientID }) {
-

Médicos Cadastrados

@@ -105,7 +108,7 @@ function TableDoctor({ setCurrentPage, setPatientID }) { - + @@ -130,7 +133,7 @@ function TableDoctor({ setCurrentPage, setPatientID }) {
Email Telefone Ações
- + {/* Ver Detalhes */} + @@ -189,6 +197,55 @@ function TableDoctor({ setCurrentPage, setPatientID }) {
+ + {/* Modal de confirmação de exclusão */} + {showDeleteModal && ( +
+ e.target.classList.contains("modal") && setShowDeleteModal(false) + } + > +
+
+
+
Confirmação de Exclusão
+ +
+
+

+ Tem certeza que deseja excluir este médico? +

+
+
+ + +
+
+
+
+ )} ); } diff --git a/src/pages/EditPage.jsx b/src/pages/EditPage.jsx index b706ef9..1b94620 100644 --- a/src/pages/EditPage.jsx +++ b/src/pages/EditPage.jsx @@ -4,7 +4,7 @@ import PatientForm from '../components/patients/PatientForm' import {useEffect, useState} from 'react' -const EditPage = ( {id}) => { +const EditPage = ( {id, setCurrentPage}) => { const [PatientToPUT, setPatientPUT] = useState({}) @@ -22,9 +22,10 @@ fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`, requestOpt .then(data => setPatientPUT(data)) .catch(error => console.log('error', error)); -}, []) +}, [id,requestOptions]) + const HandlePutPatient = async () => { - //alert(`Atualizando paciente "${PatientToPUT.nome}" com sucesso`); + var myHeaders = new Headers(); myHeaders.append("Authorization", "Bearer "); @@ -50,26 +51,23 @@ const HandlePutPatient = async () => { // se o backend retorna JSON const result = await response.json(); console.log("ATUALIZADO COM SUCESSO", result); - - return result; // <- importante! + + return result; } catch (error) { console.error("Erro ao atualizar paciente:", error); throw error; } + + }; - - return ( -
- - {setCurrentPage('table')}} + setCurrentPage={setCurrentPage} formData={PatientToPUT} setFormData={setPatientPUT} /> diff --git a/src/pages/PatientCadastroManager.jsx b/src/pages/PatientCadastroManager.jsx index 339d3b9..8a2fab8 100644 --- a/src/pages/PatientCadastroManager.jsx +++ b/src/pages/PatientCadastroManager.jsx @@ -1,11 +1,8 @@ -import { useState } from 'react'; - - +import {useState} from 'react'; import PatientForm from '../components/patients/PatientForm'; function PatientCadastroManager( {setCurrentPage} ) { - const [formData, setFormData] = useState({}) var myHeaders = new Headers(); @@ -30,6 +27,7 @@ function PatientCadastroManager( {setCurrentPage} ) { 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); + 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 deleted file mode 100644 index bfc0e06..0000000 --- a/src/pages/Table.jsx +++ /dev/null @@ -1,295 +0,0 @@ -import React, { useState, useEffect } from "react"; - -function TablePaciente({ setCurrentPage, setPatientID }) { - const [pacientes, setPacientes] = useState([]); - const [search, setSearch] = useState(""); - const [filtroConvenio, setFiltroConvenio] = useState("Todos"); - const [filtroVIP, setFiltroVIP] = useState(false); - const [filtroAniversariante, setFiltroAniversariante] = useState(false); - - - const GetAnexos = async (id) => { - var myHeaders = new Headers(); - myHeaders.append("Authorization", "Bearer "); - - var requestOptions = { - method: 'GET', - headers: myHeaders, - redirect: 'follow' - }; - try { - const response = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}/anexos`, requestOptions); - const result = await response.json(); - - return result.data; // agora retorna corretamente - } catch (error) { - console.log('error', error); - return []; - } - - } - - const DeleteAnexo = async (patientID) => { - - - const RespostaGetAnexos = await GetAnexos(patientID) - - for(let i = 0; i < RespostaGetAnexos.length; i++){ - - const idAnexo = RespostaGetAnexos[i].id; - - console.log('anexos',RespostaGetAnexos) - - - var myHeaders = new Headers(); - myHeaders.append("Authorization", "Bearer "); - - var requestOptions = { - method: 'DELETE', - headers: myHeaders, - redirect: 'follow' - }; - - fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientID}/anexos/${idAnexo}`, requestOptions) - .then(response => response.text()) - .then(result => console.log('anexo excluido com sucesso',result)) - .catch(error => console.log('error', error)); - - } - - } - - // Função para excluir paciente - const deletePatient = async (id) => { - DeleteAnexo(id) - - 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}`, - requestOptionsDelete - ) - .then((response) => response.text()) - .then((mensage) => console.log(mensage)) - .catch((error) => console.log("Deu problema", error)); - }; - - - - // Requisição inicial para buscar pacientes - useEffect(() => { - fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes") - .then((response) => response.json()) - .then((result) => setPacientes(result["data"])) - .catch((error) => - console.log("Erro para encontrar pacientes no banco de dados", error) - ); - }, []); - - // Função para verificar se hoje é aniversário do paciente - const ehAniversariante = (dataNascimento) => { - if (!dataNascimento) return false; - const hoje = new Date(); - const nascimento = new Date(dataNascimento); - - return ( - hoje.getDate() === nascimento.getDate() && - hoje.getMonth() === nascimento.getMonth() - ); - }; - - - const pacientesFiltrados = pacientes.filter((paciente) => { - const texto = `${paciente.nome}`.toLowerCase(); - - const passaBusca = texto.includes(search.toLowerCase()); - const passaVIP = filtroVIP ? paciente.vip === true : true; - const passaConvenio = - filtroConvenio === "Todos" || paciente.convenio === filtroConvenio; - const passaAniversario = filtroAniversariante - ? ehAniversariante(paciente.data_nascimento) - : true; - - return passaBusca && passaVIP && passaConvenio && passaAniversario; - }); - - return ( - <> -
-

Lista de Pacientes

-
-
-
-
-
-
-

Pacientes Cadastrados

- -
- -
-
-
- Filtros -
- -
- setSearch(e.target.value)} - style={{ - minWidth: 250, - maxWidth: 300, - width: 260, - flex: "0 0 auto", - }} - /> - - - - - - -
-
- - -
- - - - - - - - - - - {pacientesFiltrados.length > 0 ? ( - pacientesFiltrados.map((paciente) => ( - - - - - - - - - )) - ) : ( - - - - )} - -
NomeCPFEmailTelefone
{paciente.nome}{paciente.cpf}{paciente.email}{paciente.telefone} - - {paciente.ativo} - - -
- - - - - - - -
-
- Nenhum paciente encontrado. -
-
-
-
-
-
-
- - ); -} - -export default TablePaciente;