diff --git a/web/kanban.js b/web/kanban.js index 9d9010b..ea2af95 100644 --- a/web/kanban.js +++ b/web/kanban.js @@ -40,6 +40,23 @@ function ago(value){ const hours=Math.round(minutes/60); return hours<48?'há '+hours+' h':'há '+Math.round(hours/24)+' dias'; } +// The customer's WhatsApp opens the conversation, for messages the system does +// not send (a correction, a question about the artwork). +function whatsappLink(zap){ + const digits=String(zap||'').replace(/\D/g,''); + if(digits.length<10)return null; + return 'https://wa.me/'+(digits.length<=11?'55':'')+digits; +} +function contato(customer){ + const line=node('span','CNPJ '+customer.cnpj+' · '); + const href=whatsappLink(customer.zap); + if(!href){line.append(customer.zap||'');return line;} + const d=String(customer.zap).replace(/\D/g,'').replace(/^55(?=\d{10,11}$)/,''); + const shown=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):customer.zap; + const a=node('a',shown,'zap');a.href=href;a.target='_blank';a.rel='noopener noreferrer'; + a.title='Abrir conversa no WhatsApp'; + line.append(a);return line; +} function node(tag,text,className){const e=document.createElement(tag);if(text!==undefined&&text!==null)e.textContent=text;if(className)e.className=className;return e;} function button(text,fn,className='btn'){ const b=node('button',text,className);b.type='button'; @@ -244,7 +261,7 @@ function renderPanel(order){ const body=node('div',undefined,'panel-body'); const s=order.snapshot, dest=s.destination; const facts=node('section',undefined,'facts'); - const who=node('div');who.append(node('p','Cliente','eyebrow'),node('b',s.customer.mail),node('span','CNPJ '+s.customer.cnpj+' · '+s.customer.zap)); + const who=node('div');who.append(node('p','Cliente','eyebrow'),node('b',s.customer.mail),contato(s.customer)); const where=node('div');where.append(node('p','Entrega','eyebrow'),node('b',dest?dest.recipient:'Retirada em Franca'), node('span',dest?dest.street+', '+dest.number+(dest.complement?' '+dest.complement:'')+' · '+dest.district+' · '+dest.city+'/'+dest.state+' · CEP '+dest.postal_code:'Cliente retira na fábrica')); facts.append(who,where);