diff --git a/src/components/patients/PatientForm.jsx b/src/components/patients/PatientForm.jsx index c554020..ddb76e4 100644 --- a/src/components/patients/PatientForm.jsx +++ b/src/components/patients/PatientForm.jsx @@ -52,6 +52,8 @@ function PatientForm({ onSave, onCancel, formData, setFormData, isLoading }) { })); }; + + useEffect(() => { const peso = parseFloat(formData.weight_kg); const altura = parseFloat(formData.height_m); @@ -63,9 +65,20 @@ function PatientForm({ onSave, onCancel, formData, setFormData, isLoading }) { } }, [formData.weight_kg, formData.height_m, setFormData]); + const handleCep = (value) => { + if(value.length === 8){ + fetch(`https://viacep.com.br/ws/${value}/json/`) + .then(response => response.json()) + .then(result => {setFormData(prev => ({...prev, street:result.logradouro,neighborhood:result.bairro,city:result.localidade, + state:result.estado + + }))}) + } + } + const handleChange = (e) => { const { name, value, type, checked, files } = e.target; - + console.log(name, value) if (value && emptyFields.includes(name)) { setEmptyFields(prev => prev.filter(field => field !== name)); } @@ -101,8 +114,11 @@ function PatientForm({ onSave, onCancel, formData, setFormData, isLoading }) { } else if (name.includes('weight_kg') || name.includes('height_m')) { setFormData(prev => ({ ...prev, [name]: FormatPeso(value) })); } else if (name === 'rn_in_insurance' || name === 'vip' || name === 'validadeIndeterminada') { - setFormData(prev => ({ ...prev, [name]: checked })); - } else { + setFormData(prev => ({ ...prev, [name]: checked })); + } else if(name === 'cep'){ + handleCep(value) + setFormData(prev => ({...prev, [name]: value})) + }else { setFormData(prev => ({ ...prev, [name]: value })); } }; @@ -189,9 +205,6 @@ function PatientForm({ onSave, onCancel, formData, setFormData, isLoading }) { } const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - if (!emailRegex.test(formData.email)) { - throw new Error('Email inválido. Por favor, verifique o email digitado.'); - } await onSave({ ...formData, bmi: parseFloat(formData.bmi) || null }); }; @@ -647,4 +660,4 @@ function PatientForm({ onSave, onCancel, formData, setFormData, isLoading }) { ); } -export default PatientForm; \ No newline at end of file +export default PatientForm; diff --git a/src/pages/DoctorDetails.jsx b/src/pages/DoctorDetails.jsx index e426f75..23e59d4 100644 --- a/src/pages/DoctorDetails.jsx +++ b/src/pages/DoctorDetails.jsx @@ -4,11 +4,12 @@ import { useParams,Link, useNavigate, useLocation } from "react-router-dom"; import { GetDoctorByID } from "../components/utils/Functions-Endpoints/Doctor"; import { useAuth } from "../components/utils/AuthProvider"; -const DoctorDetails = ({doctor}) => { +const DoctorDetails = ({DictInfo}) => { const {getAuthorizationHeader} = useAuth(); const Parametros = useParams() const navigate = useNavigate(); const location = useLocation(); + const Voltar = () => { @@ -16,11 +17,6 @@ const Voltar = () => { navigate(`/${prefixo}/medicos`); } - - - - - return ( <>
@@ -36,12 +32,12 @@ const Voltar = () => {
- {doctor.nome || "Nome Completo"} -

{doctor.cpf || "CPF"}

+ {DictInfo.full_name || "Nome Completo"} +

{DictInfo.cpf || "CPF"}

- @@ -55,29 +51,29 @@ const Voltar = () => {
-

{doctor.full_name || "-"}

+

{DictInfo.full_name || "-"}

-

{doctor.birth_date || "-"}

+

{DictInfo.birth_date || "-"}

-

{doctor.cpf || "-"}

+

{DictInfo.cpf || "-"}

-

{doctor.crm || "-"}

+

{DictInfo.crm || "-"}

-

{doctor.crm_uf || "-"}

+

{DictInfo.crm_uf || "-"}

-

{doctor.specialty || "-"}

+

{DictInfo.specialty || "-"}

@@ -89,31 +85,31 @@ const Voltar = () => {
-

{doctor.cep || "-"}

+

{DictInfo.cep || "-"}

-

{doctor.street || "-"}

+

{DictInfo.street || "-"}

-

{doctor.neighborhood || "-"}

+

{DictInfo.neighborhood || "-"}

-

{doctor.city || "-"}

+

{DictInfo.city || "-"}

-

{doctor.state || "-"}

+

{DictInfo.state || "-"}

-

{doctor.number || "-"}

+

{DictInfo.number || "-"}

-

{doctor.complement || "-"}

+

{DictInfo.complement || "-"}

@@ -125,15 +121,15 @@ const Voltar = () => {
-

{doctor.email || "-"}

+

{DictInfo.email || "-"}

-

{doctor.phone_mobile || "-"}

+

{DictInfo.phone_mobile || "-"}

-

{doctor.phone2 || "-"}

+

{DictInfo.phone2 || "-"}

diff --git a/src/pages/DoctorEditPage.jsx b/src/pages/DoctorEditPage.jsx index 1b75ffa..f50b934 100644 --- a/src/pages/DoctorEditPage.jsx +++ b/src/pages/DoctorEditPage.jsx @@ -45,18 +45,8 @@ const DoctorEditPage = ({DictInfo}) => { redirect: "follow", }; - try { - const response = await fetch( - `https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/doctors?id=eq.${DoctorID}`, - requestOptions - ); - console.log("Resposta PUT Doutor:", response); - alert("Dados do médico atualizados com sucesso!"); - } catch (error) { - console.error("Erro ao atualizar médico:", error); - alert("Erro ao atualizar dados do médico."); - throw error; - } + fetch(`https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/doctors?id=eq.${DictInfo.id}`,requestOptions) + .then(response => console.log(response)) }; // 2. Função para Atualizar DISPONIBILIDADE (PATCH) @@ -97,12 +87,6 @@ const DoctorEditPage = ({DictInfo}) => { return (
-

- {mode === "availability" - ? `Editar Horário Disponível (ID: ${availabilityId.substring(0, 8)})` - : `Editar Médico (ID: ${DoctorID})`} -

- { }; fetch(`https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/patients?id=eq.${PatientToPUT.id}`,requestOptions) - .then(response => response.json) + .then(response => console.log(response)) .then(result => console.log(result)) .catch(console.log("erro"))