amwolf36 commited on
Commit
0807e9d
·
verified ·
1 Parent(s): ab20504

Agora antes dos dados pessoais vamos colocar uma sessao com um formulario de consulta via API usando os numeros do CPF com validação e Mascara. O formulario deve pedir o CPF, quando digitado se estiver incorreto abrir uma modal informando CPF Falso, Invalído ou Politicamente Exposto. Se o CPF for valido use os dados da API para em um efeito de carregamento buscar os dados da API na URL https://dadospublicos.blog/consulta?token=meu_token_secreto&cpf={CPF} que retorna o json da seguinte forma {"mensagem":"O CPF 08609953998 pertence a Alex XXXXXXXX XXXX, sexo M - Masculino e tem 33 anos de idade."}. o botao acessar no cabeçalho, deve rolar para o formulario de consulta na API - Follow Up Deployment

Browse files
Files changed (2) hide show
  1. index.html +149 -2
  2. prompts.txt +2 -1
index.html CHANGED
@@ -94,7 +94,10 @@
94
  <p class="text-blue-100 mt-1">Receba rapidamente informações da pessoa que possui este CPF</p>
95
  </div>
96
  <div class="flex items-center">
97
- <button class="bg-white text-primary px-4 py-2 rounded-md font-medium flex items-center">
 
 
 
98
  <i class="fas fa-sign-in-alt mr-2"></i> Acessar
99
  </button>
100
  </div>
@@ -107,6 +110,39 @@
107
  <div class="grid grid-cols-1 lg:grid-cols-4 gap-6">
108
  <!-- Service Categories (3 cols) -->
109
  <div class="lg:col-span-3 space-y-6">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  <!-- Personal Data -->
111
  <div class="service-category bg-white rounded-xl shadow p-6">
112
  <h2 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
@@ -509,6 +545,31 @@
509
  </div>
510
  </div>
511
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  <!-- Checkout Modal -->
513
  <div id="checkoutModal" class="modal">
514
  <div class="modal-content">
@@ -558,7 +619,93 @@ Arquivo corrigido e completo com as seguintes melhorias:
558
 
559
  <!-- O código HTML permanece inalterado, exceto pela correção do JS no final -->
560
  <script>
561
- const mp = new MercadoPago('YOUR_PUBLIC_KEY', {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
  locale: 'pt-BR'
563
  });
564
 
 
94
  <p class="text-blue-100 mt-1">Receba rapidamente informações da pessoa que possui este CPF</p>
95
  </div>
96
  <div class="flex items-center">
97
+ <button
98
+ onclick="document.getElementById('cpf-form-section').scrollIntoView({ behavior: 'smooth' })"
99
+ class="bg-white text-primary px-4 py-2 rounded-md font-medium flex items-center"
100
+ >
101
  <i class="fas fa-sign-in-alt mr-2"></i> Acessar
102
  </button>
103
  </div>
 
110
  <div class="grid grid-cols-1 lg:grid-cols-4 gap-6">
111
  <!-- Service Categories (3 cols) -->
112
  <div class="lg:col-span-3 space-y-6">
113
+ <!-- CPF Validation Form -->
114
+ <div id="cpf-form-section" class="bg-white rounded-xl shadow p-6">
115
+ <h2 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
116
+ <i class="fas fa-id-card mr-2 text-primary"></i>
117
+ Consulta por CPF
118
+ </h2>
119
+ <form id="cpf-form" class="space-y-4">
120
+ <div>
121
+ <label class="block text-sm font-medium text-gray-700 mb-1">Número do CPF</label>
122
+ <input
123
+ id="cpf-input"
124
+ type="text"
125
+ placeholder="000.000.000-00"
126
+ required
127
+ class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-primary focus:border-primary"
128
+ data-mask="000.000.000-00"
129
+ >
130
+ </div>
131
+ <button
132
+ type="submit"
133
+ class="w-full bg-primary hover:bg-blue-800 text-white font-medium py-3 rounded-md transition"
134
+ >
135
+ <i class="fas fa-search mr-2"></i> Consultar CPF
136
+ </button>
137
+ </form>
138
+ <div id="api-response" class="mt-4 hidden">
139
+ <div class="bg-blue-50 p-4 rounded-md">
140
+ <i class="fas fa-spinner fa-spin text-blue-500 mr-2"></i>
141
+ <span>Consultando dados públicos...</span>
142
+ </div>
143
+ </div>
144
+ </div>
145
+
146
  <!-- Personal Data -->
147
  <div class="service-category bg-white rounded-xl shadow p-6">
148
  <h2 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
 
545
  </div>
546
  </div>
547
 
