diff --git a/src/components/doctors/DoctorForm.jsx b/src/components/doctors/DoctorForm.jsx index 72559427..c7e82422 100644 --- a/src/components/doctors/DoctorForm.jsx +++ b/src/components/doctors/DoctorForm.jsx @@ -124,6 +124,9 @@ function DoctorForm({ onSave, onCancel, PatientDict }) { }; // Função para buscar endereço pelo CEP + const [showModal, setShowModal] = useState(false); + const [modalMsg, setModalMsg] = useState(''); + const handleCepBlur = async () => { const cep = formData.cep.replace(/\D/g, ''); if (cep.length === 8) { @@ -139,17 +142,20 @@ function DoctorForm({ onSave, onCancel, PatientDict }) { estado: data.uf || '' })); } else { - alert('CEP não encontrado!'); + setModalMsg('CEP não encontrado!'); + setShowModal(true); } } catch (error) { - alert('Erro ao buscar o CEP.'); + setModalMsg('Erro ao buscar o CEP.'); + setShowModal(true); } } }; const handleSubmit = () => { - if (!formData.nome || !formData.cpf || !formData.genero || !formData.dataNascimento || !formData.email) { - alert('Por favor, preencha: Nome ,CPF, Gênero, Data de Nascimento e Email.'); + if (!formData.nome || !formData.cpf || !formData.genero || !formData.dataNascimento ) { + setModalMsg('Por favor, preencha: Nome, CPF, Gênero, Data de Nascimento.'); + setShowModal(true); return; } @@ -180,9 +186,31 @@ function DoctorForm({ onSave, onCancel, PatientDict }) { } } ); + setModalMsg('Médico salvo com sucesso!'); + setShowModal(true); }; return ( + <> + {/* Modal de feedback */} + {showModal && ( +
+
+
+
+
Atenção
+ +
+
+

{modalMsg}

+
+
+ +
+
+
+
+ )}

MediConnect

