diff --git a/src/components/doctors/DoctorForm.jsx b/src/components/doctors/DoctorForm.jsx
index 5254aa2..7044d17 100644
--- a/src/components/doctors/DoctorForm.jsx
+++ b/src/components/doctors/DoctorForm.jsx
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import {Link} from 'react-router-dom'
-function DoctorForm({ onSave, onCancel, PatientDict }) {
+function DoctorForm({ onSave, onCancel, formData, setFormData }) {
const FormatTelefones = (valor) => {
@@ -30,47 +30,7 @@ function DoctorForm({ onSave, onCancel, PatientDict }) {
}
- const [formData, setFormData] = useState({
- foto: null,
- nome: PatientDict.nome,
- nomeSocial: PatientDict.nome_social,
- dataNascimento: PatientDict.data_nascimento,
- genero: PatientDict.sexo,
- cpf: PatientDict.cpf,
- profissao: PatientDict.profissao ,
- nomeConjuge: '',
- outroId: '',
- cep: '',
- cidade: PatientDict.cidade,
- estado: PatientDict.estado,
- bairro: PatientDict.bairro,
- rua: PatientDict.logradouro,
- numero: '',
- complemento: '',
- email: PatientDict.email,
- telefone1: PatientDict.celular,
- telefone2: '',
- telefone3: '',
- observacoes: '',
- rg: '',
- documentoTipo: '',
- numeroDocumento: '',
- etniaRaca: '',
- naturalidade: '',
- nacionalidade: '',
- estadoCivil: '',
-
- // INFORMAÇÕES MÉDICAS
- tipoSanguineo: '',
- peso: '',
- altura: '',
- imc: '',
- alergias: '',
-
- // ANEXO
- anexos: null,
- });
-
+
// Estado para armazenar a URL da foto do avatar
const [avatarUrl, setAvatarUrl] = useState(null);
@@ -94,6 +54,8 @@ function DoctorForm({ onSave, onCancel, PatientDict }) {
const handleChange = (e) => {
const { name, value, type, checked, files } = e.target;
+ console.log(name, value)
+
if (type === 'checkbox') {
setFormData({ ...formData, [name]: checked });
} else if (type === 'file') {
@@ -110,9 +72,7 @@ function DoctorForm({ onSave, onCancel, PatientDict }) {
setAvatarUrl(null); // Limpa o avatar se nenhum arquivo for selecionado
}
- } else {
- setFormData({ ...formData, [name]: value });
- }
+ }
if (name.includes('cpf')) {
let cpfFormatado = FormatCPF(value);
@@ -120,6 +80,8 @@ function DoctorForm({ onSave, onCancel, PatientDict }) {
} else if (name.includes('telefone')) {
let telefoneFormatado = FormatTelefones(value);
setFormData(prev => ({ ...prev, [name]: telefoneFormatado }));
+ }else {
+ setFormData({ ...formData, [name]: value });
}
};
@@ -156,35 +118,14 @@ function DoctorForm({ onSave, onCancel, PatientDict }) {
if (!formData.nome || !formData.cpf || !formData.genero || !formData.dataNascimento ) {
setModalMsg('Por favor, preencha: Nome, CPF, Gênero, Data de Nascimento.');
setShowModal(true);
- return;
+
}
onSave(
{
- ...formData,
- endereco: {
- cep: formData.cep,
- cidade: formData.cidade,
- estado: formData.estado,
- bairro: formData.bairro,
- logradouro: formData.rua,
- numero: formData.numero,
- complemento: formData.complemento,
- },
- contato: {
- email: formData.email,
- telefone1: formData.telefone1,
- telefone2: formData.telefone2,
- telefone3: formData.telefone3,
- },
- infoMedicas: {
- tipoSanguineo: formData.tipoSanguineo,
- peso: formData.peso,
- altura: formData.altura,
- imc: formData.imc,
- alergias: formData.alergias,
- }
+ ...formData, crm_uf:'SE',crm:'1234'
}
+
);
setModalMsg('Médico salvo com sucesso!');
setShowModal(true);
@@ -267,7 +208,7 @@ function DoctorForm({ onSave, onCancel, PatientDict }) {
{/* CADASTRO */}
-
+
@@ -275,11 +216,11 @@ function DoctorForm({ onSave, onCancel, PatientDict }) {
-
+
-
-
+
diff --git a/src/components/utils/Functions-Endpoints/Doctor.js b/src/components/utils/Functions-Endpoints/Doctor.js
new file mode 100644
index 0000000..2d6046f
--- /dev/null
+++ b/src/components/utils/Functions-Endpoints/Doctor.js
@@ -0,0 +1,26 @@
+import API_KEY from "../apiKeys";
+
+
+
+const GetDoctorByID = async (ID,authHeader) => {
+
+ console.log(authHeader, 'mostrando autorização dentro da função')
+
+ var myHeaders = new Headers();
+ myHeaders.append('apikey', API_KEY)
+ myHeaders.append('Authorization', authHeader)
+
+ var requestOptions = {
+ method: 'GET',
+ redirect: 'follow',
+ headers:myHeaders
+};
+
+
+const result = await fetch(`https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/doctors?id=eq.${ID}`, requestOptions)
+const DictMedico = await result.json()
+return DictMedico
+
+}
+
+export {GetDoctorByID}
\ No newline at end of file
diff --git a/src/pages/DoctorCadastroManager.jsx b/src/pages/DoctorCadastroManager.jsx
index ac36ee2..a4764fb 100644
--- a/src/pages/DoctorCadastroManager.jsx
+++ b/src/pages/DoctorCadastroManager.jsx
@@ -7,13 +7,10 @@ import API_KEY from '../components/utils/apiKeys';
function DoctorCadastroManager( ) {
- // Este estado vai controlar qual "tela" mostrar: 'list' (lista) ou 'form' (formulário)
-
+ const [DoctorDict, setDoctorDict] = useState({})
+
const { getAuthorizationHeader, isAuthenticated } = useAuth();
- var myHeaders = new Headers();
- myHeaders.append("Content-Type", "application/json");
-
// Estado do modal de sucesso
const [showModal, setShowModal] = useState(false);
const [modalMsg, setModalMsg] = useState('');
@@ -84,7 +81,8 @@ function DoctorCadastroManager( ) {
diff --git a/src/pages/DoctorDetails.jsx b/src/pages/DoctorDetails.jsx
index c8b7726..6eff137 100644
--- a/src/pages/DoctorDetails.jsx
+++ b/src/pages/DoctorDetails.jsx
@@ -1,19 +1,32 @@
import React, { useEffect, useState } from "react";
import avatarPlaceholder from '../assets/images/avatar_placeholder.png';
+import { useParams } from "react-router-dom";
+import { GetDoctorByID } from "../components/utils/Functions-Endpoints/Doctor";
+import { useAuth } from "../components/utils/AuthProvider";
-const Details = ({ patientID, setCurrentPage }) => {
- const [paciente, setPaciente] = useState({});
+const Details = ({setCurrentPage }) => {
+ const {getAuthorizationHeader, isAuthenticated} = useAuth();
+ const [doctor, setDoctor] = useState({});
+ const Parametros = useParams()
+ const doctorID = Parametros.id
useEffect(() => {
- if (!patientID) return;
+ if (!doctorID) return;
- fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientID}`)
- .then(res => res.json())
- .then(data => setPaciente(data))
- .catch(err => console.error("Erro ao buscar médico:", err));
- }, [patientID]);
+ const authHeader = getAuthorizationHeader()
- //if (!paciente) return Carregando...
;
+ 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 (
<>
@@ -29,8 +42,8 @@ const Details = ({ patientID, setCurrentPage }) => {
-
{paciente.nome || "Nome Completo"}
-
{paciente.cpf || "CPF"}
+
{doctor.nome || "Nome Completo"}
+
{doctor.cpf || "CPF"}