From ae5988997e38c688cb0e0d6bd9a3d90f9e457d48 Mon Sep 17 00:00:00 2001 From: Caio Miguel Lima Nunes Date: Wed, 24 Sep 2025 18:57:18 -0300 Subject: [PATCH] Adicionado o modal no codigo --- src/components/doctors/DoctorForm.jsx | 173 +++++------------------- src/components/patients/PatientForm.jsx | 51 +++++-- src/pages/DoctorCadastroManager.jsx | 42 ++++-- src/pages/PatientCadastroManager.jsx | 3 +- 4 files changed, 110 insertions(+), 159 deletions(-) diff --git a/src/components/doctors/DoctorForm.jsx b/src/components/doctors/DoctorForm.jsx index 7255942..c7e8242 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 673a405..58352a8 100644 --- a/src/components/patients/PatientForm.jsx +++ b/src/components/patients/PatientForm.jsx @@ -2,6 +2,10 @@ 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); @@ -169,18 +173,20 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { const handleSubmit = async () => { if (!formData.nome || !formData.cpf || !formData.sexo || !formData.data_nascimento){ - alert('Por favor, preencha Nome ,CPF, Gênero e data de nascimento.'); + 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; } - onSave({ ...formData, endereco: { @@ -214,10 +220,39 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) { pacienteVip: formData.pacienteVip, }, }); + setMessage('Paciente salvo com sucesso!'); + setMessageType('success'); + setShowMessage(true); }; return ( -
+
+ {/* Modal de feedback */} + {showMessage && ( +
+ )} + {showMessage && ( +
+
+
+
+
+ {messageType === 'danger' ? 'Atenção' : 'Sucesso'} +
+ +
+
+ {message} +
+
+ +
+
+
+
+ )}

MediConnect

{/* DADOS PESSOAIS */} @@ -281,7 +316,7 @@ function PatientForm({ onSave, onCancel,formData, setFormData }) {
- +
diff --git a/src/pages/DoctorCadastroManager.jsx b/src/pages/DoctorCadastroManager.jsx index 3a928c4..3976e53 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/PatientCadastroManager.jsx b/src/pages/PatientCadastroManager.jsx index 7653975..832eb93 100644 --- a/src/pages/PatientCadastroManager.jsx +++ b/src/pages/PatientCadastroManager.jsx @@ -30,8 +30,7 @@ function PatientCadastroManager( {setCurrentPage} ) { .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 + ; //altere isso para integração com backend // Após salvar, voltamos para a tela de lista };