@@ -247,7 +275,7 @@ function DoctorForm({ onSave, onCancel, PatientDict }) {
- +
@@ -406,11 +434,11 @@ function DoctorForm({ onSave, onCancel, PatientDict }) {
- +
- +
@@ -434,137 +462,10 @@ function DoctorForm({ onSave, onCancel, PatientDict }) { Cancelar
+
- //
- //

MediConnect

- - // {/* ------------------ DADOS PESSOAIS ------------------ */} - //
Dados Pessoais
- //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- - // {/* ------------------ ENDEREÇO ------------------ */} - //
Endereço
- //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- - // {/* ------------------ CONTATO ------------------ */} - //
Contato
- //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- // - // - //
- //
- - // {/* ------------------ INFORMAÇÕES ADICIONAIS ------------------ */} - //
Informações Adicionais
- //
- // - // - //
- - // {/* Botões */} - //
- // - // - //
- //
+ ); } - export default DoctorForm; diff --git a/src/components/patients/PatientForm.jsx b/src/components/patients/PatientForm.jsx index 43d8f3e4..04cf8979 100644 --- a/src/components/patients/PatientForm.jsx +++ b/src/components/patients/PatientForm.jsx @@ -1,8 +1,15 @@ import React, { useState, useEffect } from 'react'; + function PatientForm({ onSave, onCancel,formData, setFormData }) { + // Estado para controlar modal de feedback + const [showMessage, setShowMessage] = useState(false); + const [message, setMessage] = useState(''); + const [messageType, setMessageType] = useState('success'); // 'success' ou 'danger' + + const FormatTelefones = (valor) => { const digits = String(valor).replace(/\D/g, '').slice(0, 11); return digits @@ -32,7 +39,6 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { const result = await response.json() return result.data - } @@ -40,10 +46,10 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { let aviso let Erro = false - const resutadoAPI = await ReceberRespostaAPIdoCPF(cpf) + const resultadoAPI = await ReceberRespostaAPIdoCPF(cpf) - const valido = resutadoAPI.valido - const ExisteNoBancoDeDados = resutadoAPI.existe + const valido = resultadoAPI.valido + const ExisteNoBancoDeDados = resultadoAPI.existe if(valido === false){ aviso = 'CPF inválido' @@ -109,8 +115,6 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { const handleChange = (e) => { const { name, value, type, checked, files } = e.target; - console.log(formData, name) - if (type === 'checkbox') { setFormData({ ...formData, [name]: checked }); } else if (type === 'file') { @@ -132,7 +136,7 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { setFormData({...formData, cpf:FormatCPF(value) }); - } else if (name.includes('telefone')) { + }else if (name.includes('telefone')) { let telefoneFormatado = FormatTelefones(value); setContato(prev => ({ ...prev, [name]: telefoneFormatado })); }else if (name === 'email') { @@ -140,6 +144,7 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { }else if(name.includes('endereco')) { setEnderecoData(prev => ({ ...prev, [name.split('.')[1]]: value })); }else{ + console.log(formData, value) setFormData({ ...formData, [name]: value }); } }; @@ -170,20 +175,24 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { const handleSubmit = async (e) => { e.preventDefault(); if (!formData.nome || !formData.cpf || !formData.sexo || !formData.data_nascimento){ - alert('Por favor, preencha Nome ,CPF, Gênero e data de nascimento.'); + console.log(formData) + setMessage('Por favor, preencha: Nome, CPF, Gênero, Data de Nascimento .'); + setMessageType('danger'); + setShowMessage(true); return; } - const CPFinvalido = await ValidarCPF(formData.cpf) - console.log(CPFinvalido) + const CPFinvalido = await ValidarCPF(formData.cpf); if(CPFinvalido[0] === true){ - alert(CPFinvalido[1]) - return + setMessage(CPFinvalido[1]); + setMessageType('danger'); + setShowMessage(true); return } - const pacienteSalvo = await onSave({ + const pacienteSalvo = await onSave({ ...formData, + id: 2, endereco: { cep: enderecoData.cep, cidade: enderecoData.cidade, @@ -214,14 +223,19 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { validadeIndeterminada: formData.validadeIndeterminada, pacienteVip: formData.pacienteVip, }, + }); + setMessage('Paciente salvo com sucesso!'); + setMessageType('success'); + setShowMessage(true); + const pacienteId = pacienteSalvo.id; try{ if (formData.foto) await uploadFotoPaciente(pacienteId, formData.foto); if (formData.anexos) await uploadAnexoPaciente(pacienteId, formData.anexos); - alert("Paciente salvo com sucesso!"); + } catch (error) { console.error(error); alert("Erro ao salvar paciente ou enviar arquivos."); @@ -256,13 +270,40 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { if (!res.ok) throw new Error('Erro ao enviar anexo'); alert('Anexo enviado com sucesso!'); } catch (err) { - console.error(err); - alert('Falha ao enviar anexo'); + console.error(err, 'deu erro'); + } - }; + + }; return ( -
+
+ {/* Modal de feedback */} + {showMessage && ( +
+ )} + {showMessage && ( +
+
+
+
+
+ {messageType === 'danger' ? 'Atenção' : 'Sucesso'} +
+ +
+
+ {message} +
+
+ +
+
+
+
+ )}

MediConnect

{/* DADOS PESSOAIS */} @@ -326,7 +367,7 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) {
- +
diff --git a/src/pages/DoctorCadastroManager.jsx b/src/pages/DoctorCadastroManager.jsx index 3a928c44..3976e53b 100644 --- a/src/pages/DoctorCadastroManager.jsx +++ b/src/pages/DoctorCadastroManager.jsx @@ -12,6 +12,10 @@ function DoctorCadastroManager( ) { var myHeaders = new Headers(); myHeaders.append("Content-Type", "application/json"); + // Estado do modal de sucesso + const [showModal, setShowModal] = useState(false); + const [modalMsg, setModalMsg] = useState(''); + // Função que será chamada para "salvar" o paciente const handleSavePatient = (patientData) => { console.log('Salvando médico:', patientData); @@ -23,32 +27,45 @@ function DoctorCadastroManager( ) { header: myHeaders, body:raw, redirect:'follow' - } + fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions) + .then(response => response.text()) + .then(result => console.log(result)) + .catch(error => console.log('error', error)); - fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions) - .then(response => response.text()) - .then(result => console.log(result)) - .catch(error => console.log('error', error)); - - alert(`Médico "${patientData.nome}" salvo com sucesso!`); //altere isso para integração com backend - // Após salvar, voltamos para a tela de lista + setModalMsg(`Médico "${patientData.nome}" salvo com sucesso!`); + setShowModal(true); setView('list'); }; return ( <> + {/* Modal de feedback */} + {showModal && ( +
+
+
+
+
Sucesso
+ +
+
+

{modalMsg}

+
+
+ +
+
+
+
+ )}

Cadastro de Médicos

- {/* Aqui está a lógica principal: */} - {/* Se a view for 'list', mostramos a lista com o botão. */} - {/* Se for 'form', mostramos o formulário de cadastro. */} - {view === 'list' ? ( setView('form')} /> ) : ( @@ -56,7 +73,6 @@ function DoctorCadastroManager( ) { onSave={handleSavePatient} onCancel={() => setView('list')} PatientDict={{}} - /> )}
diff --git a/src/pages/EditPage.jsx b/src/pages/EditPage.jsx index b204fd95..b706ef92 100644 --- a/src/pages/EditPage.jsx +++ b/src/pages/EditPage.jsx @@ -23,30 +23,41 @@ fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`, requestOpt .catch(error => console.log('error', error)); }, []) +const HandlePutPatient = async () => { + //alert(`Atualizando paciente "${PatientToPUT.nome}" com sucesso`); -const HandlePutPatient = () => { - alert(`Atualizando paciente "${PatientToPUT.nome}" com sucesso`) - var myHeaders = new Headers(); -myHeaders.append("Authorization", "Bearer "); -myHeaders.append("Content-Type", "application/json"); + var myHeaders = new Headers(); + myHeaders.append("Authorization", "Bearer "); + myHeaders.append("Content-Type", "application/json"); -var raw = JSON.stringify(PatientToPUT) + var raw = JSON.stringify(PatientToPUT); -console.log(PatientToPUT) + console.log("Enviando paciente para atualização:", PatientToPUT); -var requestOptions = { - method: 'PUT', - headers: myHeaders, - body: raw, - redirect: 'follow' + var requestOptions = { + method: 'PUT', + headers: myHeaders, + body: raw, + redirect: 'follow' + }; + + try { + const response = await fetch( + "https://mock.apidog.com/m1/1053378-0-default/pacientes/" + PatientToPUT.id, + requestOptions + ); + + // se o backend retorna JSON + const result = await response.json(); + console.log("ATUALIZADO COM SUCESSO", result); + + return result; // <- importante! + } catch (error) { + console.error("Erro ao atualizar paciente:", error); + throw error; + } }; -fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/", requestOptions) - .then(response => response.text()) - .then(result => console.log('ATUALIZADO COM SUCESSO',result)) - .catch(error => console.log('error', error)); - - } return ( diff --git a/src/pages/PatientCadastroManager.jsx b/src/pages/PatientCadastroManager.jsx index 7653975a..e33e7d49 100644 --- a/src/pages/PatientCadastroManager.jsx +++ b/src/pages/PatientCadastroManager.jsx @@ -13,29 +13,32 @@ function PatientCadastroManager( {setCurrentPage} ) { myHeaders.append("Content-Type", "application/json"); // Função que será chamada para "salvar" o paciente - const handleSavePatient = (patientData) => { - console.log('Salvando paciente:', patientData); + const handleSavePatient = async (patientData) => { + console.log('Salvando paciente:', patientData); - var raw = JSON.stringify(patientData) + var raw = JSON.stringify(patientData); - var requestOptions = { - method:'POST', - header: myHeaders, - body:raw, - redirect:'follow' - } - - - fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions) - .then(response => response.text()) - .then(result => console.log(result)) - .catch(error => console.log('error', error)); - - alert(`Paciente "${patientData.nome}" salvo com sucesso!`); //altere isso para integração com backend - // Após salvar, voltamos para a tela de lista - + var requestOptions = { + method: 'POST', + headers: { + "Content-Type": "application/json" + }, + body: raw, + redirect: 'follow' }; + try { + const response = await fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions); + const result = await response.json(); + console.log("Paciente salvo no backend:", result); + return result; + } catch (error) { + console.error("Erro ao salvar paciente:", error); + throw error; + } +}; + + return ( <>