PageSourceSearch

https://www.tdec.com.br/assets/AdminNewsletterSubscribers-BhGeK4Je.js

js tdec.com.br collected 2026-10-04 21:45:25 UTC 8,893 bytes, 8 lines download raw bytes

1import{c as T,s as U,r as a,j as e,H as $,L as h,B as S,F as O,e as n}from"./index-Dxm6N3LP.js";import{u as q}from"./useAuth-DxZh9XUt.js";import{s as x}from"./client-QodGYSS2.js";import{I as f}from"./input-Bvv_Rk_1.js";import{A as P}from"./arrow-left-CznwGBZ7.js";import{D as H}from"./download-BQ9pvODf.js";import{F as M}from"./file-text-CyCH_y0s.js";import{U as Q}from"./users-C8sYpBhY.js";import{S as V}from"./send-BhrBF3sV.js";import{P as z}from"./plus-BJmjVI5t.js";import{S as G}from"./search-D1VNy0HQ.js";import{C as J}from"./circle-check-BaSNrPRt.js";import{T as K}from"./trash-2-BoZcOlNn.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const W=T("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]),X=[{key:"all",label:"Todos"},{key:"active",label:"Ativos"},{key:"unsubscribed",label:"Cancelados"}],me=()=>{const{user:j,isAdmin:o,loading:g}=q(),N=U(),[c,E]=a.useState([]),[L,v]=a.useState(!0),[l,A]=a.useState("all"),[d,I]=a.useState(""),[b,w]=a.useState(""),[y,k]=a.useState("");a.useEffect(()=>{document.title="Inscritos da Newsletter — Admin TDec"},[]),a.useEffect(()=>{g||(!j||!o)&&N("/admin/login",{replace:!0})},[j,o,g,N]);const m=async()=>{v(!0);const{data:s,error:t}=await x.from("newsletter_subscribers").select("id, email, name, status, source, consent, created_at").order("created_at",{ascending:!1});t?n.error(t.message):E(s??[]),v(!1)};a.useEffect(()=>{o&&m()},[o]);const u=a.useMemo(()=>c.filter(s=>{const t=l==="all"||s.status===l,r=!d.trim()||(s.email+(s.name??"")).toLowerCase().includes(d.toLowerCase());return t&&r}),[c,l,d]),R=c.filter(s=>s.status==="active").length,C=async(s,t)=>{const{error:r}=await x.from("newsletter_subscribers").update({status:t}).eq("id",s);r?n.error(r.message):m()},B=async(s,t)=>{if(!window.confirm(`Remover ${t} da base de inscritos?`))return;const{error:r}=await x.from("newsletter_subscribers").delete().eq("id",s);r?n.error(r.message):(n.success("Inscrito removido."),m())},_=async()=>{const s=b.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(s)){n.error("E-mail inválido.");return}const{error:t}=await x.from("newsletter_subscribers").insert({email:s,name:y.trim()||null,source:"admin",consent:!0,status:"active"});t?n.error(t.message.includes("duplicate")?"Este e-mail já está inscrito.":t.message):(n.success("Inscrito adicionado."),w(""),k(""),m())},D=()=>{const s=`email,nome,status,origem,consentimento,data
7`,t=u.map(i=>[i.email,i.name??"",i.status,i.source,i.consent?"sim":"não",new Date(i.created_at).toLocaleString("pt-BR")].map(F=>`"${String(F).replace(/"/g,'""')}"`).join(",")).join(`
8`),r=URL.createObjectURL(new Blob([s+t],{type:"text/csv;charset=utf-8;"})),p=document.createElement("a");p.href=r,p.download=`inscritos-newsletter-${new Date().toISOString().slice(0,10)}.csv`,p.click(),URL.revokeObjectURL(r)};return e.jsxs("div",{className:"min-h-screen bg-background text-foreground",children:[e.jsx($,{}),e.jsx("main",{className:"pt-32 pb-24",children:e.jsxs("div",{className:"container-tdec",children:[e.jsxs(h,{to:"/admin",className:"inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground mb-6",children:[e.jsx(P,{className:"w-4 h-4"})," Painel Admin"]}),e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("div",{className:"eyebrow mb-2",children:"Newsletter"}),e.jsx("h1",{className:"font-display text-3xl md:text-4xl font-bold",children:"Inscritos"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[R," ativos de ",c.length," cadastros."]})]}),e.jsxs(S,{variant:"outline",onClick:D,children:[e.jsx(H,{className:"w-4 h-4"})," Exportar CSV"]})]}),e.jsxs("div",{className:"grid sm:grid-cols-3 gap-3 mb-6",children:[e.jsxs(h,{to:"/admin/newsletter",className:"card-tdec p-4 flex items-center gap-3 hover:border-primary/40 transition-colors",children:[e.jsx(M,{className:"w-5 h-5 text-primary-glow"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:"Notícias"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Conteúdo da newsletter"})]})]}),e.jsxs("div",{className:"card-tdec p-4 flex items-center gap-3 border-primary/40",children:[e.jsx(Q,{className:"w-5 h-5 text-primary-glow"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:"Inscritos"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Base de e-mails"})]})]}),e.jsxs(h,{to:"/admin/newsletter/campaigns",className:"card-tdec p-4 flex items-center gap-3 hover:border-primary/40 transition-colors",children:[e.jsx(V,{className:"w-5 h-5 text-primary-glow"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:"Campanhas"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Envios e histórico"})]})]})]}),e.jsxs("div",{className:"card-tdec p-5 mb-6",children:[e.jsx("div",{className:"text-sm font-medium mb-3",children:"Adicionar inscrito manualmente"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsx(f,{value:y,onChange:s=>k(s.target.value),placeholder:"Nome (opcional)",className:"sm:max-w-[240px]"}),e.jsx(f,{value:b,onChange:s=>w(s.target.value),type:"email",placeholder:"[email protected]"}),e.jsxs(S,{variant:"hero",onClick:_,children:[e.jsx(z,{className:"w-4 h-4"})," Adicionar"]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-5",children:[e.jsxs("div",{className:"relative flex-1 min-w-[220px]",children:[e.jsx(G,{className:"absolute left-3.5 to
8p-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(f,{value:d,onChange:s=>I(s.target.value),placeholder:"Buscar por e-mail ou nome...",className:"pl-10"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:X.map(s=>e.jsx("button",{onClick:()=>A(s.key),className:`px-3.5 py-2 rounded-full text-[11px] font-mono uppercase tracking-[0.15em] border transition-all ${l===s.key?"bg-gradient-primary border-primary text-primary-foreground":"border-border text-muted-foreground hover:border-primary/50 hover:text-foreground"}`,children:s.label},s.key))})]}),e.jsx("div",{className:"card-tdec overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm min-w-[720px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs font-mono uppercase tracking-[0.15em] text-muted-foreground border-b border-border",children:[e.jsx("th",{className:"px-5 py-3",children:"E-mail"}),e.jsx("th",{className:"px-5 py-3",children:"Nome"}),e.jsx("th",{className:"px-5 py-3",children:"Origem"}),e.jsx("th",{className:"px-5 py-3",children:"Inscrição"}),e.jsx("th",{className:"px-5 py-3",children:"Status"}),e.jsx("th",{className:"px-5 py-3 text-right",children:"Ações"})]})}),e.jsx("tbody",{children:L?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-5 py-10 text-center text-muted-foreground",children:"Carregando..."})}):u.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-5 py-10 text-center text-muted-foreground",children:"Nenhum inscrito encontrado."})}):u.map(s=>e.jsxs("tr",{className:"border-b border-border/60 hover:bg-muted/20",children:[e.jsx("td",{className:"px-5 py-3 font-medium",children:s.email}),e.jsx("td",{className:"px-5 py-3 text-muted-foreground",children:s.name||"—"}),e.jsx("td",{className:"px-5 py-3 text-muted-foreground font-mono text-xs",children:s.source}),e.jsx("td",{className:"px-5 py-3 text-muted-foreground font-mono text-xs",children:new Date(s.created_at).toLocaleDateString("pt-BR")}),e.jsx("td",{className:"px-5 py-3",children:e.jsx("span",{className:`px-2 py-1 rounded-full text-[10px] font-mono uppercase tracking-wider ${s.status==="active"?"bg-primary/15 text-primary-glow":"bg-muted/40 text-muted-foreground"}`,children:s.status==="active"?"Ativo":"Cancelado"})}),e.jsx("td",{className:"px-5 py-3 text-right",children:e.jsxs("div",{className:"inline-flex items-center justify-end gap-1",children:[s.status==="active"?e.jsx("button",{onClick:()=>C(s.id,"unsubscribed"),className:"w-8 h-8 inline-flex items-center justify-center rounded hover:bg-muted/40 text-muted-foreground",title:"Cancelar inscrição",children:e.jsx(W,{className:"w-4 h-4"})}):e.jsx("button",{onClick:()=>C(s.id,"active"),className:"w-8 h-8 inline-flex items-center justify-center rounded hover:bg-primary/15 text-primary-glow",title:"Reativar",children:e.jsx(J,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>B(s.id,s.email),className:"w-8 h-8 inline-flex items-center justify-center rounded hover:bg-destructive/20 hover:text-destructive text-muted-foreground",title:"Excluir",children:e.jsx(K,{className:"w-4 h-4"})})]})})]},s.id))})]})})})]})}),e.jsx(O,{})]})};export{me as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.