feat: customers buy with a CPF or a CNPJ
All checks were successful
Build and deploy / Validate source (push) Successful in 1m38s
Build and deploy / Integration suite on a real stack (push) Successful in 4m57s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Successful in 2m1s
All checks were successful
Build and deploy / Validate source (push) Successful in 1m38s
Build and deploy / Integration suite on a real stack (push) Successful in 4m57s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Successful in 2m1s
The cart and the account signup take either document, each with its own mask and check digits. Tiny gets a person (F) for a CPF, Mercado Pago the matching identification type, and only CNPJs go to the company registry. The Kanban, the account page and the alerts show which one it is. Also pins the Correios test's clock: its fake token expired today, so the suite failed from Oct 16 on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,9 @@ const quando=d=>new Date(d).toLocaleString('pt-BR',{day:'2-digit',month:'2-digit
|
||||
const dia=d=>new Date(d).toLocaleDateString('pt-BR',{day:'2-digit',month:'2-digit',year:'2-digit'});
|
||||
const metros=m=>Number(m).toLocaleString('pt-BR',{minimumFractionDigits:2,maximumFractionDigits:2})+' m';
|
||||
const soDigitos=v=>String(v||'').replace(/\D/g,'');
|
||||
const fmtCnpj=v=>soDigitos(v).replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/,'$1.$2.$3/$4-$5');
|
||||
// The account's CPF or CNPJ, formatted, and which of the two it is.
|
||||
const fmtCnpj=v=>{const d=soDigitos(v);return d.length===11?d.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})$/,'$1.$2.$3-$4'):d.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/,'$1.$2.$3/$4-$5');};
|
||||
const tipoDoc=v=>soDigitos(v).length===11?'CPF':'CNPJ';
|
||||
const fmtZap=v=>{const d=soDigitos(v);return d.length===11?'('+d.slice(0,2)+') '+d.slice(2,7)+'-'+d.slice(7):d.length===10?'('+d.slice(0,2)+') '+d.slice(2,6)+'-'+d.slice(6):v;};
|
||||
const fmtCep=v=>{const d=soDigitos(v).slice(0,8);return d.length>5?d.slice(0,5)+'-'+d.slice(5):d;};
|
||||
// Lucide shapes (ISC licence), the same as on the Site.
|
||||
@@ -264,7 +266,7 @@ async function details(id,container,criado){
|
||||
// ---- Overview ------------------------------------------------------------
|
||||
|
||||
async function geral(){
|
||||
$('account').textContent='CNPJ '+fmtCnpj(conta.cnpj)+' · '+conta.mail;
|
||||
$('account').textContent=tipoDoc(conta.cnpj)+' '+fmtCnpj(conta.cnpj)+' · '+conta.mail;
|
||||
const data=await api('/customer/orders?page=1&size=1');states=data.states;
|
||||
const box=$('metricas');box.replaceChildren();
|
||||
for(const [key,label] of [['pay','Aguardando pagamento'],['prod','Em produção'],['cor','Correção'],['fin','Finalizados']]){
|
||||
@@ -283,7 +285,7 @@ async function geral(){
|
||||
|
||||
const CAMPOS_END=[['dNome','recipient'],['dRua','street'],['dNum','number'],['dComp','complement'],['dBairro','district'],['dCidade','city'],['dUf','state']];
|
||||
function dados(){
|
||||
$('dCnpj').value=fmtCnpj(conta.cnpj);$('dZap').value=fmtZap(conta.zap);$('dMail').value=conta.mail;
|
||||
$('dCnpjRotulo').textContent=tipoDoc(conta.cnpj);$('dCnpj').value=fmtCnpj(conta.cnpj);$('dZap').value=fmtZap(conta.zap);$('dMail').value=conta.mail;
|
||||
const end=conta.address||{};
|
||||
$('dCep').value=fmtCep(end.postal_code||'');
|
||||
for(const [id,k] of CAMPOS_END)$(id).value=end[k]||'';
|
||||
@@ -386,7 +388,7 @@ async function authenticate(path,body,destino){
|
||||
$('login').onsubmit=async event=>{event.preventDefault();try{await authenticate('/account/login',{email:$('email').value,password:$('password').value});}catch(e){aviso(e.message,true);}};
|
||||
$('register').onsubmit=async event=>{event.preventDefault();$('criarConta').disabled=true;
|
||||
try{await authenticate('/account/register',{customer:{cnpj:$('cnpj').value,zap:$('phone').value,mail:$('register-email').value},password:$('register-password').value});}
|
||||
catch(e){aviso(e.status===422?'Confira o CNPJ, o WhatsApp e o e-mail. A senha precisa ter 12 caracteres ou mais.':e.message,true);}
|
||||
catch(e){aviso(e.status===422?'Confira o CPF ou CNPJ, o WhatsApp e o e-mail. A senha precisa ter 12 caracteres ou mais.':e.message,true);}
|
||||
finally{$('criarConta').disabled=false;}};
|
||||
|
||||
// Signup code: the account is created only once the code e-mailed to the
|
||||
|
||||
Reference in New Issue
Block a user