PageSourceSearch

https://laiglesiafiel.com/assets/AdminDashboard-4d85363f.js

js laiglesiafiel.com collected 2026-10-02 01:36:09 UTC 17,298 bytes, 1 lines download raw bytes

1import{j as e,T as he,u as o,R as A,cd as W,cq as xe,cR as ue,q as G,cE as ge,O as B,E as pe,eb as F,ag as je,bb as fe,bp as be,cK as Ne,bR as ve,bQ as Ce}from"./vendor-ui-fc56ca80.js";import{r as d,e as we}from"./vendor-react-f9ccc48d.js";import{a1 as ye,a2 as Se,a3 as ke,a4 as Ae,a5 as De,a6 as Pe,a7 as Ie,a8 as Te,h as Re,B as c,t as D,v as P,w as I,y as T,I as ze,P as Ee,R as N,K as Le,M as Me,N as He,O as Ue,bP as Be,am as Fe}from"./index-90016d22.js";import{a as u}from"./adminService-9c8edc1b.js";import{u as Oe}from"./userService-352fd3e3.js";import{L as Ve}from"./LanguageIndicator-27d06f31.js";import{K as J,at as X}from"./vendor-firebase-a557f106.js";import{u as Ke,L as $e,ac as qe}from"./vendor-utils-323b9898.js";import"./vendor-charts-9af8b7c0.js";const _e=({isOpen:v,onClose:C,onConfirm:m,title:f,description:w,confirmText:R="Confirmar",cancelText:r="Cancelar",danger:h=!1})=>e.jsx(ye,{open:v,onOpenChange:C,children:e.jsxs(Se,{children:[e.jsxs(ke,{children:[e.jsxs(Ae,{className:"flex items-center",children:[h&&e.jsx(he,{className:"h-5 w-5 text-destructive mr-2"}),f]}),e.jsx(De,{children:w})]}),e.jsxs(Pe,{children:[e.jsx(Ie,{children:r}),e.jsx(Te,{onClick:m,className:h?"bg-destructive hover:bg-destructive/90":"",children:R})]})]})}),Qe=_e;function ts(){const[v,C]=d.useState(!0),[m,f]=d.useState([]),[w,R]=d.useState(""),[r,h]=d.useState({currentPage:1,totalPages:1,totalItems:0,pageSize:10}),[b,Y]=d.useState({column:"lastAccessDate",direction:"desc"}),[l,z]=d.useState({totalChurches:0,activeChurches:0,premiumPlan:0,newThisMonth:0}),[E,L]=d.useState(null),[O,M]=d.useState(!1),[H,V]=d.useState(!1),[y,U]=d.useState(null),[K,$]=d.useState([]),[Z,q]=d.useState(!1),{userData:S}=Re(),g=we(),{t:a,i18n:_}=Ke("admin");d.useEffect(()=>{if((S==null?void 0:S.role)!=="superadmin"){g("/login");return}k(),k()},[S,r.currentPage,b]);const k=async()=>{try{C(!0);const s={page:r.currentPage,pageSize:r.pageSize,searchTerm:w,sortBy:b.column,sortDirection:b.direction},t=await u.getAllChurches(s);f(t.items),h({...r,totalPages:t.totalPages,totalItems:t.totalItems});const n=await u.getDashboardStats();z({totalChurches:n.totalChurches,activeChurches:n.activeChurches,premiumPlan:n.premiumPlan,newThisMonth:n.newThisMonth})}catch(s){console.error("Error al cargar iglesias:",s),o.error(a("dashboard.errors.loadFailed"))}finally{C(!1)}},Q=()=>{h({...r,currentPage:1}),k()},ee=async()=>{try{V(!0),await u.updateMemberCountsForAllChurches(),o.success("Conteos de miembros actualizados correctamente"),await k()}catch(s){console.error("Error al actualizar conteos:",s),o.error("Error al actualizar los conteos de miembros")}finally{V(!1)}},se=()=>{r.currentPage<r.totalPages&&h({...r,currentPage:r.currentPage+1})},ae=()=>{r.currentPage>1&&h({...r,currentPage:r.currentPage-1})},te=s=>{if(!s)return"";const t=_.language==="es"?"es-CL":"en-US";return new Intl.DateTimeFormat(t,{year:"numeric",month:"short",day:"numeric"}).format(new Date(s))},p=s=>{Y(t=>({column:s,direction:t.column===s&&t.direction==="asc"?"desc":"asc"})),h(t=>({...t,currentPage:1}))},j=s=>b.column!==s?e.jsx(Ne,{className:"ml-2 h-4 w-4 text-muted-foreground/30"}):b.direction==="asc"?e.jsx(ve,{className:"ml-2 h-4 w-4"}):e.jsx(Ce,{className:"ml-2 h-4 w-4"}),re=s=>{if(!s)return a("dashboard.noAccess");const t=new Date(s),n=_.language==="es"?Fe:$e;return qe(t,{addSuffix:!0,locale:n})},ne=s=>{L(s),M(!0)},le=async()=>{if(E){const s=[...m],t={...l};f(m.filter(n=>n.id!==E)),z({...l,totalChurches:Math.max(0,l.totalChurches-1),activeChurches:Math.max(0,l.activeChurches-1)}),M(!1);try{await u.deleteChurchAndMembers(E),o.success(a("dashboard.success.deleteChurch"))}catch(n){console.error("Error al eliminar iglesia:",n),f(s),z(t),o.error(a("dashboard.errors.deleteFailed"))}}L(null)},ie=()=>{M(!1),L(null)},oe=async(s,t)=>{const n=t||void 0;try{const i=o.loading("Iniciando modo suplantación..."),{token:x}=await u.impersonateUser(n,s),me=J();await X(me,x),o.dismiss(i),o.success("Suplantación exitosa. Redirigiendo..."),g("/app/dashboard")}catch(i){console.error("Impersonation failed:",i),o.error("Error al iniciar suplantación. Revisa la consola.")}},de=async s=>{try{const t=o.loading("Iniciando modo suplantación..."),{token:n}=await u.impersonateUser(void 0,void 0,s);await X(J(),n),o.dismiss(t),o.success("Suplantación exitosa. Redirigiendo..."),g("/app/dashboard")}catch(t){console.error("Impersonation failed:",t),o.error("No se pudo suplantar. El usuario puede no tener cuenta activa (invitación pendiente).")}},ce=async s=>{U(s),$([]),q(!0);try{const t=await Oe.getUsersByChurch(s.id),n=i=>["admin","superadmin"].includes(i.roleId||i.role)?0:(i.roleId||i.role)==="editor"?1:2;t.sort((i,x)=>n(i)-n(x)||(i.displayName||"").localeCompare(x.displayName||"")),$(t)}catch{o.error("No se pudieron cargar los usuarios de la iglesia")}finally{q(!1)}};return v&&m.length===0?e.jsx("div",{className:"flex justify-center items-center h-96",children:e.jsx(A,{className:"h-12 w-12 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-center gap-4",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:a("dashboard.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(c,{onClick:()=>g("/admin/stats"),children:a("dashboard.globalStats")}
1),e.jsx(Ve,{})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs(D,{children:[e.jsx(P,{className:"pb-2",children:e.jsx(I,{className:"text-sm font-medium",children:a("dashboard.totalChurches")})}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(W,{className:"h-4 w-4 text-muted-foreground mr-2"}),e.jsx("div",{className:"text-2xl font-bold",children:l.totalChurches})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[l.activeChurches," ",a("dashboard.active")," (",Math.round(l.activeChurches/l.totalChurches*100),"%)"]})]})]}),e.jsxs(D,{children:[e.jsx(P,{className:"pb-2",children:e.jsx(I,{className:"text-sm font-medium",children:a("dashboard.activeChurches")})}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(W,{className:"h-4 w-4 text-muted-foreground mr-2"}),e.jsx("div",{className:"text-2xl font-bold",children:l.activeChurches})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[Math.round(l.activeChurches/l.totalChurches*100),"% ",a("dashboard.active")]})]})]}),e.jsxs(D,{children:[e.jsx(P,{className:"pb-2",children:e.jsx(I,{className:"text-sm font-medium",children:a("dashboard.premiumPlan")})}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(xe,{className:"h-4 w-4 text-muted-foreground mr-2"}),e.jsx("div",{className:"text-2xl font-bold",children:l.premiumPlan})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[Math.round(l.premiumPlan/l.totalChurches*100),"% ",a("dashboard.active")]})]})]}),e.jsxs(D,{children:[e.jsx(P,{className:"pb-2",children:e.jsx(I,{className:"text-sm font-medium",children:a("dashboard.newChurches")})}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(ue,{className:"h-4 w-4 text-muted-foreground mr-2"}),e.jsx("div",{className:"text-2xl font-bold",children:l.newThisMonth})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["+",Math.round(l.newThisMonth/l.totalChurches*100),"% ",a("dashboard.active")]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-center gap-4",children:[e.jsx("h2",{className:"text-xl font-bold",children:a("dashboard.registeredChurches")}),e.jsxs("div",{className:"flex items-center gap-2 w-full sm:w-auto",children:[e.jsxs("div",{className:"relative flex-1 sm:flex-none sm:w-64",children:[e.jsx(G,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ze,{type:"search",placeholder:a("dashboard.searchPlaceholder"),className:"pl-8",value:w,onChange:s=>R(s.target.value),onKeyDown:s=>s.key==="Enter"&&Q()})]}),e.jsx(c,{variant:"outline",size:"icon",onClick:Q,children:e.jsx(G,{className:"h-4 w-4"})}),e.jsxs(c,{variant:"outline",size:"sm",onClick:ee,disabled:H,title:"Recalcular conteo de miembros desde Firestore",children:[e.jsx(A,{className:`mr-2 h-4 w-4 ${H?"animate-spin":""}`}),H?"Actualizando...":"Actualizar Conteos"]}),e.jsxs(c,{onClick:()=>g("/admin/church/new"),variant:"default",children:[e.jsx(ge,{className:"mr-2 h-4 w-4"})," ",a("dashboard.actionsText.createNewChurch")]})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("dashboard.manageChurches")}),e.jsxs("div",{className:"border rounded-md",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium cursor-pointer hover:bg-muted/80 transition-colors",onClick:()=>p("name"),children:e.jsxs("div",{className:"flex items-center",children:[a("dashboard.tableHeaders.name"),j("name")]})}),e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium cursor-pointer hover:bg-muted/80 transition-colors",onClick:()=>p("plan"),children:e.jsxs("div",{className:"flex items-center",children:[a("dashboard.tableHeaders.plan"),j("plan")]})}),e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium cursor-pointer hover:bg-muted/80 transition-colors",onClick:()=>p("userCount"),children:e.jsxs("div",{className:"flex items-center",children:[a("dashboard.tableHeaders.users"),j("userCount")]})}),e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium hidden md:table-cell cursor-pointer hover:bg-muted/80 transition-colors",onClick:()=>p("memberCount"),children:e.jsxs("div",{className:"flex items-center",children:[a("dashboard.tableHeaders.members"),j("memberCount")]})}),e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium hidden md:table-cell cursor-pointer hover:bg-muted/80 transition-colors",onClick:()=>p("createdAt"),children:e.jsxs("div",{className:"flex items-center",children:[a("dashboard.tableHeaders.created"),j("createdAt")]})}),e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium hidden md:table-cell cursor-pointer hover:bg-muted/80 transition-colors",onClick:()=>p("lastAccessDate"),children:e.jsxs("div",{className:"flex items-center",children:[a("dashboard.tableHeaders.lastAccess"),j("lastAccessDate")]})}),e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium",children:a("dashboard.healthScore.title")}),e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium",children:a("dashboard.tableHeaders.status")}),e.jsx("th",{className:"py-3 px-4 text-right text-sm font-medium",children:a("dashboard.tableHeaders.actions")})]})}),e.jsx("tbody",{children:m.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"py-4 px-4 text-center text-muted-foreground",children:v?e.jsx("div",{className:"flex justify-center",children:e.jsx(A,{className:"h-5 w-5 animate-spin"})}):a("dashboard.noChurchesFound")})}):m.map(s=>{var x;const t=u.calculateHealthScore(s);let n="bg-red-100 text-red-800 border-red-200 dark:bg-red-900/50 dark:text-red-300 dark:border-red-900/50",i=a("dashboard.healthScore.low");return t>=80?(n="bg-green-100 text-green-800 border-green-200 dark:bg-green-900/50 dark:text-green-300 dark:border-green-900/50",i=a("dashboard.healthScore.high")):t>=50&&(n="bg-yellow-100 text-yellow-800 border-yellow-200 dark:bg-yellow-900/50 dark:text-yellow-300 dark:border-yellow-900/50",i=a("dashboard.healthScore.medium")),e.jsxs("tr",{className:"border-b",children:[e.jsxs("td",{className:"py-3 px-4",children:[e.jsx("div",{className:"font-medium",children:s.name}),s.email&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s.email})]}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("div",{className:"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold",children:((x=Ee[s.plan])==null?void 0:x.name)||s.plan})}),e.jsx("td",{className:"py-3 px-4",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(B,{className:"h-3 w-3 mr-1 text-muted-foreground"}),e.jsx("span",{children:s.userCount||0})]})}),e.jsx("td",{className:"py-3 px-4 hidden md:table-cell",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(B,{className:"h-3 w-3 mr-1 text-muted-foreground"}),e.jsx("span",{children:s.memberCount||0})]})}),e.jsx("td",{className:"py-3 px-4 hidden md:table-cell",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:te(s.createdAt)})}),e.jsx("td",{className:"py-3 px-4 hidden md:table-cell",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:re(s.lastAccessDate)})}),e.jsx("td",{className:"py-3 px-4",children:e.jsxs(N,{variant:"outline",className:`${n} border-0`,children:[t," (",i,")"]})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(N,{variant:"outline",className:s.status==="inactive"?"bg-destructive/10 text-destructive border-destructive/20":"bg-green-100 text-green-800 border-green-200 dark:bg-green-900/50 dark:text-green-300 dark:border-green-900/50",children:s.status==="inactive"?a("dashboard.statusLabels.inactive"):a("dashboard.statusLabels.active")})}),e.jsx("td",{className:"py-3 px-4 text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c,{variant:"default",size:"icon",onClick:()=>g(`/admin/church/${s.id}`),title:a("dashboard.actionsText.view"),children:e.jsx(pe,{className:"h-4 w-4"})}),e.jsx(c,{variant:"outline",size:"icon",className:"bg-purple-50 text-purple-600 border-purple-200 hover:bg-purple-100 dar
1k:bg-purple-950 dark:text-purple-400 dark:border-purple-900",onClick:()=>oe(s.id,s.createdBy),title:"Suplantar (Ver como Administrador)",children:e.jsx(F,{className:"h-4 w-4"})}),e.jsx(c,{variant:"outline",size:"icon",className:"bg-indigo-50 text-indigo-600 border-indigo-200 hover:bg-indigo-100 dark:bg-indigo-950 dark:text-indigo-400 dark:border-indigo-900",onClick:()=>ce(s),title:"Suplantar por perfil (elegir usuario)",children:e.jsx(B,{className:"h-4 w-4"})}),e.jsx(c,{variant:"outline",size:"icon",className:"text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:()=>ne(String(s.id)),title:a("dashboard.actionsText.delete"),children:e.jsx(je,{className:"h-4 w-4"})})]})})]},s.id)})})]})}),m.length>0&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:[a("dashboard.pagination.showing")," ",(r.currentPage-1)*r.pageSize+1,"-",Math.min(r.currentPage*r.pageSize,r.totalItems)," ",a("dashboard.pagination.of")," ",r.totalItems," ",a("dashboard.pagination.results")]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(c,{variant:"outline",size:"icon",onClick:ae,disabled:r.currentPage===1,children:e.jsx(fe,{className:"h-4 w-4"})}),e.jsx(c,{variant:"outline",size:"icon",onClick:se,disabled:r.currentPage===r.totalPages,children:e.jsx(be,{className:"h-4 w-4"})})]})]})]})]}),O&&e.jsx(Qe,{isOpen:O,onClose:ie,onConfirm:le,title:a("dashboard.deleteChurchDialog.title"),description:a("dashboard.deleteChurchDialog.message"),confirmText:a("dashboard.deleteChurchDialog.confirm"),cancelText:a("dashboard.deleteChurchDialog.cancel"),danger:!0}),e.jsx(Le,{open:!!y,onOpenChange:s=>!s&&U(null),children:e.jsxs(Me,{className:"max-w-lg max-h-[80vh] overflow-y-auto",children:[e.jsx(He,{children:e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4 text-indigo-600"}),"Suplantar por perfil — ",y==null?void 0:y.name]})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Elegí qué usuario suplantar para ver la app exactamente como él (rol + permisos reales, sin el bypass de super-admin)."}),Z?e.jsxs("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:[e.jsx(A,{className:"h-5 w-5 animate-spin mr-2"})," Cargando usuarios…"]}):K.length===0?e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No hay usuarios en esta iglesia."}):e.jsx("div",{className:"space-y-1.5",children:K.map(s=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border p-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.displayName||"(sin nombre)"}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:s.email}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[e.jsx(N,{variant:"secondary",className:"text-[10px]",children:s.roleId||s.role}),s.ministerialRole&&e.jsx(N,{variant:"outline",className:"text-[10px]",children:Be[s.ministerialRole]??s.ministerialRole}),s.status!=="active"&&e.jsx(N,{variant:"outline",className:"text-[10px] text-amber-600",children:s.status})]})]}),e.jsxs(c,{size:"sm",variant:"outline",className:"shrink-0 gap-1",disabled:!s.email||s.status==="pending",title:s.status==="pending"?"Invitación pendiente: sin cuenta para suplantar":"Suplantar",onClick:()=>{U(null),de(s.email)},children:[e.jsx(F,{className:"h-3.5 w-3.5"})," Suplantar"]})]},s.id))})]})})]})}export{ts 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.