From 981c4bac6e345a8b637b091c4c94957d787b80b3 Mon Sep 17 00:00:00 2001 From: joao_pedro Date: Thu, 13 Nov 2025 08:33:29 -0300 Subject: [PATCH] =?UTF-8?q?bug:=20solu=C3=A7=C3=A3o=20do=20edit=20para=20o?= =?UTF-8?q?=20paciente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/DoctorDetails.jsx | 24 ++------- src/pages/DoctorEditPage.jsx | 40 +++------------ src/pages/DoctorTable.jsx | 12 ++--- src/pages/EditPage.jsx | 50 +++---------------- src/perfis/Perfil_adm/Perfiladm.jsx | 21 ++++---- .../perfil_secretaria/PerfilSecretaria.jsx | 6 +-- 6 files changed, 41 insertions(+), 112 deletions(-) diff --git a/src/pages/DoctorDetails.jsx b/src/pages/DoctorDetails.jsx index 9a6a179b..e426f751 100644 --- a/src/pages/DoctorDetails.jsx +++ b/src/pages/DoctorDetails.jsx @@ -4,36 +4,22 @@ import { useParams,Link, useNavigate, useLocation } from "react-router-dom"; import { GetDoctorByID } from "../components/utils/Functions-Endpoints/Doctor"; import { useAuth } from "../components/utils/AuthProvider"; -const Details = () => { +const DoctorDetails = ({doctor}) => { const {getAuthorizationHeader} = useAuth(); - const [doctor, setDoctor] = useState({}); const Parametros = useParams() const navigate = useNavigate(); const location = useLocation(); + - const Voltar = () => { +const Voltar = () => { const prefixo = location.pathname.split("/")[1]; navigate(`/${prefixo}/medicos`); } - const doctorID = Parametros.id - useEffect(() => { - if (!doctorID) return; - - const authHeader = getAuthorizationHeader() - - GetDoctorByID(doctorID, authHeader) - .then((data) => { - console.log(data, "médico vindo da API"); - setDoctor(data[0]) - ; // supabase retorna array - }) - .catch((err) => console.error("Erro ao buscar paciente:", err)); - }, [doctorID]); - //if (!doctor) return

Carregando...

; + return ( <> @@ -156,4 +142,4 @@ const Details = () => { ); }; -export default Details; \ No newline at end of file +export default DoctorDetails; diff --git a/src/pages/DoctorEditPage.jsx b/src/pages/DoctorEditPage.jsx index 4115823e..1b75ffad 100644 --- a/src/pages/DoctorEditPage.jsx +++ b/src/pages/DoctorEditPage.jsx @@ -8,49 +8,23 @@ import API_KEY from "../components/utils/apiKeys"; const ENDPOINT_AVAILABILITY = "https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/doctor_availability"; -const DoctorEditPage = () => { +const DoctorEditPage = ({DictInfo}) => { const { getAuthorizationHeader } = useAuth(); const [DoctorToPUT, setDoctorPUT] = useState({}); const Parametros = useParams(); const [searchParams] = useSearchParams(); - const DoctorID = Parametros.id; + + const DoctorID = "b24c88b2-1d51-4c04-8fe8-e75c3f2817d1"; const availabilityId = searchParams.get("availabilityId"); const [availabilityToPATCH, setAvailabilityToPATCH] = useState(null); const [mode, setMode] = useState("doctor"); + console.log("teste", DictInfo) - useEffect(() => { - const authHeader = getAuthorizationHeader(); - - if (availabilityId) { - setMode("availability"); - - fetch(`${ENDPOINT_AVAILABILITY}?id=eq.${availabilityId}&select=*`, { - method: "GET", - headers: { - apikey: API_KEY, - Authorization: authHeader, - }, - }) - .then((res) => res.json()) - .then((data) => { - if (data && data.length > 0) { - setAvailabilityToPATCH(data[0]); - console.log("Disponibilidade vinda da API:", data[0]); - } - }) - .catch((err) => console.error("Erro ao buscar disponibilidade:", err)); - } else { - setMode("doctor"); - GetDoctorByID(DoctorID, authHeader) - .then((data) => { - console.log(data, "médico vindo da API"); - setDoctorPUT(data[0]); - }) - .catch((err) => console.error("Erro ao buscar paciente:", err)); - } - }, [DoctorID, availabilityId, getAuthorizationHeader]); + useEffect(() => { + setDoctorPUT(DictInfo) + }, [DictInfo]); const HandlePutDoctor = async () => { const authHeader = getAuthorizationHeader(); diff --git a/src/pages/DoctorTable.jsx b/src/pages/DoctorTable.jsx index e5c2d76f..cdcce24b 100644 --- a/src/pages/DoctorTable.jsx +++ b/src/pages/DoctorTable.jsx @@ -4,7 +4,7 @@ import { useAuth } from "../components/utils/AuthProvider"; import { Link } from "react-router-dom"; import "./style/TableDoctor.css"; -function TableDoctor() { +function TableDoctor({setDictInfo}) { const { getAuthorizationHeader, isAuthenticated } = useAuth(); const [medicos, setMedicos] = useState([]); @@ -437,14 +437,14 @@ function TableDoctor() { {medico.email || 'Não informado'}
- - - - @@ -596,4 +596,4 @@ function TableDoctor() { ); } -export default TableDoctor; \ No newline at end of file +export default TableDoctor; diff --git a/src/pages/EditPage.jsx b/src/pages/EditPage.jsx index 35a33fa1..82f10085 100644 --- a/src/pages/EditPage.jsx +++ b/src/pages/EditPage.jsx @@ -1,40 +1,21 @@ import React from 'react' - import PatientForm from '../components/patients/PatientForm' - import {useEffect, useState} from 'react' import { GetPatientByID } from '../components/utils/Functions-Endpoints/Patient' import API_KEY from '../components/utils/apiKeys' import {useNavigate, useParams } from 'react-router-dom' import { useAuth } from '../components/utils/AuthProvider' -const EditPage = (DictInfo) => { +const EditPage = ({DictInfo}) => { const navigate = useNavigate() - const Parametros = useParams() const [PatientToPUT, setPatientPUT] = useState({}) const { getAuthorizationHeader, isAuthenticated } = useAuth(); -console.log(DictInfo, "usuario vindo do set") -const PatientID = Parametros.id - - useEffect(() => { - const authHeader = getAuthorizationHeader() - console.log(DictInfo.DictInfo.id, "id do cabra") - - GetPatientByID(DictInfo.DictInfo.id, authHeader) - .then((data) => { - console.log(data[0], "paciente vindo da API"); - setPatientPUT(data[0]); // supabase retorna array - }) - .catch((err) => console.error("Erro ao buscar paciente:", err)); - - - + setPatientPUT(DictInfo) }, [DictInfo]) - const HandlePutPatient = async () => { const authHeader = getAuthorizationHeader() @@ -44,9 +25,9 @@ const HandlePutPatient = async () => { myHeaders.append("Authorization", authHeader); myHeaders.append("Content-Type", "application/json"); - var raw = JSON.stringify(PatientToPUT); + var raw = JSON.stringify({...PatientToPUT, bmi:Number(PatientToPUT) || null}); - console.log("Enviando paciente para atualização:", PatientToPUT); + console.log("Enviando atualização:", PatientToPUT); var requestOptions = { method: 'PATCH', @@ -55,26 +36,11 @@ const HandlePutPatient = async () => { redirect: 'follow' }; - try { - const response = await fetch(`https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/patients?id=eq.${PatientID}`,requestOptions); - console.log(response) - + fetch(`https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/patients?id=eq.${PatientToPUT.id}`,requestOptions) + .then(response => response.json) + .then(result => console.log(result)) + .catch(console.log("erro")) - if(response.ok === false){ - console.error("Erro ao atualizar paciente:"); - } - else{ - console.log("ATUALIZADO COM SUCESSO"); - navigate('/secretaria/pacientes') - } - - return response; - } catch (error) { - console.error("Erro ao atualizar paciente:", error); - throw error; - } - - }; return ( diff --git a/src/perfis/Perfil_adm/Perfiladm.jsx b/src/perfis/Perfil_adm/Perfiladm.jsx index 2632fbe6..73496dfc 100644 --- a/src/perfis/Perfil_adm/Perfiladm.jsx +++ b/src/perfis/Perfil_adm/Perfiladm.jsx @@ -14,11 +14,14 @@ import DoctorEditPage from "../../pages/DoctorEditPage"; import UserDashboard from '../../PagesAdm/gestao.jsx'; import PainelAdministrativo from '../../PagesAdm/painel.jsx'; import admItems from "../../data/sidebar-items-adm.json"; - +import {useState} from "react" // ...restante do código... function Perfiladm() { - return ( + + const [DictInfo, setDictInfo] = useState({}) + + return (
@@ -27,12 +30,12 @@ function Perfiladm() { } /> } /> } /> - } /> - } /> - } /> - } /> - } /> - } /> + } /> + } /> + } /> + } /> + } /> + } /> } /> } /> @@ -46,4 +49,4 @@ function Perfiladm() { ); } -export default Perfiladm; \ No newline at end of file +export default Perfiladm; diff --git a/src/perfis/perfil_secretaria/PerfilSecretaria.jsx b/src/perfis/perfil_secretaria/PerfilSecretaria.jsx index 514c29e1..f76b9bc8 100644 --- a/src/perfis/perfil_secretaria/PerfilSecretaria.jsx +++ b/src/perfis/perfil_secretaria/PerfilSecretaria.jsx @@ -31,11 +31,11 @@ function PerfilSecretaria({ onLogout }) { } /> } /> } /> - } /> + } /> } /> } /> - } /> - } /> + } /> + } /> } /> } /> } />