bug: detalhes e editar do doctor
This commit is contained in:
parent
815ce759cd
commit
1d048023b1
@ -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;
|
||||
export default PatientForm;
|
||||
|
||||
@ -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 (
|
||||
<>
|
||||
<div className="card p-3 shadow-sm">
|
||||
@ -36,12 +32,12 @@ const Voltar = () => {
|
||||
<img src={avatarPlaceholder} alt="" />
|
||||
</div>
|
||||
<div className="media-body ms-3 font-extrabold">
|
||||
<span>{doctor.nome || "Nome Completo"}</span>
|
||||
<p>{doctor.cpf || "CPF"}</p>
|
||||
<span>{DictInfo.full_name || "Nome Completo"}</span>
|
||||
<p>{DictInfo.cpf || "CPF"}</p>
|
||||
</div>
|
||||
</div>
|
||||
<Link to={`edit`}>
|
||||
<button className="btn btn-light" onClick={() => {console.log(doctor.id)}} >
|
||||
<button className="btn btn-light" onClick={() => {console.log(DictInfo.id)}} >
|
||||
<i className="bi bi-pencil-square"></i> Editar
|
||||
</button>
|
||||
</Link>
|
||||
@ -55,29 +51,29 @@ const Voltar = () => {
|
||||
<div className="row">
|
||||
<div className="col-md-6 mb-3">
|
||||
<label className="font-extrabold">Nome:</label>
|
||||
<p>{doctor.full_name || "-"}</p>
|
||||
<p>{DictInfo.full_name || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-6 mb-3">
|
||||
<label className="font-extrabold">Data de nascimento:</label>
|
||||
<p>{doctor.birth_date || "-"}</p>
|
||||
<p>{DictInfo.birth_date || "-"}</p>
|
||||
</div>
|
||||
|
||||
<div className="col-md-6 mb-3">
|
||||
<label className="font-extrabold">CPF:</label>
|
||||
<p>{doctor.cpf || "-"}</p>
|
||||
<p>{DictInfo.cpf || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-6 mb-3">
|
||||
<label className="font-extrabold">CRM:</label>
|
||||
<p>{doctor.crm || "-"}</p>
|
||||
<p>{DictInfo.crm || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-6 mb-3">
|
||||
<label className="font-extrabold">Estado do CRM:</label>
|
||||
<p>{doctor.crm_uf || "-"}</p>
|
||||
<p>{DictInfo.crm_uf || "-"}</p>
|
||||
</div>
|
||||
|
||||
<div className="col-md-6 mb-3">
|
||||
<label className="font-extrabold">Especialização:</label>
|
||||
<p>{doctor.specialty || "-"}</p>
|
||||
<p>{DictInfo.specialty || "-"}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -89,31 +85,31 @@ const Voltar = () => {
|
||||
<div className="row">
|
||||
<div className="col-md-4 mb-3">
|
||||
<label className="font-extrabold">CEP:</label>
|
||||
<p>{doctor.cep || "-"}</p>
|
||||
<p>{DictInfo.cep || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-8 mb-3">
|
||||
<label className="font-extrabold">Rua:</label>
|
||||
<p>{doctor.street || "-"}</p>
|
||||
<p>{DictInfo.street || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-4 mb-3">
|
||||
<label className="font-extrabold">Bairro:</label>
|
||||
<p>{doctor.neighborhood || "-"}</p>
|
||||
<p>{DictInfo.neighborhood || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-4 mb-3">
|
||||
<label className="font-extrabold">Cidade:</label>
|
||||
<p>{doctor.city || "-"}</p>
|
||||
<p>{DictInfo.city || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-2 mb-3">
|
||||
<label className="font-extrabold">Estado:</label>
|
||||
<p>{doctor.state || "-"}</p>
|
||||
<p>{DictInfo.state || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-4 mb-3">
|
||||
<label className="font-extrabold">Número:</label>
|
||||
<p>{doctor.number || "-"}</p>
|
||||
<p>{DictInfo.number || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-8 mb-3">
|
||||
<label className="font-extrabold">Complemento:</label>
|
||||
<p>{doctor.complement || "-"}</p>
|
||||
<p>{DictInfo.complement || "-"}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -125,15 +121,15 @@ const Voltar = () => {
|
||||
<div className="row">
|
||||
<div className="col-md-6 mb-3">
|
||||
<label className="font-extrabold">Email:</label>
|
||||
<p>{doctor.email || "-"}</p>
|
||||
<p>{DictInfo.email || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-6 mb-3">
|
||||
<label className="font-extrabold">Telefone:</label>
|
||||
<p>{doctor.phone_mobile || "-"}</p>
|
||||
<p>{DictInfo.phone_mobile || "-"}</p>
|
||||
</div>
|
||||
<div className="col-md-6 mb-3">
|
||||
<label className="font-extrabold">Telefone 2:</label>
|
||||
<p>{doctor.phone2 || "-"}</p>
|
||||
<p>{DictInfo.phone2 || "-"}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@ -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 (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold mb-4">
|
||||
{mode === "availability"
|
||||
? `Editar Horário Disponível (ID: ${availabilityId.substring(0, 8)})`
|
||||
: `Editar Médico (ID: ${DoctorID})`}
|
||||
</h1>
|
||||
|
||||
<DoctorForm
|
||||
onSave={
|
||||
mode === "availability" ? HandlePatchAvailability : HandlePutDoctor
|
||||
|
||||
@ -37,7 +37,7 @@ const HandlePutPatient = async () => {
|
||||
};
|
||||
|
||||
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"))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user