From cdc6d39f779b5a89fc5cf79dc6038c3747cefdec Mon Sep 17 00:00:00 2001 From: jp-lima Date: Wed, 24 Sep 2025 16:25:38 -0300 Subject: [PATCH] =?UTF-8?q?Come=C3=A7o=20da=20funcionalidade=20de=20CPF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AgendarConsulta/FormNovaConsulta.jsx | 113 ++++++++++++------ src/pages/PatientCadastroManager.jsx | 2 +- src/pages/Table.jsx | 43 +------ 3 files changed, 76 insertions(+), 82 deletions(-) diff --git a/src/components/AgendarConsulta/FormNovaConsulta.jsx b/src/components/AgendarConsulta/FormNovaConsulta.jsx index 6a0e5dd..7d9f116 100644 --- a/src/components/AgendarConsulta/FormNovaConsulta.jsx +++ b/src/components/AgendarConsulta/FormNovaConsulta.jsx @@ -13,16 +13,27 @@ const FormNovaConsulta = ({ onCancel }) => { if(resultado === false){ setAcessibilidade({...acessibilidade, [id]:true}); console.log('mudou')} else if(resultado === true){ setAcessibilidade({...acessibilidade, [id]:false})} - - - - - console.log(id) - } - const BuscarCPFnoBancodeDados = (cpf) => { + + const FormatCPF = (valor) => { + + + console.log(valor) + + const digits = String(valor).replace(/\D/g, '').slice(0, 11); + BuscarPacienteExistentePeloCPF(valor) + + return digits + .replace(/(\d{3})(\d)/, '$1.$2') + .replace(/(\d{3})(\d)/, '$1.$2') + .replace(/(\d{3})(\d{1,2})$/, '$1-$2'); + + } + + + const BuscarCPFnoBancodeDados = async (cpf) => { var myHeaders = new Headers(); myHeaders.append("Authorization", "Bearer "); @@ -39,17 +50,41 @@ const FormNovaConsulta = ({ onCancel }) => { redirect: 'follow' }; -fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/validar-cpf", requestOptions) - .then(response => response.text()) - .then(result => console.log(result)) - .catch(error => console.log('error', error)); + const response = await fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/validar-cpf", requestOptions); + const result = await response.json(); + return result + + } - const BuscarPacienteExistentePeloCPF = (value) => { + const BuscarPacienteExistentePeloCPF = async (value) => { - if(isNaN(value[13]) === false){ - BuscarCPFnoBancodeDados(value) - } + if(isNaN(value[13]) === false && value.length === 14)try { + const result = await BuscarCPFnoBancodeDados(value); + console.log("Resultado:", result); + + if (result.data.existe === true){ + + var myHeaders = new Headers(); + myHeaders.append("Authorization", "Bearer "); + + var requestOptions = { + method: 'GET', + headers: myHeaders, + redirect: 'follow' + }; + + fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/", requestOptions) + .then(response => response.json()) + .then(result => console.log(result)) + .catch(error => console.log('error', error)); + } + + + + } catch (error) { + console.log("error", error); + } //BuscarCPFnoBancodeDados(value) @@ -75,9 +110,9 @@ fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/validar-cpf", requ
- BuscarPacienteExistentePeloCPF(e.target.value)}> - {(inputProps) => } - + + e.target.value = FormatCPF(e.target.value)} /> +
@@ -132,30 +167,30 @@ fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/validar-cpf", requ
- -
handleclickAcessibilidade(e.currentTarget.id)}> + +
handleclickAcessibilidade(e.currentTarget.id)}> + + accessible +
+ +
handleclickAcessibilidade(e.currentTarget.id)}> + elderly +
- accessible -
+
handleclickAcessibilidade(e.currentTarget.id)}> + pregnant_woman +
+ +
handleclickAcessibilidade(e.currentTarget.id)}> + -
handleclickAcessibilidade(e.currentTarget.id)}> - elderly -
- -
handleclickAcessibilidade(e.currentTarget.id)}> - pregnant_woman -
+
+ +
handleclickAcessibilidade(e.currentTarget.id)}> + +
-
handleclickAcessibilidade(e.currentTarget.id)}> - - -
- -
handleclickAcessibilidade(e.currentTarget.id)}> - -
- -
+
diff --git a/src/pages/PatientCadastroManager.jsx b/src/pages/PatientCadastroManager.jsx index 7653975..05d14be 100644 --- a/src/pages/PatientCadastroManager.jsx +++ b/src/pages/PatientCadastroManager.jsx @@ -31,7 +31,7 @@ function PatientCadastroManager( {setCurrentPage} ) { .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 + alert(`Paciente "${patientData.nome}" !`); //altere isso para integração com backend // Após salvar, voltamos para a tela de lista }; diff --git a/src/pages/Table.jsx b/src/pages/Table.jsx index a5eb050..bfc0e06 100644 --- a/src/pages/Table.jsx +++ b/src/pages/Table.jsx @@ -59,9 +59,6 @@ function TablePaciente({ setCurrentPage, setPatientID }) { } - - - // Função para excluir paciente const deletePatient = async (id) => { DeleteAnexo(id) @@ -79,45 +76,7 @@ function TablePaciente({ setCurrentPage, setPatientID }) { .catch((error) => console.log("Deu problema", error)); }; - // Função para marcar/desmarcar VIP - const toggleVIP = async (id, atual) => { - const novoStatus = atual === true ? false : true; - - await fetch( - `https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`, - { - method: "PUT", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ vip: novoStatus }), - } - ) - .then((response) => response.json()) - .then(() => { - setPacientes((prev) => - prev.map((p) => (p.id === id ? { ...p, vip: novoStatus } : p)) - ); - }) - .catch((error) => console.log("Erro ao atualizar VIP:", error)); - }; - - // Função para atualizar convênio/particular - const updateConvenio = async (id, convenio) => { - await fetch( - `https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`, - { - method: "PUT", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ convenio }), - } - ) - .then((response) => response.json()) - .then(() => { - setPacientes((prev) => - prev.map((p) => (p.id === id ? { ...p, convenio } : p)) - ); - }) - .catch((error) => console.log("Erro ao atualizar convênio:", error)); - }; + // Requisição inicial para buscar pacientes useEffect(() => {