+ {/* Header */}
+
+
Atenção
+
+
- {/* Modal para paciente existente */}
- {showModal && pacienteExistente && (
-
- )}
+ {/* Body */}
+
+
+ Por favor, preencha:
+
+
+ {!formData.full_name &&
- Nome
}
+ {!formData.cpf &&
- CPF
}
+ {!formData.email &&
- Email
}
+ {!formData.phone_mobile &&
- Telefone
}
+
+
- {/* Modal de sucesso ao salvar paciente */}
- {showSuccessModal && (
-
-
-
-
-
Paciente salvo com sucesso!
-
-
-
-
O cadastro do paciente foi realizado com sucesso.
-
-
-
-
+ {/* Footer */}
+
+
)}
+ {/* Modal de sucesso */}
+ {showSuccessModal && (
+
+
+ {/* Header */}
+
+
Sucesso
+
+
+ {/* Body */}
+
+
+ O cadastro do paciente foi realizado com sucesso.
+
+
+
+ {/* Footer */}
+
+
+
+
+
+)}
);
}
diff --git a/src/data/sidebar-items-secretaria.json b/src/data/sidebar-items-secretaria.json
index 1944cdd..afe9e0a 100644
--- a/src/data/sidebar-items-secretaria.json
+++ b/src/data/sidebar-items-secretaria.json
@@ -6,7 +6,7 @@
{
"name":"Início",
- "url": "/secretaria/inicio",
+ "url": "/secretaria/",
"icon": "house"
},
diff --git a/src/pages/DoctorCadastroManager.jsx b/src/pages/DoctorCadastroManager.jsx
index 0af6c44..f6805e2 100644
--- a/src/pages/DoctorCadastroManager.jsx
+++ b/src/pages/DoctorCadastroManager.jsx
@@ -1,37 +1,47 @@
import React, { useState } from 'react';
-
-// Importamos os dois novos componentes que criamos
import { useAuth } from '../components/utils/AuthProvider';
import DoctorForm from '../components/doctors/DoctorForm';
import API_KEY from '../components/utils/apiKeys';
-import { Navigate, useNavigate } from 'react-router-dom';
+import { useNavigate, useLocation } from 'react-router-dom';
-
-function DoctorCadastroManager( ) {
+function DoctorCadastroManager() {
const [DoctorDict, setDoctorDict] = useState({})
const navigate = useNavigate();
+ const location = useLocation();
+ const { getAuthorizationHeader, isAuthenticated } = useAuth();
- const { getAuthorizationHeader, isAuthenticated } = useAuth();
-
- // Estado do modal de sucesso
- const [showModal, setShowModal] = useState(false);
- const [modalMsg, setModalMsg] = useState('');
-
- // Função que será chamada para salvar o médico no banco de dados
const handleSaveDoctor = async (doctorData) => {
const authHeader = getAuthorizationHeader();
-
var myHeaders = new Headers();
- myHeaders.append("Content-Type", "application/json");
- myHeaders.append("apikey", API_KEY)
- myHeaders.append("Authorization", authHeader)
+ myHeaders.append("Content-Type", "application/json");
+ myHeaders.append("apikey", API_KEY);
+ myHeaders.append("Authorization", authHeader);
+ console.log(' Dados recebidos do Form:', doctorData);
- console.log('Salvando paciente:', doctorData);
+ const cleanedData = {
+ full_name: doctorData.full_name,
+ cpf: doctorData.cpf ? doctorData.cpf.replace(/\D/g, '') : null,
+ birth_date: doctorData.birth_date || null,
+ email: doctorData.email,
+ phone_mobile: doctorData.phone_mobile ? doctorData.phone_mobile.replace(/\D/g, '') : null,
+ crm_uf: doctorData.crm_uf,
+ crm: doctorData.crm,
+ specialty: doctorData.specialty || null,
+ cep: doctorData.cep ? doctorData.cep.replace(/\D/g, '') : null,
+ street: doctorData.street || null,
+ neighborhood: doctorData.neighborhood || null,
+ city: doctorData.city || null,
+ state: doctorData.state || null,
+ number: doctorData.number || null,
+ complement: doctorData.complement || null,
+ phone2: doctorData.phone2 ? doctorData.phone2.replace(/\D/g, '') : null,
+ };
- var raw = JSON.stringify(doctorData);
- console.log(doctorData, 'aqui')
+ console.log(' Dados limpos para envio:', cleanedData);
+
+ var raw = JSON.stringify(cleanedData);
var requestOptions = {
method: 'POST',
@@ -41,35 +51,57 @@ function DoctorCadastroManager( ) {
};
try {
- const response = await fetch("https://yuanqfswhberkoevtmfr.supabase.co/rest/v1//doctors", requestOptions);
-
- console.log("Médico salvo no backend:", response);
+ const response = await fetch("https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/doctors", requestOptions);
+
+ console.log(" Status da resposta:", response.status);
+ console.log(" Response ok:", response.ok);
+
+ if (!response.ok) {
+ let errorMessage = `Erro HTTP: ${response.status}`;
+ try {
+ const errorData = await response.json();
+ console.error(" Erro detalhado:", errorData);
+ errorMessage = errorData.message || errorData.details || errorMessage;
+ } catch (e) {
+ const errorText = await response.text();
+ console.error(" Erro texto:", errorText);
+ errorMessage = errorText || errorMessage;
+ }
+ throw new Error(errorMessage);
+ }
+
+ const result = await response.json();
+ console.log("Médico salvo no backend:", result);
+
+ // Redireciona para a lista de médicos do perfil atual
+ const prefixo = location.pathname.split("/")[1];
+ navigate(`/${prefixo}/medicos`);
+
+ return result;
- return response;
} catch (error) {
- console.error("Erro ao salvar Médico:", error);
+ console.error(" Erro ao salvar Médico:", error);
throw error;
}
-};
+ };
return (
<>
- {/* Modal de feedback */}
-
Cadastro de Médicos
-
- {navigate('/medicos')}}
- formData={DoctorDict}
- setFormData={setDoctorDict}
- />
-
+ {
+ const prefixo = location.pathname.split("/")[1];
+ navigate(`/${prefixo}/medicos`);
+ }}
+ formData={DoctorDict}
+ setFormData={setDoctorDict}
+ />
diff --git a/src/pages/DoctorTable.jsx b/src/pages/DoctorTable.jsx
index 14daabc..351b6f3 100644
--- a/src/pages/DoctorTable.jsx
+++ b/src/pages/DoctorTable.jsx
@@ -3,8 +3,8 @@ import API_KEY from "../components/utils/apiKeys";
import { useAuth } from "../components/utils/AuthProvider";
import { Link } from "react-router-dom";
-function TableDoctor({ setCurrentPage, setPatientID }) {
- const {getAuthorizationHeader, isAuthenticated} = useAuth();
+function TableDoctor({ setPatientID }) {
+ const { getAuthorizationHeader, isAuthenticated } = useAuth();
const [medicos, setMedicos] = useState([]);
const [search, setSearch] = useState("");
@@ -75,8 +75,6 @@ function TableDoctor({ setCurrentPage, setPatientID }) {
.catch(error => console.log('error', error));
}, []);
-
-
// Filtrar médicos pelo campo de pesquisa e aniversariantes
const medicosFiltrados = medicos.filter(
(medico) =>
@@ -165,7 +163,7 @@ function TableDoctor({ setCurrentPage, setPatientID }) {
{/* Ver Detalhes */}
-
+
|