PageSourceSearch

https://zeropointlabs.ai/assets/NewsletterManagement-Dzi8ivJr.js

js zeropointlabs.ai collected 2026-10-05 15:19:45 UTC 7,491 bytes, 12 lines download raw bytes

1import{c as q,r as v,ak as O,u as V,j as e,C as d,e as y,f as b,U as z,a as m,I as R,g as p,s as g,w as n}from"./index-CLtGP32Z.js";import{u as D}from"./useMutation-BvxM86re.js";import{B as K}from"./badge-BKvD35-V.js";import{T as X,a as $,b as k,c as x,d as P,e as u}from"./table-VQ_0MYAS.js";import{S as G,a as J,b as W,c as Y,d as w}from"./select-Bq2l4yDN.js";import{A as Z,a as ee,b as se,c as te,d as ae,e as re,f as le,g as ie}from"./alert-dialog-nG4Kb3iB.js";import{S as ne}from"./search-CW3eO2GS.js";import{D as ce}from"./download-0Cc2Blf3.js";import{M as T}from"./mail-BrhL5Kus.js";import{T as oe}from"./trash-2-MtCU_bNd.js";import"./index-CMZ90543.js";import"./index-DAJOau0q.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 _=q("UserCheck",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["polyline",{points:"16 11 18 13 22 9",key:"1pwet4"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const I=q("UserX",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"17",x2:"22",y1:"8",y2:"13",key:"3nzzx3"}],["line",{x1:"22",x2:"17",y1:"8",y2:"13",key:"1swrse"}]]),we=()=>{const[h,E]=v.useState(""),[c,F]=v.useState("all"),[j,f]=v.useState(null),N=O(),{data:a,isLoading:L}=V({queryKey:["admin-newsletter"],queryFn:async()=>{const{data:s,error:t}=await g.from("newsletter_subscribers").select("*").order("subscribed_at",{ascending:!1});if(t)throw t;return s}}),S=D({mutationFn:async({id:s,isActive:t})=>{const{error:l}=await g.from("newsletter_subscribers").update({is_active:!t}).eq("id",s);if(l)throw l},onSuccess:()=>{N.invalidateQueries({queryKey:["admin-newsletter"]}),n.success("Subscriber status updated")},onError:()=>{n.error("Could not update subscriber status")}}),M=D({mutationFn:async s=>{const{error:t}=await g.from("newsletter_subscribers").delete().eq("id",s);if(t)throw t},onSuccess:()=>{N.invalidateQueries({queryKey:["admin-newsletter"]}),n.success("Subscriber deleted"),f(null)},onError:()=>{n.error("Could not delete subscriber")}}),r=a==null?void 0:a.filter(s=>{const t=s.email.toLowerCase().includes(h.toLowerCase()),l=c==="all"||c==="active"&&s.is_active||c==="inactive"&&!s.is_active;return t&&l}),C=(a==null?void 0:a.length)||0,A=(a==null?void 0:a.filter(s=>s.is_active).length)||0,U=C-A,H=()=>{if(!r||r.length===0){n.error("No data to export");return}const s=["Email","Status","Subscribed Date"],t=r.map(o=>[o.email,o.is_active?"Active":"Inactive",new Date(o.subscribed_at).toLocaleDateString()]),l=[s.join(","),...t.map(o=>o.join(","))].join(`
12`),Q=new Blob([l],{type:"text/csv;charset=utf-8;"}),i=document.createElement("a"),B=URL.createObjectURL(Q);i.setAttribute("href",B),i.setAttribute("download",`newsletter-subscribers-${new Date().toISOString().split("T")[0]}.csv`),i.style.visibility="hidden",document.body.appendChild(i),i.click(),document.body.removeChild(i),n.success(`Exported ${r.length} subscribers to CSV`)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Newsletter Subscribers"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Manage your newsletter subscriber list"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs(d,{children:[e.jsxs(y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(b,{className:"text-sm font-medium",children:"Total Subscribers"}),e.jsx(z,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(m,{children:e.jsx("div",{className:"text-2xl font-bold",children:C})})]}),e.jsxs(d,{children:[e.jsxs(y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(b,{className:"text-sm font-medium",children:"Active"}),e.jsx(_,{className:"h-4 w-4 text-green-500"})]}),e.jsx(m,{children:e.jsx("div",{className:"text-2xl font-bold",children:A})})]}),e.jsxs(d,{children:[e.jsxs(y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(b,{className:"text-sm font-medium",children:"Inactive"}),e.jsx(I,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(m,{children:e.jsx("div",{className:"text-2xl font-bold",children:U})})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ne,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(R,{placeholder:"Search by email...",value:h,onChange:s=>E(s.target.value),className:"pl-10"})]}),e.jsxs(G,{value:c,onValueChange:s=>F(s),children:[e.jsx(J,{className:"w-full sm:w-[180px]",children:e.jsx(W,{placeholder:"Filter by status"})}),e.jsxs(Y,{children:[e.jsx(w,{value:"all",children:"All Subscribers"}),e.jsx(w,{value:"active",children:"Active Only"}),e.jsx(w,{value:"inactive",children:"Inactive Only"})]})]}),e.jsxs(p,{onClick:H,variant:"outline",className:"gap-2",children:[e.jsx(ce,{className:"h-4 w-4"})," Export CSV"]})]}),L?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading subscribers..."}):r&&r.length>0?e.jsx("div",{className:"border rounded-lg",children:e.jsxs(X,{children:[e.jsx($,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Email"}),e.jsx(x,{children:"Status"}),e.jsx(x,{children:"Subscribed Date"}),e.jsx(x,{className:"text-right",children:"Actions"})]})}),e.jsx(P,{children:r.map(s=>e.jsxs(k,{children:[e.jsx(u,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"h-4 w-4 text-muted-foreground"}),s.email]})}),e.jsx(u,{children:e.jsx(K,{variant:s.is_active?"default":"secondary",children:s.is_active?"Active":"Inactive"})}),e.jsx(u,{children:new Date(s.subscribed_at).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}),e.jsx(u,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(p,{size:"sm",variant:"outline",onClick:()=>S.mutate({id:s.id,isActive:s.is_active}),disabled:S.isPending,children:s.is_active?e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"h-4 w-4 mr-1"}),"Deactivate"]}):e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"h-4 w-4 mr-1"}),"Activate"]})}),e.jsx(p,{size:"sm",variant:"destructive",onClick:()=>f(s.id),children:e.jsx(oe,{className:"h-4 w-4"})})]})})]},s.id))})]})}):e.jsx(d,{children:e.jsxs(m,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(T,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No subscribers found"}),e.jsx("p",{className:"text-muted-foreground text-center",children:h||c!=="all"?"Try adjusting your filters":"No one has subscribed to the newsletter yet"})]})}),e.jsx(Z,{open:!!j,onOpenChange:()=>f(null),children:e.jsxs(ee,{children:[e.jsxs(se,{children:[e.jsx(te,{children:"Are you sure?"}),e.jsx(ae,{children:"This will permanently delete the subscriber from the newsletter list."})]}),e.jsxs(re,{children:[e.jsx(le,{children:"Cancel"}),e.jsx(ie,{onClick:()=>j&&M.mutate(j),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})})]})};export{we 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.