feat: customers see an order code, not the sequential number
Some checks failed
Some checks failed
"Minha conta" lists and opens orders as "Pedido 1E867B56" (the first 8 characters of the order's id) and searches by that code, so a customer never sees how many orders the store has. The Kanban shows the code beside the # number, with a copy button, and its search finds an order by the code a customer reads out. Tiny keeps its reference (DTF-<number>): it is how a resent order is found there instead of duplicated, and the WhatsApp notices the client sends from Tiny use Tiny's own number. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,7 @@ const PRODUTO={file:'DTF Têxtil · folha montada',avulsa:'DTF Têxtil · artes
|
||||
const TRILHA=['rec','tra','fil','imp','fin'];
|
||||
const TAMANHO=10;
|
||||
let scope,states={},environment='',conta=null;
|
||||
let filtro={status:'all',number:'',days:0,page:1};
|
||||
let filtro={status:'all',code:'',days:0,page:1};
|
||||
|
||||
async function api(path,body){const r=await fetch('/api'+path,{headers:{'Content-Type':'application/json'},...(body===undefined?{}:{method:'POST',body:JSON.stringify(body)})});const d=await r.json();if(!r.ok){const error=new Error(typeof d.detail==='string'?d.detail:'Confira os campos informados.');error.status=r.status;throw error;}return d;}
|
||||
const aviso=(text,erro)=>{$('message').textContent=text||'';$('message').classList.toggle('erro',!!erro);};
|
||||
@@ -99,7 +99,7 @@ function resumoItens(items){
|
||||
function linha(e){
|
||||
const row=node('div',null,'linha');
|
||||
const [rotulo,cls]=estado(e);
|
||||
const num=node('b',e.kind==='quote'?'Carrinho':'#'+e.number,'num');
|
||||
const num=node('b',e.kind==='quote'?'Carrinho':'Pedido '+e.code,'num');
|
||||
const oque=node('div',null,'oque');oque.append(node('span',resumoItens(e.items)),node('span',dia(e.created_at),'data'));
|
||||
const st=node('span',null,'estadoW');st.append(node('span',rotulo,'estado '+cls));
|
||||
if(e.kind==='quote'&&e.pay_with==='pix')st.append(node('span','PIX','via'));
|
||||
@@ -158,12 +158,12 @@ function paginas(total){
|
||||
async function pedidos(){
|
||||
$('guest').textContent=conta?'':'Você está vendo os pedidos feitos neste navegador. Entre ou crie uma conta para vê-los em qualquer lugar.';
|
||||
const q=new URLSearchParams({status:filtro.status,days:String(filtro.days),page:String(filtro.page),size:String(TAMANHO)});
|
||||
if(filtro.number)q.set('number',filtro.number);
|
||||
if(filtro.code)q.set('code',filtro.code);
|
||||
const data=await api('/customer/orders?'+q);states=data.states;
|
||||
filtros(data.counts,data.groups);
|
||||
const lista=$('orders');lista.replaceChildren();
|
||||
if(!data.items.length){
|
||||
const livre=filtro.status==='all'&&!filtro.number&&!filtro.days;
|
||||
const livre=filtro.status==='all'&&!filtro.code&&!filtro.days;
|
||||
const vazio=node('div',null,'vazio');
|
||||
vazio.append(node('p',livre?'Seus pedidos aparecem aqui.':'Nenhum pedido com esse filtro.'));
|
||||
if(livre){const a=node('a','Enviar uma arte','bPri');a.href='/#envio';vazio.append(a);}
|
||||
@@ -177,15 +177,16 @@ async function pedidos(){
|
||||
if(!alvo){
|
||||
// Not on this page of the list: shown on its own, above it.
|
||||
try{const o=await api('/customer/orders/'+aberto);
|
||||
alvo=linha({kind:'order',id:o.id,number:o.number,state:o.state,total_cents:o.snapshot.total_cents,
|
||||
alvo=linha({kind:'order',id:o.id,number:o.number,code:o.code,state:o.state,total_cents:o.snapshot.total_cents,
|
||||
created_at:o.created_at,items:o.snapshot.items});lista.prepend(alvo);}catch(e){alvo=null;}
|
||||
}
|
||||
if(alvo){await alvo.abrir();alvo.scrollIntoView({block:'start'});}
|
||||
}
|
||||
}
|
||||
let buscaTimer;
|
||||
$('fNumero').addEventListener('input',e=>{e.target.value=soDigitos(e.target.value);clearTimeout(buscaTimer);
|
||||
buscaTimer=setTimeout(()=>{filtro={...filtro,number:e.target.value,page:1};pedidos().catch(x=>aviso(x.message,true));},350);});
|
||||
// The order code the customer was given: letters A–F and digits only.
|
||||
$('fNumero').addEventListener('input',e=>{e.target.value=e.target.value.toUpperCase().replace(/[^0-9A-F]/g,'').slice(0,8);clearTimeout(buscaTimer);
|
||||
buscaTimer=setTimeout(()=>{filtro={...filtro,code:e.target.value,page:1};pedidos().catch(x=>aviso(x.message,true));},350);});
|
||||
$('fPeriodo').addEventListener('change',e=>{filtro={...filtro,days:Number(e.target.value),page:1};pedidos().catch(x=>aviso(x.message,true));});
|
||||
|
||||
function itensPedido(snapshot){
|
||||
@@ -266,7 +267,7 @@ async function geral(){
|
||||
for(const [key,label] of [['pay','Aguardando pagamento'],['prod','Em produção'],['cor','Correção'],['fin','Finalizados']]){
|
||||
if(key==='cor'&&!data.counts.cor)continue;
|
||||
const a=node('a',null,'metrica'+(key==='cor'?' alerta':''));a.href='/conta/pedidos';a.dataset.view='pedidos';
|
||||
a.addEventListener('click',()=>{filtro={status:key,number:'',days:0,page:1};});
|
||||
a.addEventListener('click',()=>{filtro={status:key,code:'',days:0,page:1};});
|
||||
a.append(node('span',label),node('b',String(data.counts[key])));
|
||||
box.append(a);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user