From 54c337aaaec85c2c6a72e295c462daceaa8209c1 Mon Sep 17 00:00:00 2001 From: jp-lima Date: Fri, 26 Sep 2025 13:04:27 -0300 Subject: [PATCH] =?UTF-8?q?Adi=C3=A7=C3=A3o=20das=20rotas=20com=20react-ro?= =?UTF-8?q?uter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 90 +++--- src/components/Sidebar.js | 131 --------- src/components/doctors/DoctorForm.jsx | 10 +- src/components/patients/PatientForm.jsx | 13 +- src/data/sidebar-items.json | 14 +- src/pages/DoctorTable.jsx | 2 +- src/pages/Inicio.jsx | 3 +- src/pages/Table.jsx | 353 ------------------------ 8 files changed, 59 insertions(+), 557 deletions(-) delete mode 100644 src/components/Sidebar.js delete mode 100644 src/pages/Table.jsx diff --git a/src/App.js b/src/App.js index 2afc1a31..cfff4cec 100644 --- a/src/App.js +++ b/src/App.js @@ -1,66 +1,42 @@ -import React, { useState } from 'react'; -import Sidebar from './components/Sidebar'; -//import Header from './components/Header'; -import TablePaciente from "./pages/Table"; - -import Inicio from './pages/Inicio'; -import PatientCadastroManager from './pages/PatientCadastroManager'; -import EditPage from './pages/EditPage'; -import DoctorEditPage from './pages/DoctorEditPage'; - -import Details from './pages/Details'; -import DoctorDetails from './pages/DoctorDetails'; - -import DoctorTable from './pages/DoctorTable'; -import DoctorCadastroManager from './pages/DoctorCadastroManager'; -import Agendamento from './pages/Agendamento' +import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; +import Sidebar from "./components/Sidebar"; +import Inicio from "./pages/Inicio"; +import TablePaciente from "./pages/TablePaciente"; +import PatientCadastroManager from "./pages/PatientCadastroManager"; +import DoctorCadastroManager from "./pages/DoctorCadastroManager"; +import DoctorTable from "./pages/DoctorTable"; +import Agendamento from "./pages/Agendamento"; import LaudoManager from "./pages/LaudoManager"; +import Details from "./pages/Details"; +import EditPage from "./pages/EditPage"; +import DoctorDetails from "./pages/DoctorDetails"; +import DoctorEditPage from "./pages/DoctorEditPage"; function App() { - const [isSidebarActive] = useState(true); - const [currentPage, setCurrentPage] = useState('Inicio'); - const [patientID, setPatientID] = useState(null); - - - const renderPageContent = () => { - switch (currentPage) { - case 'Inicio': - return ; - case 'agendamento': - return ; - case 'form-layout': - return ; - case 'doctor-form-layout': - return ; - case 'table': - return ; - case 'doctor-table': - return ; - case 'details-page-paciente': - return
; - case 'details-page-doctor': - return ; - case 'edit-page-paciente': - return ; - case 'edit-page-doctor': - return ; - case 'laudo-manager': - return ; - default: - return ; - } - }; - return ( -
- -
- - {renderPageContent()} + +
+ +
+ + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + Página não encontrada} /> + +
-
+ ); } -export default App; \ No newline at end of file +export default App; diff --git a/src/components/Sidebar.js b/src/components/Sidebar.js deleted file mode 100644 index 095b41ee..00000000 --- a/src/components/Sidebar.js +++ /dev/null @@ -1,131 +0,0 @@ -import React, { useState } from 'react'; -// ADIÇÃO 1: Importar o arquivo JSON com os itens do menu -import menuItems from '../data/sidebar-items.json'; // <-- ATENÇÃO: ajuste o caminho para o seu arquivo! - -// ADIÇÃO 2: A função agora precisa receber 'props' para ter acesso ao setCurrentPage -function Sidebar(props) { - const [isActive, setIsActive] = useState(true); - const [openSubmenu, setOpenSubmenu] = useState(null); - - const toggleSidebar = () => { - setIsActive(!isActive); - }; - - const handleSubmenuClick = (submenuName) => { - setOpenSubmenu(openSubmenu === submenuName ? null : submenuName); - }; - - // ===================================================== - // renderLink atualizado para suportar Table.jsx - // ===================================================== - const renderLink = (item) => { - if (item.url && !item.url.includes('.html') && !item.url.startsWith('http')) { - return ( - { - e.preventDefault(); - props.setCurrentPage(item.url); // agora passa "table" corretamente - }} - > - {item.icon && } - {item.name} - - ); - } - return ( - - {item.icon && } - {item.name} - - ); - }; - - return ( - - ); -} - -export default Sidebar; diff --git a/src/components/doctors/DoctorForm.jsx b/src/components/doctors/DoctorForm.jsx index 6ef87f53..5254aa2b 100644 --- a/src/components/doctors/DoctorForm.jsx +++ b/src/components/doctors/DoctorForm.jsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; - +import {Link} from 'react-router-dom' function DoctorForm({ onSave, onCancel, PatientDict }) { @@ -458,9 +458,11 @@ function DoctorForm({ onSave, onCancel, PatientDict }) { - + + +
diff --git a/src/components/patients/PatientForm.jsx b/src/components/patients/PatientForm.jsx index 4b77f233..74f66590 100644 --- a/src/components/patients/PatientForm.jsx +++ b/src/components/patients/PatientForm.jsx @@ -1,4 +1,5 @@ import React, { useState, useEffect } from 'react'; +import {Link} from 'react-router-dom' function PatientForm({ onSave, onCancel, formData, setFormData }) { const [errorModalMsg, setErrorModalMsg] = useState(""); @@ -615,11 +616,15 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) { - + + + + + {/* Modal para paciente existente */} {showModal && pacienteExistente && (
@@ -703,6 +708,8 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {

{errorModalMsg || '(Erro 404).Por favor, tente novamente mais tarde'}

+ + diff --git a/src/data/sidebar-items.json b/src/data/sidebar-items.json index 64efcad7..81762b68 100644 --- a/src/data/sidebar-items.json +++ b/src/data/sidebar-items.json @@ -6,43 +6,43 @@ { "name":"Início", - "url": "Inicio", + "url": "/", "icon": "house" }, { "name": "Cadastro de Pacientes", - "url": "form-layout", + "url": "/pacientes/cadastro", "icon": "heart-pulse-fill" }, { "name": "Cadastro do Médico", - "url": "doctor-form-layout", + "url": "/medicos/cadastro", "icon": "capsule" }, { "name": "Lista de Pacientes", "icon": "clipboard-heart-fill", - "url": "table" + "url": "/pacientes" }, { "name": "Lista de Médico", "icon": "hospital-fill", - "url": "doctor-table" + "url": "/medicos" }, { "name": "Agendar consulta", "icon": "calendar-plus-fill", - "url": "agendamento" + "url": "/agendamento" }, { "name": "Laudo do Paciente", "icon": "table", - "url": "laudo-manager" + "url": "/laudo" } ] \ No newline at end of file diff --git a/src/pages/DoctorTable.jsx b/src/pages/DoctorTable.jsx index b1cc213b..549c37e8 100644 --- a/src/pages/DoctorTable.jsx +++ b/src/pages/DoctorTable.jsx @@ -42,7 +42,7 @@ function TableDoctor({ setCurrentPage, setPatientID }) { useEffect(() => { fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes") .then((response) => response.json()) - .then((result) => setMedicos(result["data"])) + .then((result) => console.log('nada')) .catch((error) => console.log("Erro para encontrar médicos no banco de dados", error) ); diff --git a/src/pages/Inicio.jsx b/src/pages/Inicio.jsx index 2edcfe0a..dc47fae1 100644 --- a/src/pages/Inicio.jsx +++ b/src/pages/Inicio.jsx @@ -11,7 +11,8 @@ function Inicio({ setCurrentPage }) { try { const res = await fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes"); const data = await res.json(); - setPacientes(data.data); + console.log(data) + //setPacientes(data.data); } catch (error) { console.error("Erro ao buscar pacientes:", error); } diff --git a/src/pages/Table.jsx b/src/pages/Table.jsx deleted file mode 100644 index ff188fac..00000000 --- a/src/pages/Table.jsx +++ /dev/null @@ -1,353 +0,0 @@ -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"); - const [filtroVIP, setFiltroVIP] = useState(false); - const [filtroAniversariante, setFiltroAniversariante] = useState(false); - - // Estado para controlar a exibição do erro 404 - const [showError404, setShowError404] = 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); - if (!response.ok) { - setShowError404(true); - setTimeout(() => setShowError404(false), 5000); // Esconde a mensagem após 5 segundos - throw new Error('Erro 404'); - } - const result = await response.json(); - return result.data; - } 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; - - 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 => { - if (!response.ok) { - setShowError404(true); - setTimeout(() => setShowError404(false), 5000); // Esconde a mensagem após 5 segundos - throw new Error('Erro 404'); - } - return response.text(); - }) - .then(result => console.log('anexo excluido com sucesso', result)) - .catch(error => console.log('error', error)); - } - } - - const handleDeleteClick = (id) => { - setDeleteId(id); - setShowDeleteModal(true); - }; - - const confirmDeletePatient = async () => { - if (!deleteId) return; - await DeleteAnexo(deleteId); - const requestOptionsDelete = { method: "DELETE", redirect: "follow" }; - await fetch( - `https://mock.apidog.com/m1/1053378-0-default/pacientes/${deleteId}`, - requestOptionsDelete - ) - .then((response) => { - if (!response.ok) { - setShowError404(true); - 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) => { - const novoStatus = atual === true ? false : true; - await fetch( - `https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`, - { - method: "PUT", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ vip: novoStatus }), - } - ) - .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, vip: novoStatus } : p)) - ); - }) - .catch((error) => console.log("Erro ao atualizar VIP:", error)); - }; - - - useEffect(() => { - fetch("https://mock.apidog.com/m1053378-0-det/pacientes") - .then((response) => { - if (!response.ok) { - setShowError404(true); - setTimeout(() => setShowError404(false), 5000); - throw new Error('Erro 404'); - } - return response.json(); - }) - .then((result) => setPacientes(result["data"])) - .catch((error) => - console.log("Erro para encontrar pacientes no banco de dados", error) - ); - }, []); - - 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 ( - <> - {/* Modal de confirmação de exclusão */} - {showDeleteModal && ( -
-
-
-
-
Confirmação de Exclusão
- -
-
-

- Tem certeza que deseja excluir este paciente? -

-
-
- - -
-
-
-
- )} -
-

Lista de Pacientes

-
-
-
-
-
-
-

Pacientes Cadastrados

- -
- -
- {showError404 && ( -
- (Erro 404). Por favor, tente novamente mais tarde. -
- )} -
-
- Filtros -
-
- setSearch(e.target.value)} - style={{ - minWidth: 250, - maxWidth: 300, - width: 260, - flex: "0 0 auto", - }} - /> - - - -
-
-
- - - - - - - - - - - - {pacientesFiltrados.length > 0 ? ( - pacientesFiltrados.map((paciente) => ( - - - - - - - - - )) - ) : ( - - - - )} - -
NomeCPFEmailTelefoneAções
{paciente.nome}{paciente.cpf}{paciente.email}{paciente.telefone} - - {paciente.ativo} - - -
- - - -
-
- Nenhum paciente encontrado. -
-
-
-
-
-
-
- - ); -} - -export default TablePaciente; \ No newline at end of file