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:
@@ -1013,8 +1013,8 @@ h2 em{font-style:normal;color:var(--laranja)}
|
||||
<div class="cxE">
|
||||
<h4>Seus dados</h4>
|
||||
<div class="campos">
|
||||
<div class="cp"><label>CNPJ <span class="obr" aria-hidden="true">*</span></label>
|
||||
<input id="fCnpj" aria-required="true" autocomplete="off" inputmode="numeric" maxlength="18" placeholder="00.000.000/0000-00">
|
||||
<div class="cp"><label for="fCnpj">CPF ou CNPJ <span class="obr" aria-hidden="true">*</span></label>
|
||||
<input id="fCnpj" aria-required="true" autocomplete="off" inputmode="numeric" maxlength="18" placeholder="CPF ou CNPJ">
|
||||
<span class="err" id="eCnpj"></span></div>
|
||||
<div class="cp"><label>WhatsApp <span class="obr" aria-hidden="true">*</span></label>
|
||||
<input id="fZap" aria-required="true" autocomplete="off" inputmode="numeric" maxlength="15" placeholder="(16) 99999-9999">
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<div class="searchbox">
|
||||
<label class="search">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="11" cy="11" r="7"></circle><path d="M20 20l-3.5-3.5"></path></svg>
|
||||
<input id="search" type="search" placeholder="Buscar em pedidos e cotações: cliente, CNPJ, nº" aria-label="Buscar em pedidos e cotações" autocomplete="off" role="combobox" aria-expanded="false" aria-controls="search-results">
|
||||
<input id="search" type="search" placeholder="Buscar em pedidos e cotações: cliente, CPF/CNPJ, nº" aria-label="Buscar em pedidos e cotações" autocomplete="off" role="combobox" aria-expanded="false" aria-controls="search-results">
|
||||
<kbd>/</kbd>
|
||||
</label>
|
||||
<div id="search-results" class="results" role="listbox" aria-label="Resultados da busca" hidden></div>
|
||||
@@ -63,7 +63,7 @@
|
||||
<div class="chips" id="quote-filters"></div>
|
||||
<label class="qsearch">
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="11" cy="11" r="7"></circle><path d="M20 20l-3.5-3.5"></path></svg>
|
||||
<input id="quote-q" type="search" placeholder="Filtrar por e-mail, CNPJ ou WhatsApp" aria-label="Filtrar cotações por cliente" autocomplete="off">
|
||||
<input id="quote-q" type="search" placeholder="Filtrar por e-mail, CPF/CNPJ ou WhatsApp" aria-label="Filtrar cotações por cliente" autocomplete="off">
|
||||
</label>
|
||||
<div class="chips small" id="quote-chips"></div>
|
||||
<div id="quote-list"></div>
|
||||
|
||||
@@ -122,7 +122,9 @@ function place(dest,prefix=''){
|
||||
}
|
||||
const cm=v=>Number(v).toLocaleString('pt-BR',{maximumFractionDigits:1});
|
||||
const plural=(n,one,many)=>n+' '+(n===1?one:many);
|
||||
function cnpj(value){const d=String(value||'').replace(/\D/g,'');return d.length===14?d.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/,'$1.$2.$3/$4-$5'):String(value||'');}
|
||||
// The customer's CPF or CNPJ, formatted, and which of the two it is.
|
||||
function cnpj(value){const d=String(value||'').replace(/\D/g,'');return d.length===14?d.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/,'$1.$2.$3/$4-$5'):d.length===11?d.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})$/,'$1.$2.$3-$4'):String(value||'');}
|
||||
const docKind=value=>String(value||'').replace(/\D/g,'').length===11?'CPF':'CNPJ';
|
||||
function copyButton(text,label){
|
||||
const b=node('button',undefined,'copy');b.type='button';b.title=label;b.setAttribute('aria-label',label);b.append(icon(ICON_COPY));
|
||||
b.onclick=async e=>{e.stopPropagation();try{await navigator.clipboard.writeText(text);say('Copiado.');}catch(_){say('Não foi possível copiar.',true);}};
|
||||
@@ -672,7 +674,7 @@ function renderPanel(order){
|
||||
const s=order.snapshot, dest=s.destination;
|
||||
const facts=node('section',undefined,'facts');
|
||||
const who=node('div',undefined,'fcard');
|
||||
const doc=node('span',undefined,'line');doc.append('CNPJ '+cnpj(s.customer.cnpj),copyButton(cnpj(s.customer.cnpj),'Copiar CNPJ'));
|
||||
const doc=node('span',undefined,'line');doc.append(docKind(s.customer.cnpj)+' '+cnpj(s.customer.cnpj),copyButton(cnpj(s.customer.cnpj),'Copiar '+docKind(s.customer.cnpj)));
|
||||
who.append(node('p','Cliente','eyebrow'),buyerBlock(s),doc);
|
||||
const zap=whatsappLink(s.customer.zap);
|
||||
if(zap){const a=node('a','Abrir conversa','zapbtn');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.title=s.customer.zap;a.prepend(icon(ICON_CHAT));who.append(a);}
|
||||
@@ -1272,7 +1274,7 @@ function review(quote){
|
||||
const name=node('div',undefined,'qname');name.append(buyerBlock(quote.draft),badge(...status));
|
||||
const pay=paymentBadge(quote.payment);if(pay)name.append(pay);
|
||||
const sub=node('div',undefined,'qsub');const c=quote.draft.customer;
|
||||
const doc=node('span');doc.append('CNPJ '+cnpj(c.cnpj),copyButton(cnpj(c.cnpj),'Copiar CNPJ'));sub.append(doc);
|
||||
const doc=node('span');doc.append(docKind(c.cnpj)+' '+cnpj(c.cnpj),copyButton(cnpj(c.cnpj),'Copiar '+docKind(c.cnpj)));sub.append(doc);
|
||||
const zap=whatsappLink(c.zap);
|
||||
if(zap){const a=node('a',c.zap,'zapbtn');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.prepend(icon(ICON_CHAT));sub.append(a);}
|
||||
sub.append(place(quote.draft.destination,'Entrega em '),node('span','#'+quote.id.slice(0,8)+' · '+ago(quote.created_at),'faint'));
|
||||
@@ -1662,7 +1664,7 @@ async function runSearch(text){
|
||||
for(const row of rows){const hit=make(row);hit.el.id='hit-'+searchHits.length;searchHits.push(hit);parts.push(hit.el);}
|
||||
}
|
||||
if(!searchHits.length)parts.push(node('p','Nada encontrado para “'+text+'”.','rempty'));
|
||||
parts.push(node('div','↑ ↓ para escolher · Enter abre · Esc fecha · busca por e-mail, CNPJ, WhatsApp ou nº do pedido','rhelp'));
|
||||
parts.push(node('div','↑ ↓ para escolher · Enter abre · Esc fecha · busca por e-mail, CPF/CNPJ, WhatsApp ou nº do pedido','rhelp'));
|
||||
box.replaceChildren(...parts);box.hidden=false;$('search').setAttribute('aria-expanded','true');
|
||||
}
|
||||
function hitRow(items,title,sub,meta,badge,color,open){
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
<h2>Criar conta</h2>
|
||||
<p class="nota2">Os pedidos feitos neste navegador passam para a sua conta.</p>
|
||||
<div class="duas">
|
||||
<div><label for="cnpj">CNPJ</label><input id="cnpj" inputmode="numeric" autocomplete="off" required></div>
|
||||
<div><label for="cnpj">CPF ou CNPJ</label><input id="cnpj" inputmode="numeric" autocomplete="off" maxlength="18" required></div>
|
||||
<div><label for="phone">WhatsApp</label><input id="phone" inputmode="numeric" autocomplete="tel" required></div>
|
||||
</div>
|
||||
<label for="register-email">E-mail</label>
|
||||
@@ -141,9 +141,9 @@
|
||||
<section class="vista" id="vDados" hidden aria-labelledby="tDados">
|
||||
<h1 id="tDados">Dados da conta</h1>
|
||||
<form class="bloco" id="fPerfil">
|
||||
<h2>Empresa e entrega</h2>
|
||||
<h2>Dados e entrega</h2>
|
||||
<div class="duas">
|
||||
<div><label for="dCnpj">CNPJ</label><input id="dCnpj" readonly aria-readonly="true"></div>
|
||||
<div><label for="dCnpj" id="dCnpjRotulo">CPF ou CNPJ</label><input id="dCnpj" readonly aria-readonly="true"></div>
|
||||
<div><label for="dZap">WhatsApp</label><input id="dZap" inputmode="numeric" autocomplete="tel" required></div>
|
||||
</div>
|
||||
<div class="duas">
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -97,20 +97,32 @@ let pedido=[]; // itens já fechados · o pagamento
|
||||
let entrega={tipo:'retira', cep:'', valor:0, cotado:true, end:{}, servico:'', opcoes:[]};
|
||||
let cliente={cnpj:'', zap:'', mail:''};
|
||||
|
||||
// CNPJ com os dois dígitos verificadores · máscara sem conta não vale nada
|
||||
function cnpjOk(v){
|
||||
// CPF (11 dígitos) ou CNPJ (14), com os dois dígitos verificadores · máscara
|
||||
// sem conta não vale nada. A chave cliente.cnpj guarda qualquer um dos dois.
|
||||
function docOk(v){
|
||||
const d=(v||'').replace(/\D/g,'');
|
||||
if(d.length!==14 || /^(\d)\1{13}$/.test(d)) return false;
|
||||
if((d.length!==11 && d.length!==14) || /^(\d)\1+$/.test(d)) return false;
|
||||
const calc=(base,pesos)=>{
|
||||
const soma=base.split('').reduce((t,n,i)=>t+ +n*pesos[i],0);
|
||||
const r=soma%11; return r<2? 0 : 11-r;
|
||||
};
|
||||
if(d.length===11){
|
||||
const p1=[10,9,8,7,6,5,4,3,2], p2=[11,...p1];
|
||||
return calc(d.slice(0,9),p1)===+d[9] && calc(d.slice(0,10),p2)===+d[10];
|
||||
}
|
||||
const p1=[5,4,3,2,9,8,7,6,5,4,3,2], p2=[6,...p1];
|
||||
return calc(d.slice(0,12),p1)===+d[12] && calc(d.slice(0,13),p2)===+d[13];
|
||||
}
|
||||
// 000.000.000-00 até 11 dígitos; passando disso, 00.000.000/0000-00.
|
||||
function fmtDoc(v){
|
||||
const d=(v||'').replace(/\D/g,'').slice(0,14);
|
||||
if(d.length<=11) return d.replace(/^(\d{3})(\d)/,'$1.$2').replace(/^(\d{3})\.(\d{3})(\d)/,'$1.$2.$3')
|
||||
.replace(/^(\d{3})\.(\d{3})\.(\d{3})(\d)/,'$1.$2.$3-$4');
|
||||
return d.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{0,2})/,'$1.$2.$3/$4-$5');
|
||||
}
|
||||
const zapOk=v=>{ const d=(v||'').replace(/\D/g,''); return d.length===10||d.length===11; };
|
||||
const mailOk=v=>/^[^\s@]+@[^\s@]+\.[a-z]{2,}$/i.test((v||'').trim());
|
||||
const clienteOk=()=>cnpjOk(cliente.cnpj)&&zapOk(cliente.zap)&&mailOk(cliente.mail);
|
||||
const clienteOk=()=>docOk(cliente.cnpj)&&zapOk(cliente.zap)&&mailOk(cliente.mail);
|
||||
// Frete cotado pelo CEP não entrega nada sozinho: a transportadora e o Tiny
|
||||
// precisam do endereço completo antes do pagamento.
|
||||
const UFS='AC AL AP AM BA CE DF ES GO MA MT MS MG PA PB PR PE PI RJ RN RS RO RR SC SP SE TO'.split(' ');
|
||||
|
||||
@@ -120,11 +120,7 @@ function liga(id,fmt,val,chave,erro,msg){
|
||||
er.textContent = ok? '' : msg;
|
||||
});
|
||||
}
|
||||
liga('fCnpj', v=>{
|
||||
const d=v.replace(/\D/g,'').slice(0,14);
|
||||
return d.replace(/^(\d{2})(\d)/,'$1.$2').replace(/^(\d{2})\.(\d{3})(\d)/,'$1.$2.$3')
|
||||
.replace(/\.(\d{3})(\d)/,'.$1/$2').replace(/(\d{4})(\d)/,'$1-$2');
|
||||
}, cnpjOk, 'cnpj', 'eCnpj', 'CNPJ inválido · confira os números');
|
||||
liga('fCnpj', fmtDoc, docOk, 'cnpj', 'eCnpj', 'CPF ou CNPJ inválido · confira os números');
|
||||
liga('fZap', v=>{
|
||||
const d=v.replace(/\D/g,'').slice(0,11);
|
||||
return d.length>6 ? '('+d.slice(0,2)+') '+d.slice(2,d.length-4)+'-'+d.slice(-4)
|
||||
|
||||
Reference in New Issue
Block a user