feat: Minhas folhas on the server and in Minha conta: saved sheets per account with their uploads, 30 days, 50 per account; order again, edit, delete (Rodada 5, B9)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-30 16:09:52 -03:00
parent 21858b5764
commit 5671235681
9 changed files with 453 additions and 8 deletions

View File

@@ -141,6 +141,21 @@ button:disabled{opacity:.6;cursor:default}
.correcaoForm textarea{height:auto;padding:10px 13px;resize:vertical}
.correcaoForm .bPri{margin-top:14px;align-self:flex-start}
/* Saved sheets (Minhas folhas). */
.folhas{display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));gap:14px;padding:14px}
.folhaCard{display:flex;flex-direction:column;border:1px solid var(--linha);border-radius:var(--raio2);background:#fff;overflow:hidden}
.folhaPic{aspect-ratio:4/3;background:var(--cinza);border-bottom:1px solid var(--linha)}
.folhaPic img{display:block;width:100%;height:100%;object-fit:cover}
.folhaPic .semFoto{width:100%;height:100%;background:repeating-linear-gradient(135deg,var(--cinza),var(--cinza) 10px,#EDEDED 10px,#EDEDED 20px)}
.folhaBody{display:flex;flex-direction:column;gap:4px;padding:14px 16px 6px}
.folhaNome{font-family:"Inter",sans-serif;font-size:16px;font-weight:800;overflow-wrap:anywhere}
.folhaProduto,.folhaMetros{margin:0;font-size:14px;color:var(--fraco)}
.folhaValidade{margin:6px 0 0;font-size:14px;color:var(--texto2)}
.folhaValidade.vencida{color:#B42318}
.folhaAcoes{display:flex;flex-wrap:wrap;gap:8px;padding:12px 16px 16px;margin-top:auto}
.folhaAcoes .bPri,.folhaAcoes .bSec{height:38px;padding:0 14px;font-size:14.5px}
.folhaAcoes .folhaGrande{max-width:100%;min-height:38px;height:auto;padding:7px 12px;text-align:center;line-height:1.25;white-space:normal}
@media (max-width:820px){
.area{grid-template-columns:1fr;gap:16px}
.lateral{position:static;flex-direction:row;flex-wrap:wrap}

View File

@@ -107,6 +107,7 @@
<nav class="lateral" aria-label="Minha conta">
<a href="/conta" data-view="geral" data-conta>Visão geral</a>
<a href="/conta/pedidos" data-view="pedidos">Pedidos</a>
<a href="/conta/folhas" data-view="folhas" data-conta>Minhas folhas</a>
<a href="/conta/dados" data-view="dados" data-conta>Dados da conta</a>
<a href="/conta/entrar" data-view="entrar" id="navEntrar">Entrar</a>
<button type="button" id="logout" hidden>Sair</button>
@@ -140,6 +141,11 @@
<div class="paginas" id="paginas"></div>
</section>
<section class="vista" id="vFolhas" hidden aria-labelledby="tFolhas">
<h1 id="tFolhas">Minhas folhas</h1>
<div class="lista" id="sheets"></div>
</section>
<section class="vista" id="vDados" hidden aria-labelledby="tDados">
<h1 id="tDados">Dados da conta</h1>
<form class="bloco" id="fPerfil">

View File

@@ -28,7 +28,8 @@ function icone(nome){
return span.firstChild;
}
const PRODUTO={file:'DTF Têxtil · folha montada',avulsa:'DTF Têxtil · artes avulsas',
uvfile:'DTF UV · folha montada',uv:'DTF UV · artes avulsas'};
uvfile:'DTF UV · folha montada',uv:'DTF UV · artes avulsas',
premium:'DTF Têxtil Premium · folha montada'};
// Artes avulsas que o Site separou por traço (item 17): uma folha por item.
const nomeItem=item=>(PRODUTO[item.mode]||item.mode)+(item.split?' · folha '+item.split.part+' de '+item.split.of:'');
// The order's steps as the customer sees them (Dropstar's flow, 2026-10-23).
@@ -50,6 +51,7 @@ function vista(){
if(p==='/conta/entrar') return 'entrar';
if(p==='/conta/redefinir') return 'redefinir';
if(p==='/conta/dados') return 'dados';
if(p==='/conta/folhas') return 'folhas';
if(p==='/conta') return 'geral';
return 'pedidos'; // /conta/pedidos, and the old /portal.html
}
@@ -64,20 +66,22 @@ document.addEventListener('click',event=>{
async function mostra(){
aviso('');
const v=vista(), proximo=new URLSearchParams(location.search).get('next');
// Overview and details are the account's; orders also work for a guest.
if((v==='geral'||v==='dados')&&!conta){history.replaceState({},'','/conta/entrar?next='+encodeURIComponent(location.pathname));return mostra();}
// Overview, details and saved sheets are the account's; orders also work for a guest.
if((v==='geral'||v==='dados'||v==='folhas')&&!conta){history.replaceState({},'','/conta/entrar?next='+encodeURIComponent(location.pathname));return mostra();}
if(v==='entrar'&&conta){history.replaceState({},'',proximo&&/^\/conta(\/[a-z]+)?$/.test(proximo)?proximo:'/conta');return mostra();}
$('auth').hidden=v!=='entrar';
$('redefinir').hidden=v!=='redefinir';
$('area').hidden=v==='entrar'||v==='redefinir';
if(v==='redefinir'&&!resetToken)aviso('Este link está incompleto. Peça outro em “Esqueci minha senha”.',true);
$('vGeral').hidden=v!=='geral';$('vPedidos').hidden=v!=='pedidos';$('vDados').hidden=v!=='dados';
$('vFolhas').hidden=v!=='folhas';
for(const a of document.querySelectorAll('.lateral a'))a.classList.toggle('on',a.dataset.view===v);
for(const a of document.querySelectorAll('.lateral [data-conta]'))a.hidden=!conta;
$('navEntrar').hidden=!!conta;$('logout').hidden=!conta;
document.title=({entrar:'Entrar',redefinir:'Criar nova senha',geral:'Minha conta',pedidos:'Pedidos',dados:'Dados da conta'})[v]+' · DTF Dropstar';
document.title=({entrar:'Entrar',redefinir:'Criar nova senha',geral:'Minha conta',pedidos:'Pedidos',folhas:'Minhas folhas',dados:'Dados da conta'})[v]+' · DTF Dropstar';
if(v==='geral')await geral();
else if(v==='pedidos')await pedidos();
else if(v==='folhas')await folhas();
else if(v==='dados')dados();
}
@@ -299,6 +303,85 @@ async function geral(){
else{const v=node('div',null,'vazio');v.append(node('p','Seu primeiro pedido aparece aqui.'));const a=node('a','Enviar uma arte','bPri');a.href='/#envio';v.append(a);ultimo.append(v);}
}
// ---- Saved sheets (Minhas folhas) ----------------------------------------
const FOLHA_PAGINA={file:'/arquivo-por-metro',avulsa:'/artes-avulsas',uvfile:'/uv-arquivo-por-metro',
uv:'/uv-artes-avulsas',premium:'/arquivo-por-metro'};
const FOLHA_MAX=300*1024*1024;
const ddmm=d=>new Date(d).toLocaleDateString('pt-BR',{day:'2-digit',month:'2-digit'});
async function excluirFolha(id){
const r=await fetch('/api/account/sheets/'+encodeURIComponent(id),{method:'DELETE'});
const d=await r.json();
if(!r.ok){const error=new Error(typeof d.detail==='string'?d.detail:'Não foi possível excluir a folha.');error.status=r.status;throw error;}
return d;
}
async function guardarNoCarrinho(item){
const database=await new Promise((resolve,reject)=>{const req=indexedDB.open('dtf-local-cart',1);req.onupgradeneeded=()=>req.result.createObjectStore('cart');req.onsuccess=()=>resolve(req.result);req.onerror=()=>reject(req.error);});
try{
await new Promise((resolve,reject)=>{
const tx=database.transaction('cart','readwrite'),store=tx.objectStore('cart');
const req=store.get(scope);
req.onsuccess=()=>{
const saved=req.result;
const items=Array.isArray(saved?.items)?saved.items:[];
store.put({items:[...items,item],expires:Date.now()+86400000},scope);
};
tx.oncomplete=resolve;tx.onerror=()=>reject(tx.error);tx.onabort=()=>reject(tx.error);
});
}finally{database.close();}
}
function folhaCartao(f){
const card=node('article',null,'folhaCard');
const pic=node('div',null,'folhaPic');
if(f.picture){const img=node('img');img.alt='Miniatura da folha '+f.name;img.loading='lazy';img.src=f.picture;pic.append(img);}
else pic.append(node('div',null,'semFoto'));
const body=node('div',null,'folhaBody');
body.append(node('h2',f.name,'folhaNome'),node('p',PRODUTO[f.mode]||f.mode,'folhaProduto'),
node('p',metros(f.metres),'folhaMetros'));
const validade=f.available?'Arquivos até '+ddmm(f.files_until)
:(f.files_until?'Arquivos vencidos em '+ddmm(f.files_until)+'. Envie de novo para pedir.'
:'Arquivos vencidos. Envie de novo para pedir.');
body.append(node('p',validade,'folhaValidade'+(f.available?'':' vencida')));
card.append(pic,body);
const acoes=node('div',null,'folhaAcoes');
if(f.available){
acoes.append(button('Pedir de novo',async()=>{
const sheet=await api('/account/sheets/'+encodeURIComponent(f.id)+'/use',{});
await guardarNoCarrinho(sheet.item);
location.assign('/carrinho');
},'bPri bMini'));
if(Number(f.total_size)<=FOLHA_MAX){
acoes.append(button('Editar',()=>location.assign(FOLHA_PAGINA[f.mode]+'?folha='+encodeURIComponent(f.id)),'bSec'));
}else{
const grande=node('button','Grande demais para editar aqui. Use Pedir de novo.','bSec folhaGrande');
grande.type='button';grande.disabled=true;acoes.append(grande);
}
}
acoes.append(button('Excluir',async()=>{
if(!confirm('Excluir a folha “'+f.name+'”?'))return;
await excluirFolha(f.id);
await folhas();
},'bSec'));
card.append(acoes);
return card;
}
async function folhas(){
const lista=$('sheets');lista.replaceChildren();
const carregando=node('div',null,'vazio');carregando.append(node('p','Carregando…','nota2'));lista.append(carregando);
let data;
try{data=await api('/account/sheets');}
catch(error){lista.replaceChildren();aviso(error.message,true);return;}
lista.replaceChildren();
if(!data.sheets.length){
const vazio=node('div',null,'vazio');
vazio.append(node('p','Nenhuma folha salva. No carrinho, use Salvar em Minhas folhas.'));
lista.append(vazio);return;
}
const grade=node('div',null,'folhas');
for(const f of data.sheets)grade.append(folhaCartao(f));
lista.append(grade);
}
// ---- Account details -----------------------------------------------------
const CAMPOS_END=[['dNome','recipient'],['dRua','street'],['dNum','number'],['dComp','complement'],['dBairro','district'],['dCidade','city'],['dUf','state']];