548
+ <!-- CPF Validation Modal -->
549
+ <div id="cpfModal" class="modal">
550
+ <div class="modal-content">
551
+ <div class="modal-header">
552
+ <h2 class="text-2xl font-bold text-gray-800">CPF Inválido</h2>
553
+ <button class="modal-close text-gray-500 hover:text-gray-700">&times;</button>
554
+ </div>
555
+ <div class="p-4">
556
+ <div class="flex items-start">
557
+ <i class="fas fa-exclamation-triangle text-red-500 text-3xl mr-3"></i>
558
+ <div>
559
+ <h3 class="font-bold text-lg" id="cpf-modal-title">CPF Inválido</h3>
560
+ <p class="text-gray-600 mt-1" id="cpf-modal-message">O CPF informado não é válido ou está em situação irregular.</p>
561
+ </div>
562
+ </div>
563
+ <button
564
+ id="cpf-modal-close"
565
+ class="w-full mt-4 bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-2 rounded-md transition"
566
+ >
567
+ Fechar
568
+ </button>
569
+ </div>
570
+ </div>
571
+ </div>
572
+
573
  <!-- Checkout Modal -->
574
  <div id="checkoutModal" class="modal">
575
  <div class="modal-content">
 
619
 
620
  <!-- O código HTML permanece inalterado, exceto pela correção do JS no final -->
621
  <script>
622
+ // CPF Validation and API Call
623
+ const cpfModal = document.getElementById('cpfModal');
624
+ const cpfForm = document.getElementById('cpf-form');
625
+ const cpfInput = document.getElementById('cpf-input');
626
+ const apiResponse = document.getElementById('api-response');
627
+
628
+ // CPF Validation
629
+ function validateCPF(cpf) {
630
+ cpf = cpf.replace(/[^\d]+/g,'');
631
+ if(cpf.length !== 11 || /^(\d)\1{10}$/.test(cpf)) return false;
632
+
633
+ let sum = 0;
634
+ for (let i = 0; i < 9; i++)
635
+ sum += parseInt(cpf.charAt(i)) * (10 - i);
636
+ let rest = 11 - (sum % 11);
637
+ if(rest === 10 || rest === 11) rest = 0;
638
+ if(rest !== parseInt(cpf.charAt(9))) return false;
639
+
640
+ sum = 0;
641
+ for (let i = 0; i < 10; i++)
642
+ sum += parseInt(cpf.charAt(i)) * (11 - i);
643
+ rest = 11 - (sum % 11);
644
+ if(rest === 10 || rest === 11) rest = 0;
645
+ if(rest !== parseInt(cpf.charAt(10))) return false;
646
+
647
+ return true;
648
+ }
649
+
650
+ function showCPFModal(title, message) {
651
+ document.getElementById('cpf-modal-title').textContent = title;
652
+ document.getElementById('cpf-modal-message').textContent = message;
653
+ cpfModal.style.display = 'block';
654
+ document.body.style.overflow = 'hidden';
655
+ }
656
+
657
+ document.getElementById('cpf-modal-close').addEventListener('click', () => {
658
+ cpfModal.style.display = 'none';
659
+ document.body.style.overflow = 'auto';
660
+ });
661
+
662
+ cpfForm.addEventListener('submit', async (e) => {
663
+ e.preventDefault();
664
+ const cpf = cpfInput.value.replace(/[^\d]+/g,'');
665
+
666
+ if(!validateCPF(cpf)) {
667
+ showCPFModal('CPF Inválido', 'O número de CPF informado não é válido.');
668
+ return;
669
+ }
670
+
671
+ apiResponse.classList.remove('hidden');
672
+ apiResponse.innerHTML = `
673
+ <div class="bg-blue-50 p-4 rounded-md">
674
+ <i class="fas fa-spinner fa-spin text-blue-500 mr-2"></i>
675
+ <span>Consultando dados públicos...</span>
676
+ </div>
677
+ `;
678
+
679
+ try {
680
+ const response = await fetch(`https://dadospublicos.blog/consulta?token=meu_token_secreto&cpf=${cpf}`);
681
+ const data = await response.json();
682
+
683
+ apiResponse.innerHTML = `
684
+ <div class="bg-green-50 p-4 rounded-md">
685
+ <i class="fas fa-check-circle text-green-500 mr-2"></i>
686
+ <span>${data.mensagem}</span>
687
+ </div>
688
+ `;
689
+ } catch (error) {
690
+ apiResponse.innerHTML = `
691
+ <div class="bg-red-50 p-4 rounded-md">
692
+ <i class="fas fa-times-circle text-red-500 mr-2"></i>
693
+ <span>Erro ao consultar CPF. Tente novamente.</span>
694
+ </div>
695
+ `;
696
+ }
697
+ });
698
+
699
+ // Input mask for CPF
700
+ cpfInput.addEventListener('input', function(e) {
701
+ let value = e.target.value.replace(/\D/g, '');
702
+ value = value.replace(/(\d{3})(\d)/, '$1.$2');
703
+ value = value.replace(/(\d{3})(\d)/, '$1.$2');
704
+ value = value.replace(/(\d{3})(\d{1,2})$/, '$1-$2');
705
+ e.target.value = value;
706
+ });
707
+
708
+ const mp = new MercadoPago('APP_USR-6968004978980874-052014-90176298abb4a882412671c4fe3bf14c-2081587558', {
709
  locale: 'pt-BR'
710
  });
711
 
prompts.txt CHANGED
@@ -1,3 +1,4 @@
1
  o formulario só deve aparecer em uma modal elegante e full screen quadno o botao finalizar compra for adicionado. O total do pedido nao esta sendo somado em cada opçao
