PageSourceSearch

https://irpa2026colombia.org/assets/SponsorsAdmin-DZcWHR8F.js

js irpa2026colombia.org collected 2026-10-08 03:16:50 UTC 13,805 bytes, 1 lines download raw bytes

1import{u as ne,g as ce,d as de,r as x,s as d,j as e,b as q,B as t,A as B}from"./index-DnVm687U.js";import{H as G,F as H}from"./Footer-Bvqa_r8G.js";import{C as me,b as xe,c as he,d as ue,a as ge}from"./card-CRFaJYNz.js";import{I as A}from"./input-D4ugazI8.js";import{L as v}from"./label-BWZGrcrB.js";import{S as je}from"./switch-BVLlnVxk.js";import{T as pe,a as fe,b as R,c as u,d as ve,e as g}from"./table-DWz2i9MN.js";import{D as we,a as be,b as Ne,c as _e,d as ye,e as Ce,f as Ae}from"./dialog-BQOPzVNo.js";import{A as O,a as U,b as V,c as W,d as $,e as J,f as K,g as M,h as X}from"./alert-dialog-RI-hpkS0.js";import{B as De}from"./badge-BLNB1n0H.js";import{A as Ee,b as Pe,a as Se}from"./alert-CuNsnv7-.js";import{A as ke}from"./arrow-left-i1Qu9EeE.js";import{I as Te}from"./info-zLLFQJ0e.js";import{P as Le}from"./plus-Bh0gLK_k.js";import{I as ze}from"./image-De8TZUUA.js";import{E as Y}from"./external-link-DgRNJBvk.js";import{A as Z}from"./arrow-down-DUlxwCgi.js";import{S as Q}from"./square-pen-VVKvgBd-.js";import{T as ee}from"./trash-2-mVbNQiFx.js";import"./dropdown-menu-elZyZctl.js";import"./index-B-Wc5f3e.js";import"./Combination-D1NCdNup.js";import"./index-C7OIboLl.js";import"./shield-BN1RiLGr.js";import"./log-out-CtUQRbPX.js";import"./search-BNZJvCG8.js";import"./mail-BBtFmBsn.js";import"./index-Cue5PJE5.js";import"./index-yRo4nqrX.js";const da=()=>{const w=ne(),{user:D,userRole:b,loading:N}=ce(),{toast:l}=de(),[n,ae]=x.useState([]),[se,re]=x.useState(!0),[_,E]=x.useState(!1),[ie,y]=x.useState(!1),[i,P]=x.useState(null),[S,C]=x.useState(null),[r,h]=x.useState({name:"",website_url:"",is_active:!0,logo_file:null});x.useEffect(()=>{if(!N){if(!D||b!=="super_admin"&&b!=="admin_association"){w("/auth");return}j()}},[D,b,N,w]);const j=async()=>{try{const{data:a,error:s}=await d.from("sponsors").select("*").order("display_order",{ascending:!0});if(s)throw s;ae(a||[])}catch(a){l({title:"Error al cargar patrocinadores",description:a.message,variant:"destructive"})}finally{re(!1)}},te=a=>{var c;const s=(c=a.target.files)==null?void 0:c[0];if(!s)return;if(s.size>500*1024){l({title:"Archivo muy grande",description:"El logo no puede superar 500 KB",variant:"destructive"});return}if(!["image/png","image/jpeg","image/jpg","image/webp","image/svg+xml"].includes(s.type)){l({title:"Formato inválido",description:"Solo se permiten archivos PNG, JPG, WEBP o SVG",variant:"destructive"});return}h({...r,logo_file:s});const o=new FileReader;o.onloadend=()=>{C(o.result)},o.readAsDataURL(s)},le=async a=>{const s=a.name.split(".").pop(),o=`${Math.random().toString(36).substring(2)}-${Date.now()}.${s}`,{error:c}=await d.storage.from("sponsor-logos").upload(o,a);if(c)throw c;const{data:{publicUrl:p}}=d.storage.from("sponsor-logos").getPublicUrl(o);return p},k=async a=>{try{const s=a.split("/").pop();s&&await d.storage.from("sponsor-logos").remove([s])}catch(s){console.error("Error deleting logo:",s)}},oe=async a=>{if(a.preventDefault(),!r.name.trim()){l({title:"Nombre requerido",description:"Por favor ingrese el nombre del patrocinador",variant:"destructive"});return}if(!i&&!r.logo_file){l({title:"Logo requerido",description:"Por favor seleccione un logo",variant:"destructive"});return}E(!0);try{let s=(i==null?void 0:i.logo_url)||"";if(r.logo_file&&(s=await le(r.logo_file),i!=null&&i.logo_url&&await k(i.logo_url)),i){const{error:m}=await d.from("sponsors").update({name:r.name,logo_url:s,website_url:r.website_url||null,is_active:r.is_active}).eq("id",i.id);if(m)throw m;l({title:"Patrocinador actualizado",description:"Los cambios se guardaron correctamente"})}else{const m=n.length>0?Math.max(...n.map(c=>c.display_order)):-1,{error:o}=await d.from("sponsors").insert({name:r.name,logo_url:s,website_url:r.website_url||null,is_active:r.is_active,display_order:m+1});if(o)throw o;l({title:"Patrocinador agregado",description:"El nuevo patrocinador se agregó correctamente"})}y(!1),F(),j()}catch(s){l({title:"Error",description:s.message,variant:"destructive"})}finally{E(!1)}},T=a=>{P(a),h({name:a.name,website_url:a.website_url||"",is_active:a.is_active,logo_file:null}),C(a.logo_url),y(!0)},L=async a=>{try{await k(a.logo_url);const{error:s}=await d.from("sponsors").delete().eq("id",a.id);if(s)throw s;l({title:"Patrocinador eliminado",description:"El patrocinador se eliminó correctamente"}),j()}catch(s){l({title:"Error al eliminar",description:s.message,variant:"destructive"})}},z=async a=>{try{const{error:s}=await d.from("sponsors").update({is_active:!a.is_active}).eq("id",a.id);if(s)throw s;l({title:a.is_active?"Patrocinador desactivado":"Patrocinador activado",description:`El patrocinador ahora está ${a.is_active?"oculto":"visible"} en el carrusel`}),j()}catch(s){l({title:"Error",description:s.message,variant:"destructive"})}},f=async(a,s)=>{const m=n.findIndex(p=>p.id===a.id),o=s==="up"?m-1:m+1;if(o<0||o>=n.length)return;const c=n[o];try{await d.from("sponsors").update({display_order:c.display_order}).eq("id",a.id),await d.from("sponsors").update({display_order:a.display_order}).eq("id",c.id),j()}catch(p){l({title:"Error al reordenar",description:p.message,variant:"destructive"})}},F=()=>{h({name:"",website_url:"",is_active:!0,logo_file:null}),C(null),P(null)},I=a=>{y(a),a||F()};return N||se?e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx(G,{}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(q,{className:"w-8 h-8 animate-spin text-primary"})}),e.jsx(H,{})]}):e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx(G,{}),e.jsx("main",{className:"flex-1 bg-gradient-to-b from-background to-muted/20 py-8 md:py-12 mt-20",children:e.jsxs("div",{className:"container mx-auto px-3 md:px-4 max-w-6xl",children:[e.jsxs("div",{className:"flex items-center gap-3 md:gap-4 mb-6 md:mb-8",children:[e.jsx(t,{variant:"ghost",size:"icon",className:"shrink-0",onClick:()=>w("/admin?tab=management"),children:e.jsx(ke,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl md:text-4xl font-bold",children:"Gestión de Patrocinadores"}),e.jsx("p",{className:"text-muted-foreground mt-1 md:mt-2 text-sm md:text-base",children:"Administra los logos que aparecen en el carrusel del sitio"})]})]}),e.jsxs(Ee,{className:"mb-6",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx(Pe,{children:"Especificaciones para Logos"}),e.jsxs(Se,{className:"space-y-1 text-sm",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Formato:"})," PNG (preferido con fondo transparente), JPG, WEBP o SVG"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Dimensiones:"})," 400x400 píxeles (relación 1:1 cuadrada)"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Resolución:"})," 144 DPI mínimo para calidad óptima"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Tamaño máximo:"})," 500 KB"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Colores:"})," Logo en colores originales (se aplicará efecto grayscale automáticamente con color en hover)"]})]})]}),e.jsxs(me,{children:[e.jsx(xe,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between sm:items-center gap-3",children:[e.jsxs("div",{children:[e.jsxs(he,{children:["Patrocinadores (",n.length,")"]}),e.jsxs(ue,{children:[n.filter(a=>a.is_active).length," activos en el carrusel"]})]}),e.jsxs(we,{open:ie,onOpenChange:I,children:[e.jsx(be,{asChild:!0,children:e.jsxs(t,{className:"w-full sm:w-auto",children:[e.jsx(Le,{className:"w-4 h-4 mr-2"}),"Agregar Patrocinador"]})}),e.jsxs(Ne,{className:"max-w-md w-[95vw]",children:[e.jsxs(_e,{children:[e.jsx(ye,{children:i?"Editar Patrocinador":"Nuevo Patrocinador"}),e.jsx(Ce,{children:i?"Actualiza la información del patrocinador":"Completa los datos del nuevo patrocinador"})]}),e.jsxs("form",{onSubmit:oe,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{htmlFor:"name",children:"Nombre del Patrocinador *"}),e.jsx(A,{id:"name",value:r.name,onChange:a=>h({...r,name:a.target.value}),placeholder:"Ej: Empresa XYZ",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(v,{htmlFor:"logo",children:["Logo ",i?"(opcional para actualizar)":"*"]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(A,{id:"logo",type:"file",accept:"image/png,image/jpeg,image/jpg,image/webp,image/svg+xml",onChange:te}),S&&e.jsx("div",{className:"flex justify-center p-4 bg-muted rounded-lg",children:e.jsx("img",{src:S,alt:"Preview",className:"max-h-32 max-w-full object-contain"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{htmlFor:"website",children:"Sitio Web (opcional)"}),e.jsx(A,{id:"website",type:"url",value:r.website_url,onChange:a=>h({...r,website_url:a.target.value}),placeholder:"https://ejemplo.com"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(v,{htmlFor:"active",children:"Visible en carrusel"}),e.jsx(je,{id:"active",checked:r.is_active,onCheckedChange:a=>h({...r,is_active:a})})]}),e.jsxs(Ae,{className:"flex-col sm:flex-row gap-2",children:[e.jsx(t,{type:"button",variant:"outline",onClick:()=>I(!1),disabled:_,children:"Cancelar"}),e.jsxs(t,{type:"submit",disabled:_,children:[_&&e.jsx(q,{className:"w-4 h-4 mr-2 animate-spin"}),i?"Actualizar":"Agregar"]})]})]})]})]})]})}),e.jsx(ge,{children:n.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ze,{className:"w-12 h-12 mx-auto text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"No hay patrocinadores registrados"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"md:hidden space-y-3",children:n.map((a,s)=>e.jsxs("div",{className:"border rounded-lg p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:a.logo_url,alt:a.name,className:"w-12 h-12 object-contain shrink-0 rounded"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium text-sm break-words",children:a.name}),a.website_url?e.jsxs("a",{href:a.website_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-xs text-primary hover:underline",children:["Ver sitio ",e.jsx(Y,{className:"w-3 h-3"})]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"Sin sitio web"})]}),e.jsx(De,{variant:a.is_active?"default":"secondary",className:"shrink-0 text-xs",children:a.is_active?"Activo":"Inactivo"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx(t,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>f(a,"up"),disabled:s===0,children:e.jsx(B,{className:"w-4 h-4"})}),e.jsx(t,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>f(a,"down"),disabled:s===n.length-1,children:e.jsx(Z,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(t,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>z(a),children:a.is_active?"Desactivar":"Activar"}),e.jsx(t,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>T(a),children:e.jsx(Q,{className:"w-3.5 h-3.5"})}),e.jsxs(O,{children:[e.jsx(U,{asChild:!0,children:e.jsx(t,{variant:"destructive",size:"icon",className:"h-8 w-8",children:e.jsx(ee,{className:"w-3.5 h-3.5"})})}),e.jsxs(V,{className:"w-[95vw] max-w-md",children:[e.jsxs(W,{children:[e.jsx($,{children:"¿Eliminar patrocinador?"}),e.jsxs(J,{children:['Esta acción no se puede deshacer. Se eliminará permanentemente el patrocinador "',a.name,'" y su logo.']})]}),e.jsxs(K,{children:[e.jsx(M,{children:"Cancelar"}),e.jsx(X,{onClick:()=>L(a),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Eliminar"})]})]})]})]})]})]},a.id))}),e.jsx("div",{className:"hidden md:block overflow-x-auto",children:e.jsxs(pe,{children:[e.jsx(fe,{children:e.jsxs(R,{children:[e.jsx(u,{children:"Logo"}),e.jsx(u,{children:"Nombre"}),e.jsx(u,{children:"Sitio Web"}),e.jsx(u,{children:"Estado"}),e.jsx(u,{children:"Orden"}),e.jsx(u,{className:"text-right",children:"Acciones"})]})}),e.jsx(ve,{children:n.map((a,s)=>e.jsxs(R,{children:[e.jsx(g,{children:e.jsx("img",{src:a.logo_url,alt:a.name,className:"w-12 h-12 object-contain"})}),e.jsx(g,{className:"font-medium",children:a.name}),e.jsx(g,{children:a.website_url?e.jsxs("a",{href:a.website_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-primary hover:underline",children:["Ver sitio",e.jsx(Y,{className:"w-3 h-3"})]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(g,{children:e.jsx(t,{variant:a.is_active?"default":"secondary",size:"sm",onClick:()=>z(a),children:a.is_active?"Activo":"Inactivo"})}),e.jsx(g,{children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(t,{variant:"ghost",size:"icon",onClick:()=>f(a,"up"),disabled:s===0,children:e.jsx(B,{className:"w-4 h-4"})}),e.jsx(t,{variant:"ghost",size:"icon",onClick:()=>f(a,"down"),disabled:s===n.length-1,children:e.jsx(Z,{className:"w-4 h-4"})})]})}),e.jsx(g,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(t,{variant:"outline",size:"icon",onClick:()=>T(a),children:e.jsx(Q,{className:"w-4 h-4"})}),e.jsxs(O,{children:[e.jsx(U,{asChild:!0,children:e.jsx(t,{variant:"destructive",size:"icon",children:e.jsx(ee,{className:"w-4 h-4"})})}),e.jsxs(V,{children:[e.jsxs(W,{children:[e.jsx($,{children:"¿Eliminar patrocinador?"}),e.jsxs(J,{children:['Esta acción no se puede deshacer. Se eliminará permanentemente el patrocinador "',a.name,'" y su logo.']})]}),e.jsxs(K,{children:[e.jsx(M,{children:"Cancelar"}),e.jsx(X,{onClick:()=>L(a),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Eliminar"})]})]})]})]})})]},a.id))})]})})]})})]})]})}),e.jsx(H,{})]})};export{da 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.