feat: the cart and the account ask for the customer's name
All checks were successful
Build and deploy / Validate source (push) Successful in 10s
Build and deploy / Integration suite on a real stack (push) Successful in 4m49s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m15s
All checks were successful
Build and deploy / Validate source (push) Successful in 10s
Build and deploy / Integration suite on a real stack (push) Successful in 4m49s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m15s
The Site asked only for CPF/CNPJ, WhatsApp and e-mail, so a person's Tiny contact was named after the recipient or the e-mail, and the WhatsApp notices the client's n8n sends from Tiny greeted "Olá, fulano@gmail.com". The cart's "Seus dados" and the signup now ask for a name, the account page can change it, and it names a CPF customer's Tiny contact (a CNPJ keeps the registry's razão social), the Kanban card and the team's alerts. Orders placed before have none, as the server still accepts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
(() => {
|
||||
// A browser may put back what was typed before the reload without telling
|
||||
// the page, which then shows values it does not know and cannot pay with.
|
||||
const CAMPOS=['fCnpj','fZap','fMail','cepIn','eNome','eRua','eNum','eComp','eBairro','eCidade','eUf'];
|
||||
const CAMPOS=['fNome','fCnpj','fZap','fMail','cepIn','eNome','eRua','eNum','eComp','eBairro','eCidade','eUf'];
|
||||
for(const id of CAMPOS)if($(id))$(id).value='';
|
||||
let database,scope,timer,restoring=true;
|
||||
let signedOut=false;
|
||||
@@ -45,9 +45,9 @@
|
||||
const account=await window.dtfApi('/account/me');
|
||||
const c=account.customer;
|
||||
if(c && !cliente.mail){
|
||||
cliente={cnpj:c.cnpj,zap:c.zap,mail:c.mail};
|
||||
cliente={name:c.name||'',cnpj:c.cnpj,zap:c.zap,mail:c.mail};
|
||||
// The fields' own input handlers format them, as if typed.
|
||||
for(const [id,key] of [['fCnpj','cnpj'],['fZap','zap'],['fMail','mail']]){$(id).value=cliente[key];$(id).dispatchEvent(new Event('input'));}
|
||||
for(const [id,key] of [['fNome','name'],['fCnpj','cnpj'],['fZap','zap'],['fMail','mail']]){$(id).value=cliente[key];$(id).dispatchEvent(new Event('input'));}
|
||||
const a=c.address;
|
||||
if(a && !entrega.cep){
|
||||
entrega.cep=a.postal_code;
|
||||
|
||||
@@ -1013,6 +1013,9 @@ h2 em{font-style:normal;color:var(--laranja)}
|
||||
<div class="cxE">
|
||||
<h4>Seus dados</h4>
|
||||
<div class="campos">
|
||||
<div class="cp larga"><label for="fNome">Nome <span class="obr" aria-hidden="true">*</span></label>
|
||||
<input id="fNome" aria-required="true" autocomplete="name" maxlength="80" placeholder="Como devemos te chamar">
|
||||
<span class="err" id="eNomeCli"></span></div>
|
||||
<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>
|
||||
|
||||
@@ -57,7 +57,9 @@
|
||||
</form>
|
||||
<form class="bloco" id="register">
|
||||
<h2>Criar conta</h2>
|
||||
<p class="nota2">Os pedidos feitos neste navegador passam para a sua conta.</p>
|
||||
<p class="nota2">Seus pedidos feitos com o mesmo CPF/CNPJ e e-mail aparecem na conta.</p>
|
||||
<label for="register-name">Nome</label>
|
||||
<input id="register-name" autocomplete="name" maxlength="80" required>
|
||||
<div class="duas">
|
||||
<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>
|
||||
@@ -142,6 +144,8 @@
|
||||
<h1 id="tDados">Dados da conta</h1>
|
||||
<form class="bloco" id="fPerfil">
|
||||
<h2>Dados e entrega</h2>
|
||||
<label for="dNomeCli">Nome</label>
|
||||
<input id="dNomeCli" autocomplete="name" maxlength="80" required>
|
||||
<div class="duas">
|
||||
<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>
|
||||
|
||||
@@ -266,7 +266,7 @@ async function details(id,container,criado){
|
||||
// ---- Overview ------------------------------------------------------------
|
||||
|
||||
async function geral(){
|
||||
$('account').textContent=tipoDoc(conta.cnpj)+' '+fmtCnpj(conta.cnpj)+' · '+conta.mail;
|
||||
$('account').textContent=(conta.name?conta.name+' · ':'')+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']]){
|
||||
@@ -285,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(){
|
||||
$('dCnpjRotulo').textContent=tipoDoc(conta.cnpj);$('dCnpj').value=fmtCnpj(conta.cnpj);$('dZap').value=fmtZap(conta.zap);$('dMail').value=conta.mail;
|
||||
$('dNomeCli').value=conta.name||'';$('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]||'';
|
||||
@@ -308,9 +308,9 @@ $('fPerfil').onsubmit=async event=>{
|
||||
const algum=cep||Object.values(campos).some(Boolean);
|
||||
const address=algum?{...campos,state:campos.state.toUpperCase(),postal_code:cep}:null;
|
||||
try{
|
||||
const r=await api('/account/profile',{zap:$('dZap').value,address});
|
||||
const r=await api('/account/profile',{name:$('dNomeCli').value,zap:$('dZap').value,address});
|
||||
conta=r.customer;aviso('Dados salvos.');
|
||||
}catch(e){aviso(e.status===422?(algum?'Confira o WhatsApp e o endereço: todos os campos, menos o complemento, são necessários.':'Confira o WhatsApp.'):e.message,true);}
|
||||
}catch(e){aviso(e.status===422?(algum?'Confira o nome, o WhatsApp e o endereço: todos os campos, menos o complemento, são necessários.':'Confira o nome e o WhatsApp.'):e.message,true);}
|
||||
};
|
||||
// A new e-mail is confirmed with the code sent to it before the account changes.
|
||||
let troca=null, trocaTimer=null;
|
||||
@@ -387,8 +387,8 @@ 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 CPF ou CNPJ, o WhatsApp e o e-mail. A senha precisa ter 12 caracteres ou mais.':e.message,true);}
|
||||
try{await authenticate('/account/register',{customer:{name:$('register-name').value,cnpj:$('cnpj').value,zap:$('phone').value,mail:$('register-email').value},password:$('register-password').value});}
|
||||
catch(e){aviso(e.status===422?'Confira o nome, 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
|
||||
|
||||
@@ -95,7 +95,7 @@ let pedido=[]; // itens já fechados · o pagamento
|
||||
// grava forma_envio X, transportador DropStar e frete por conta do remetente — igual
|
||||
// ao que a expedição já recebe hoje, sem criar processo novo.
|
||||
let entrega={tipo:'retira', cep:'', valor:0, cotado:true, end:{}, servico:'', opcoes:[]};
|
||||
let cliente={cnpj:'', zap:'', mail:''};
|
||||
let cliente={name:'', cnpj:'', zap:'', mail:''};
|
||||
|
||||
// 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.
|
||||
@@ -122,7 +122,9 @@ function fmtDoc(v){
|
||||
}
|
||||
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=()=>docOk(cliente.cnpj)&&zapOk(cliente.zap)&&mailOk(cliente.mail);
|
||||
// Nome: duas letras bastam (o cliente pode ser só "Ana").
|
||||
const nomeOk=v=>((v||'').match(/\p{L}/gu)||[]).length>=2;
|
||||
const clienteOk=()=>nomeOk(cliente.name)&&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,6 +120,7 @@ function liga(id,fmt,val,chave,erro,msg){
|
||||
er.textContent = ok? '' : msg;
|
||||
});
|
||||
}
|
||||
liga('fNome', v=>v.replace(/\s+/g,' ').replace(/^ /,''), nomeOk, 'name', 'eNomeCli', 'Informe seu nome');
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user