2
  Estamos com problema na estrutura, nao esta funcionando
3
- Incoreto, '').replace(',', '.')); total += price; }); // Update totals in both places document.querySelectorAll('.total-price').forEach(el => { el.textContent = `R${total.toFixed(2).replace('.', ',')}`; }); return total; } // Modal handling const modal = document.getElementById('checkoutModal'); const openBtn = document.getElementById('open-checkout'); const closeBtn = document.querySelector('.modal-close'); openBtn.addEventListener('click', () => { modal.style.display = 'block'; document.body.style.overflow = 'hidden'; }); closeBtn.addEventListener('click', () => { modal.style.display = 'none'; document.body.style.overflow = 'auto'; }); window.addEventListener('click', (e) => { if (e.target === modal) { modal.style.display = 'none'; document.body.style.overflow = 'auto'; } }); // Handle checkbox changes document.querySelectorAll('input[type="checkbox"]').forEach(checkbox => { checkbox.addEventListener('change', calculateTotal); }); // Checkout form handler document.getElementById('checkout-form').addEventListener('submit', async (e) => { e.preventDefault(); const formData = new FormData(e.target); const customerData = { name: formData.get('name'), email: formData.get('email'), phone: formData.get('phone') }; const total = calculateTotal(); try { // Show loading state document.getElementById('checkout-button').disabled = true; document.getElementById('checkout-button').innerHTML = ' Processando...'; // Create preference with Mercado Pago const response = await fetch('/create-preference', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ customer: customerData, amount: total, items: Array.from(document.querySelectorAll('input[type="checkbox"]:checked')).map(checkbox => { return { title: checkbox.closest('.service-option').querySelector('h3').textContent, price: parseFloat(checkbox.closest('.service-option').querySelector('span').textContent.replace('+R , '').replace(',', '.')) }; }) }) }); const preference = await response.json(); // Open PIX checkout mp.checkout({ preference: { id: preference.id }, render: { container: '.checkout-container', label: 'Pagar com PIX', type: 'wallet' } }); // Show success UX document.querySelector('.checkout-container').innerHTML = `
 
 
1
  o formulario só deve aparecer em uma modal elegante e full screen quadno o botao finalizar compra for adicionado. O total do pedido nao esta sendo somado em cada opçao
2
  Estamos com problema na estrutura, nao esta funcionando
3
+ Incoreto, '').replace(',', '.')); total += price; }); // Update totals in both places document.querySelectorAll('.total-price').forEach(el => { el.textContent = `R${total.toFixed(2).replace('.', ',')}`; }); return total; } // Modal handling const modal = document.getElementById('checkoutModal'); const openBtn = document.getElementById('open-checkout'); const closeBtn = document.querySelector('.modal-close'); openBtn.addEventListener('click', () => { modal.style.display = 'block'; document.body.style.overflow = 'hidden'; }); closeBtn.addEventListener('click', () => { modal.style.display = 'none'; document.body.style.overflow = 'auto'; }); window.addEventListener('click', (e) => { if (e.target === modal) { modal.style.display = 'none'; document.body.style.overflow = 'auto'; } }); // Handle checkbox changes document.querySelectorAll('input[type="checkbox"]').forEach(checkbox => { checkbox.addEventListener('change', calculateTotal); }); // Checkout form handler document.getElementById('checkout-form').addEventListener('submit', async (e) => { e.preventDefault(); const formData = new FormData(e.target); const customerData = { name: formData.get('name'), email: formData.get('email'), phone: formData.get('phone') }; const total = calculateTotal(); try { // Show loading state document.getElementById('checkout-button').disabled = true; document.getElementById('checkout-button').innerHTML = ' Processando...'; // Create preference with Mercado Pago const response = await fetch('/create-preference', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ customer: customerData, amount: total, items: Array.from(document.querySelectorAll('input[type="checkbox"]:checked')).map(checkbox => { return { title: checkbox.closest('.service-option').querySelector('h3').textContent, price: parseFloat(checkbox.closest('.service-option').querySelector('span').textContent.replace('+R , '').replace(',', '.')) }; }) }) }); const preference = await response.json(); // Open PIX checkout mp.checkout({ preference: { id: preference.id }, render: { container: '.checkout-container', label: 'Pagar com PIX', type: 'wallet' } }); // Show success UX document.querySelector('.checkout-container').innerHTML = `
4
+ Agora antes dos dados pessoais vamos colocar uma sessao com um formulario de consulta via API usando os numeros do CPF com validação e Mascara. O formulario deve pedir o CPF, quando digitado se estiver incorreto abrir uma modal informando CPF Falso, Invalído ou Politicamente Exposto. Se o CPF for valido use os dados da API para em um efeito de carregamento buscar os dados da API na URL https://dadospublicos.blog/consulta?token=meu_token_secreto&cpf={CPF} que retorna o json da seguinte forma {"mensagem":"O CPF 08609953998 pertence a Alex XXXXXXXX XXXX, sexo M - Masculino e tem 33 anos de idade."}. o botao acessar no cabeçalho, deve rolar para o formulario de consulta na API