PageSourceSearch

https://laiglesiafiel.com/assets/RecipientListsPage-60f1d5e0.js

js laiglesiafiel.com collected 2026-10-02 01:36:19 UTC 11,418 bytes, 4 lines download raw bytes

1import{u as i,j as e,q,R as B,O as H,ay as te,aj as re,cV as le,ag as J,d0 as ie,au as ne,a_ as ce}from"./vendor-ui-fc56ca80.js";import{r as t,e as oe}from"./vendor-react-f9ccc48d.js";import{K,M as V,N as Q,O as X,Q as de,ae as me,ag as xe,ah as U,ai as Z,I as T,B as n,z as $,T as he,am as W,h as ue,t as pe,v as je,w as ge,x as fe,y as Ne,F as ve,az as be}from"./index-90016d22.js";import{r as h}from"./recipientListService-56a8618e.js";import{ac as Y}from"./vendor-utils-323b9898.js";import"./vendor-firebase-a557f106.js";import"./vendor-charts-9af8b7c0.js";function we({list:r,open:b,onOpenChange:I,onUpdate:w}){const[u,p]=t.useState([]),[k,d]=t.useState(!1),[o,j]=t.useState(""),[y,C]=t.useState(!1),[g,z]=t.useState(""),[P,S]=t.useState("list"),[f,L]=t.useState(null),[m,N]=t.useState(""),[x,R]=t.useState(!1),A=a=>{L(a.id||null),N(a.name||"")},E=()=>{L(null),N("")},D=async()=>{if(!(!r||!f))try{R(!0),await h.updateRecipient(r.id,f,{name:m}),p(a=>a.map(l=>l.id===f?{...l,name:m}:l)),i.success("Nombre actualizado"),E()}catch(a){console.error("Update failed",a),i.error("Error al actualizar")}finally{R(!1)}};t.useEffect(()=>{b&&r&&(s(),j(""),S("list"))},[b,r]);const s=async()=>{if(r)try{d(!0);const a=await h.getRecipients(r.id);p(a)}catch(a){console.error("Failed to load recipients:",a),i.error("Error al cargar destinatarios")}finally{d(!1)}},v=async()=>{if(!(!r||!o.trim())){C(!0);try{const a=o.split(/[\n,;]+/),l=[],c=/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/;let M=0;if(a.forEach(ae=>{const O=ae.trim();if(!O)return;const _=O.match(c);if(_){const G=_[0],se=O.replace(G,"").replace(/[<>,"']/g,"").trim();l.push({email:G,name:se||void 0})}else M++}),l.length===0){i.warning("No se encontraron emails válidos.");return}await h.addRecipients(r.id,l),i.success(`${l.length} destinatarios agregados.`),M>0&&i.warning(`${M} líneas no contenían emails válidos.`),j(""),s(),w(),S("list")}catch(a){console.error("Import failed:",a),i.error("Error al importar destinatarios")}finally{C(!1)}}},ee=async a=>{if(!r||!a)return;const l=[...u];p(l.filter(c=>c.id!==a));try{await h.deleteRecipient(r.id,a),w()}catch(c){console.error("Delete failed",c),i.error("Error al eliminar"),p(l)}},F=u.filter(a=>a.email.toLowerCase().includes(g.toLowerCase())||a.name&&a.name.toLowerCase().includes(g.toLowerCase()));return e.jsx(K,{open:b,onOpenChange:I,children:e.jsxs(V,{className:"max-w-3xl h-[80vh] flex flex-col p-0 gap-0",children:[e.jsxs(Q,{className:"px-6 py-4 border-b",children:[e.jsxs(X,{children:["Gestionar Lista: ",r==null?void 0:r.name]}),e.jsxs(de,{children:[r==null?void 0:r.recipientCount," contactos en total."]})]}),e.jsxs(me,{value:P,onValueChange:S,className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"px-6 py-2 bg-slate-50 border-b",children:e.jsxs(xe,{className:"grid w-full grid-cols-2 max-w-sm",children:[e.jsx(U,{value:"list",children:"Lista de Miembros"}),e.jsx(U,{value:"import",children:"Importar / Agregar"})]})}),e.jsxs(Z,{value:"list",className:"flex-1 flex flex-col p-0 m-0 overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(q,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-slate-500"}),e.jsx(T,{placeholder:"Buscar por email o nombre...",className:"pl-9",value:g,onChange:a=>z(a.target.value)})]}),e.jsx(n,{variant:"outline",size:"icon",onClick:s,disabled:k,children:e.jsx(B,{className:`h-4 w-4 ${k?"animate-spin":""}`})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:F.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-48 text-slate-500",children:[e.jsx(H,{className:"h-10 w-10 mb-2 opacity-20"}),e.jsx("p",{children:"No hay destinatarios encontrados."})]}):e.jsxs("table",{className:"w-full text-sm text-left",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 font-medium sticky top-0 md:bg-white bg-slate-50 z-10",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 border-b",children:"Email"}),e.jsx("th",{className:"px-4 py-2 border-b",children:"Nombre"}),e.jsx("th",{className:"px-4 py-2 border-b w-32",children:"Agregado"}),e.jsx("th",{className:"px-4 py-2 border-b w-10"})]})}),e.jsx("tbody",{children:F.map(a=>{const l=f===a.id;return e.jsxs("tr",{className:`border-b ${l?"bg-blue-50/50":"hover:bg-slate-50"}`,children:[e.jsx("td",{className:"px-4 py-2 font-medium",children:a.email}),e.jsx("td",{className:"px-4 py-2 text-slate-600",children:l?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{value:m,onChange:c=>N(c.target.value),className:"h-8 text-sm w-full",placeholder:"Nombre...",onKeyDown:c=>{c.key==="Enter"&&D(),c.key==="Escape"&&E()},autoFocus:!0}),e.jsx(n,{size:"icon",variant:"ghost",className:"h-8 w-8 text-green-600 hover:text-green-700 hover:bg-green-50",onClick:D,disabled:x,children:e.jsx(te,{className:"h-4 w-4"})}),e.jsx(n,{size:"icon",variant:"ghost",className:"h-8 w-8 text-slate-400 hover:text-slate-600 hover:bg-slate-100",onClick:E,disabled:x,children:e.jsx(re,{className:"h-4 w-4"})})]}):e.jsxs("div",{className:"flex items-center group/name gap-2",children:[e.jsx("span",{className:"cursor-pointer hover:underline hover:text-blue-600",onClick:()=>A(a),children:a.name||e.jsx("span",{className:"text-slate-300 italic",children:"Sin nombre"})}),e.jsx(le,{className:"h-3 w-3 text-slate-300 opacity-0 group-hover/name:opacity-100 cursor-pointer hover:text-blue-500",onClick:()=>A(a)})]})}),e.jsx("td",{className:"px-4 py-2 text-slate-400 text-xs",children:a.addedAt?Y(a.addedAt.toDate?a.addedAt.toDate():new Date,{locale:W}):"-"}),e.jsx("td",{className:"px-4 py-2",children:!l&&e.jsx(n,{variant:"ghost",size:"icon",className:"h-6 w-6 text-red-400 hover:text-red-600",onClick:()=>a.id&&ee(a.id),children:e.jsx(J,{className:"h-3 w-3"})})})]},a.id)})})]})}),e.jsxs("div",{className:"p-2 border-t text-xs text-center text-slate-400 bg-slate-50",children:["Mostrando ",F.length," de ",u.length]})]}),e.jsx(Z,{value:"import",className:"flex-1 flex flex-col p-6 m-0 overflow-y-auto",children:e.jsxs("div",{className:"space-y-4 max-w-2xl mx-auto w-full",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Pegar Lista de Contactos"}),e.jsxs("p",{className:"text-sm text-slate-500",children:["Pega aquí tus contactos. El sistema detectará automáticamente los emails.",e.jsx("br",{}
1),"Formatos soportados:",e.jsx("br",{}),"- ",e.jsx("code",{children:"[email protected]"}),e.jsx("br",{}),"- ",e.jsx("code",{children:"Juan Pérez <[email protected]>"}),e.jsx("br",{}),"- ",e.jsx("code",{children:"Juan Pérez, [email protected]"})]}),e.jsx(he,{className:"font-mono text-sm h-64",placeholder:`[email protected]
2Pedro <[email protected]>
3...`,value:o,onChange:a=>j(a.target.value)})]}),e.jsx(n,{onClick:v,disabled:y||!o.trim(),className:"w-full",children:y?e.jsxs(e.Fragment,{children:[e.jsx(B,{className:"mr-2 h-4 w-4 animate-spin"}),"Procesando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),"Importar Contactos"]})})]})})]})]})})}function ke(){const[r,b]=t.useState([]),[I,w]=t.useState(!0),[u,p]=t.useState(""),[k,d]=t.useState(!1),[o,j]=t.useState(""),[y,C]=t.useState(""),[g,z]=t.useState(!1),[P,S]=t.useState(null),[f,L]=t.useState(!1),{userData:m}=ue(),N=oe();t.useEffect(()=>{if((m==null?void 0:m.role)!=="superadmin"){N("/app/dashboard");return}x()},[m,N]);const x=async()=>{try{w(!0);const s=await h.getLists();b(s)}catch(s){i.error("Error al cargar listas"),console.error(s)}finally{w(!1)}},R=async()=>{if(o.trim()){z(!0);try{await h.createList(o,y),i.success("Lista creada"),d(!1),j(""),C(""),x()}catch(s){i.error("Error al crear la lista"),console.error(s)}finally{z(!1)}}},A=async s=>{if(window.confirm(`¿Estás seguro de eliminar la lista "${s.name}"?
4Esta acción no se puede deshacer.`))try{await h.deleteList(s.id),i.success("Lista eliminada"),x()}catch(v){i.error("Error al eliminar"),console.error(v)}},E=s=>{S(s),L(!0)},D=r.filter(s=>s.name.toLowerCase().includes(u.toLowerCase()));return e.jsxs("div",{className:"space-y-6 container mx-auto px-4 py-8 max-w-7xl",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight text-slate-900",children:"Listas de Destinatarios"}),e.jsx("p",{className:"text-slate-500 mt-1",children:"Gestiona audiencias personalizadas para tus comunicados globales."})]}),e.jsxs(n,{onClick:()=>d(!0),children:[e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Nueva Lista"]})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(q,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-slate-500"}),e.jsx(T,{placeholder:"Buscar listas...",className:"pl-9",value:u,onChange:s=>p(s.target.value)})]})}),I?e.jsx("div",{className:"flex justify-center p-12",children:e.jsx(B,{className:"h-8 w-8 animate-spin text-slate-400"})}):D.length===0?e.jsxs("div",{className:"text-center py-16 bg-slate-50 rounded-lg border border-dashed",children:[e.jsx(H,{className:"h-12 w-12 mx-auto text-slate-300 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-slate-900",children:"No tienes listas creadas"}),e.jsx("p",{className:"text-slate-500 mb-4",children:"Crea una lista para empezar a agregar destinatarios externos."}),e.jsx(n,{onClick:()=>d(!0),variant:"outline",children:"Crear mi primera lista"})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:D.map(s=>{var v;return e.jsxs(pe,{className:"group hover:shadow-md transition-shadow",children:[e.jsxs(je,{className:"pb-3",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsx(ge,{className:"text-lg font-semibold",children:s.name}),e.jsxs("div",{className:"bg-slate-100 text-slate-600 text-xs px-2 py-1 rounded-full font-medium",children:[s.recipientCount," miembros"]})]}),e.jsx(fe,{className:"line-clamp-2 min-h-[40px]",children:s.description||"Sin descripción"})]}),e.jsx(Ne,{className:"pb-3",children:e.jsxs("div",{className:"text-xs text-slate-400",children:["Creada ",Y((v=s.createdAt)!=null&&v.toDate?s.createdAt.toDate():new Date,{addSuffix:!0,locale:W})]})}),e.jsxs(ve,{className:"pt-3 border-t bg-slate-50/50 flex justify-end gap-2",children:[e.jsx(n,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-600 hover:bg-red-50",onClick:()=>A(s),children:e.jsx(J,{className:"h-4 w-4"})}),e.jsxs(n,{variant:"secondary",size:"sm",onClick:()=>E(s),children:[e.jsx(ce,{className:"h-4 w-4 mr-2"}),"Gestionar"]})]})]},s.id)})}),e.jsx(K,{open:k,onOpenChange:d,children:e.jsxs(V,{children:[e.jsx(Q,{children:e.jsx(X,{children:"Crear Nueva Lista"})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Nombre de la Lista"}),e.jsx(T,{value:o,onChange:s=>j(s.target.value),placeholder:"Ej: Invitados Conferencia 2024"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Descripción (Opcional)"}),e.jsx(T,{value:y,onChange:s=>C(s.target.value),placeholder:"Breve descripción..."})]})]}),e.jsxs(be,{children:[e.jsx(n,{variant:"outline",onClick:()=>d(!1),children:"Cancelar"}),e.jsx(n,{onClick:R,disabled:g||!o.trim(),children:g?"Creando...":"Crear Lista"})]})]})}
4),e.jsx(we,{list:P,open:f,onOpenChange:L,onUpdate:x})]})}export{ke 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.