forked from RiseUP/riseup-squad23
bug: solução do edit para o paciente
This commit is contained in:
parent
2647691ae2
commit
981c4bac6e
@ -4,36 +4,22 @@ import { useParams,Link, useNavigate, useLocation } from "react-router-dom";
|
|||||||
import { GetDoctorByID } from "../components/utils/Functions-Endpoints/Doctor";
|
import { GetDoctorByID } from "../components/utils/Functions-Endpoints/Doctor";
|
||||||
import { useAuth } from "../components/utils/AuthProvider";
|
import { useAuth } from "../components/utils/AuthProvider";
|
||||||
|
|
||||||
const Details = () => {
|
const DoctorDetails = ({doctor}) => {
|
||||||
const {getAuthorizationHeader} = useAuth();
|
const {getAuthorizationHeader} = useAuth();
|
||||||
const [doctor, setDoctor] = useState({});
|
|
||||||
const Parametros = useParams()
|
const Parametros = useParams()
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const Voltar = () => {
|
|
||||||
|
const Voltar = () => {
|
||||||
const prefixo = location.pathname.split("/")[1];
|
const prefixo = location.pathname.split("/")[1];
|
||||||
navigate(`/${prefixo}/medicos`);
|
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 <p style={{ textAlign: "center" }}>Carregando...</p>;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -156,4 +142,4 @@ const Details = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Details;
|
export default DoctorDetails;
|
||||||
|
|||||||
@ -8,49 +8,23 @@ import API_KEY from "../components/utils/apiKeys";
|
|||||||
const ENDPOINT_AVAILABILITY =
|
const ENDPOINT_AVAILABILITY =
|
||||||
"https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/doctor_availability";
|
"https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/doctor_availability";
|
||||||
|
|
||||||
const DoctorEditPage = () => {
|
const DoctorEditPage = ({DictInfo}) => {
|
||||||
const { getAuthorizationHeader } = useAuth();
|
const { getAuthorizationHeader } = useAuth();
|
||||||
const [DoctorToPUT, setDoctorPUT] = useState({});
|
const [DoctorToPUT, setDoctorPUT] = useState({});
|
||||||
|
|
||||||
const Parametros = useParams();
|
const Parametros = useParams();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const DoctorID = Parametros.id;
|
|
||||||
|
const DoctorID = "b24c88b2-1d51-4c04-8fe8-e75c3f2817d1";
|
||||||
const availabilityId = searchParams.get("availabilityId");
|
const availabilityId = searchParams.get("availabilityId");
|
||||||
|
|
||||||
const [availabilityToPATCH, setAvailabilityToPATCH] = useState(null);
|
const [availabilityToPATCH, setAvailabilityToPATCH] = useState(null);
|
||||||
const [mode, setMode] = useState("doctor");
|
const [mode, setMode] = useState("doctor");
|
||||||
|
console.log("teste", DictInfo)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const authHeader = getAuthorizationHeader();
|
setDoctorPUT(DictInfo)
|
||||||
|
}, [DictInfo]);
|
||||||
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]);
|
|
||||||
|
|
||||||
const HandlePutDoctor = async () => {
|
const HandlePutDoctor = async () => {
|
||||||
const authHeader = getAuthorizationHeader();
|
const authHeader = getAuthorizationHeader();
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { useAuth } from "../components/utils/AuthProvider";
|
|||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import "./style/TableDoctor.css";
|
import "./style/TableDoctor.css";
|
||||||
|
|
||||||
function TableDoctor() {
|
function TableDoctor({setDictInfo}) {
|
||||||
const { getAuthorizationHeader, isAuthenticated } = useAuth();
|
const { getAuthorizationHeader, isAuthenticated } = useAuth();
|
||||||
|
|
||||||
const [medicos, setMedicos] = useState([]);
|
const [medicos, setMedicos] = useState([]);
|
||||||
@ -437,14 +437,14 @@ function TableDoctor() {
|
|||||||
<td>{medico.email || 'Não informado'}</td>
|
<td>{medico.email || 'Não informado'}</td>
|
||||||
<td>
|
<td>
|
||||||
<div className="d-flex gap-2">
|
<div className="d-flex gap-2">
|
||||||
<Link to={`${medico.id}`}>
|
<Link to={`details`}>
|
||||||
<button className="btn btn-sm btn-view">
|
<button className="btn btn-sm btn-view" onClick={() => setDictInfo({...medico})}>
|
||||||
<i className="bi bi-eye me-1"></i> Ver Detalhes
|
<i className="bi bi-eye me-1"></i> Ver Detalhes
|
||||||
</button>
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<Link to={`${medico.id}/edit`}>
|
<Link to={`edit`}>
|
||||||
<button className="btn btn-sm btn-edit">
|
<button className="btn btn-sm btn-edit" onClick={() => setDictInfo({...medico})}>
|
||||||
<i className="bi bi-pencil me-1"></i> Editar
|
<i className="bi bi-pencil me-1"></i> Editar
|
||||||
</button>
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@ -1,40 +1,21 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import PatientForm from '../components/patients/PatientForm'
|
import PatientForm from '../components/patients/PatientForm'
|
||||||
|
|
||||||
import {useEffect, useState} from 'react'
|
import {useEffect, useState} from 'react'
|
||||||
import { GetPatientByID } from '../components/utils/Functions-Endpoints/Patient'
|
import { GetPatientByID } from '../components/utils/Functions-Endpoints/Patient'
|
||||||
import API_KEY from '../components/utils/apiKeys'
|
import API_KEY from '../components/utils/apiKeys'
|
||||||
import {useNavigate, useParams } from 'react-router-dom'
|
import {useNavigate, useParams } from 'react-router-dom'
|
||||||
import { useAuth } from '../components/utils/AuthProvider'
|
import { useAuth } from '../components/utils/AuthProvider'
|
||||||
|
|
||||||
const EditPage = (DictInfo) => {
|
const EditPage = ({DictInfo}) => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const Parametros = useParams()
|
|
||||||
const [PatientToPUT, setPatientPUT] = useState({})
|
const [PatientToPUT, setPatientPUT] = useState({})
|
||||||
|
|
||||||
const { getAuthorizationHeader, isAuthenticated } = useAuth();
|
const { getAuthorizationHeader, isAuthenticated } = useAuth();
|
||||||
console.log(DictInfo, "usuario vindo do set")
|
|
||||||
const PatientID = Parametros.id
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const authHeader = getAuthorizationHeader()
|
setPatientPUT(DictInfo)
|
||||||
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));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}, [DictInfo])
|
}, [DictInfo])
|
||||||
|
|
||||||
|
|
||||||
const HandlePutPatient = async () => {
|
const HandlePutPatient = async () => {
|
||||||
const authHeader = getAuthorizationHeader()
|
const authHeader = getAuthorizationHeader()
|
||||||
|
|
||||||
@ -44,9 +25,9 @@ const HandlePutPatient = async () => {
|
|||||||
myHeaders.append("Authorization", authHeader);
|
myHeaders.append("Authorization", authHeader);
|
||||||
myHeaders.append("Content-Type", "application/json");
|
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 = {
|
var requestOptions = {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
@ -55,25 +36,10 @@ const HandlePutPatient = async () => {
|
|||||||
redirect: 'follow'
|
redirect: 'follow'
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
fetch(`https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/patients?id=eq.${PatientToPUT.id}`,requestOptions)
|
||||||
const response = await fetch(`https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/patients?id=eq.${PatientID}`,requestOptions);
|
.then(response => response.json)
|
||||||
console.log(response)
|
.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -14,10 +14,13 @@ import DoctorEditPage from "../../pages/DoctorEditPage";
|
|||||||
import UserDashboard from '../../PagesAdm/gestao.jsx';
|
import UserDashboard from '../../PagesAdm/gestao.jsx';
|
||||||
import PainelAdministrativo from '../../PagesAdm/painel.jsx';
|
import PainelAdministrativo from '../../PagesAdm/painel.jsx';
|
||||||
import admItems from "../../data/sidebar-items-adm.json";
|
import admItems from "../../data/sidebar-items-adm.json";
|
||||||
|
import {useState} from "react"
|
||||||
|
|
||||||
// ...restante do código...
|
// ...restante do código...
|
||||||
function Perfiladm() {
|
function Perfiladm() {
|
||||||
|
|
||||||
|
const [DictInfo, setDictInfo] = useState({})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<div id="app" className="active">
|
<div id="app" className="active">
|
||||||
@ -27,12 +30,12 @@ function Perfiladm() {
|
|||||||
<Route path="/" element={<UserDashboard />} />
|
<Route path="/" element={<UserDashboard />} />
|
||||||
<Route path="/pacientes/cadastro" element={<PatientCadastroManager />} />
|
<Route path="/pacientes/cadastro" element={<PatientCadastroManager />} />
|
||||||
<Route path="/medicos/cadastro" element={<DoctorCadastroManager />} />
|
<Route path="/medicos/cadastro" element={<DoctorCadastroManager />} />
|
||||||
<Route path="/pacientes" element={<TablePaciente />} />
|
<Route path="/pacientes" element={<TablePaciente setDictInfo={setDictInfo}/>} />
|
||||||
<Route path="/medicos" element={<DoctorTable />} />
|
<Route path="/medicos" element={<DoctorTable setDictInfo={setDictInfo} />} />
|
||||||
<Route path="/pacientes/:id" element={<Details />} />
|
<Route path="/pacientes/details" element={<Details DictInfo={DictInfo} />} />
|
||||||
<Route path="/pacientes/:id/edit" element={<EditPage />} />
|
<Route path="/pacientes/edit" element={<EditPage DictInfo={DictInfo} />} />
|
||||||
<Route path="/medicos/:id" element={<DoctorDetails />} />
|
<Route path="/medicos/details" element={<DoctorDetails DictInfo={DictInfo}/>} />
|
||||||
<Route path="/medicos/:id/edit" element={<DoctorEditPage />} />
|
<Route path="/medicos/edit" element={<DoctorEditPage DictInfo={DictInfo}/>} />
|
||||||
<Route path="/agendamento" element={<Agendamento />} />
|
<Route path="/agendamento" element={<Agendamento />} />
|
||||||
<Route path="/laudo" element={<LaudoManager />} />
|
<Route path="/laudo" element={<LaudoManager />} />
|
||||||
|
|
||||||
|
|||||||
@ -31,11 +31,11 @@ function PerfilSecretaria({ onLogout }) {
|
|||||||
<Route path="pacientes/cadastro" element={<PatientCadastroManager />} />
|
<Route path="pacientes/cadastro" element={<PatientCadastroManager />} />
|
||||||
<Route path="medicos/cadastro" element={<DoctorCadastroManager />} />
|
<Route path="medicos/cadastro" element={<DoctorCadastroManager />} />
|
||||||
<Route path="pacientes" element={<TablePaciente setDictInfo={setDictInfo}/>} />
|
<Route path="pacientes" element={<TablePaciente setDictInfo={setDictInfo}/>} />
|
||||||
<Route path="medicos" element={<DoctorTable />} />
|
<Route path="medicos" element={<DoctorTable setDictInfo={setDictInfo} />} />
|
||||||
<Route path="pacientes/details" element={<Details DictInfo={DictInfo}/>} />
|
<Route path="pacientes/details" element={<Details DictInfo={DictInfo}/>} />
|
||||||
<Route path="pacientes/edit" element={<EditPage DictInfo={DictInfo}/>} />
|
<Route path="pacientes/edit" element={<EditPage DictInfo={DictInfo}/>} />
|
||||||
<Route path="medicos/:id" element={<DoctorDetails />} />
|
<Route path="medicos/details" element={<DoctorDetails doctor={DictInfo} />} />
|
||||||
<Route path="medicos/:id/edit" element={<DoctorEditPage />} />
|
<Route path="medicos/edit" element={<DoctorEditPage DictInfo={DictInfo} />} />
|
||||||
<Route path="agendamento" element={<Agendamento setDictInfo={setDictInfo}/>} />
|
<Route path="agendamento" element={<Agendamento setDictInfo={setDictInfo}/>} />
|
||||||
<Route path="agendamento/edit" element={<AgendamentoEditPage setDictInfo={setDictInfo} DictInfo={DictInfo}/>} />
|
<Route path="agendamento/edit" element={<AgendamentoEditPage setDictInfo={setDictInfo} DictInfo={DictInfo}/>} />
|
||||||
<Route path="laudo" element={<LaudoManager />} />
|
<Route path="laudo" element={<LaudoManager />} />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user