PageSourceSearch

https://unbserved.com/assets/AdminBadgesPage-3_BgqynM.js

js unbserved.com collected 2026-09-24 14:56:59 UTC 13,887 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-ui-BeVD6iDL.js";import{a as u}from"./vendor-react-Dmhbt9i7.js";import{a as he,cN as ue,dh as pe,di as je,dj as ve,dk as fe,dl as Ne,dm as Ce,dn as be,br as ye,n as we,U as j,ap as k,Y as r,b2 as _e,aM as W,K as M,M as E,O as T,Q as O,cb as R,R as o,aq as Se,ad as F,W as G,r as X,bE as Be,b0 as Q,bq as Y,a0 as Ae,E as ke,T as Fe,bs as De}from"./index-cXBC_5Uy.js";import{U as ze}from"./UserBadgeAssigner-fTxdPGkL.js";import{C as H,b as J,c as Z,d as ee,a as V}from"./card-BAupyZPp.js";import{B as se}from"./badge-CuxBpOEs.js";import{A as Ie,a as Pe,b as Ue}from"./avatar-Bosk_0-q.js";import{S as Le,a as Me,b as Ee,c as Te,d as b}from"./select-B04HanS_.js";import{u as Oe,a as $,s as Re,K as Ge,P as He,D as Ve,c as Ke,S as qe,v as We,d as Xe,b as Qe,C as Ye}from"./sortable.esm-BxS_f5uj.js";import{A as $e}from"./AdminPageShell-B5XdvC8l.js";import{h as Je}from"./Medal-Buoj5RD0.js";import"./vendor-query-vEtoV3ax.js";import"./vendor-motion-CENv1AvF.js";import"./checkbox-BSwclyKP.js";import"./index-DkQrjkUl.js";import"./index-BdQq_4o_.js";import"./BackIcon-B0Ptl-7G.js";function Ze({badge:n,userCount:l,onEdit:D,onToggleActive:z,onDelete:v,onBulkAssign:c}){const{attributes:f,listeners:N,setNodeRef:I,transform:P,transition:m,isDragging:x}=Qe({id:n.id}),y={transform:Ye.Transform.toString(P),transition:m,opacity:x?.5:1},C={sm:"S",md:"M",lg:"L",xl:"XL","2xl":"2XL"};return e.jsx("div",{ref:I,style:y,children:e.jsxs(H,{className:n.is_active?"":"opacity-60",children:[e.jsx(J,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{...f,...N,className:"cursor-grab active:cursor-grabbing p-1 -ml-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(Be,{className:"w-4 h-4"})}),e.jsx("div",{className:"w-12 h-12 rounded-lg bg-muted flex items-center justify-center [&_svg]:w-8 [&_svg]:h-8",style:{color:"#F0FF00"},dangerouslySetInnerHTML:{__html:F(n.svg_content)}}),e.jsxs("div",{children:[e.jsx(Z,{className:"text-lg",children:n.name}),e.jsxs(ee,{className:"text-xs flex items-center gap-2",children:["/",n.slug,e.jsx("span",{className:"bg-muted px-1.5 py-0.5 rounded text-[10px] font-medium",children:C[n.display_size]||"M"})]})]})]}),!n.is_active&&e.jsx(se,{variant:"secondary",children:"Inativos"})]})}),e.jsxs(V,{children:[n.description&&e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:n.description}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground mb-4",children:[e.jsx(Q,{className:"w-4 h-4"}),e.jsxs("span",{children:[l," users"]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(r,{variant:"outline",size:"sm",onClick:D,children:[e.jsx(Y,{className:"w-3 h-3 mr-1"}),"Edit"]}),e.jsx(r,{variant:"outline",size:"sm",onClick:z,children:n.is_active?e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"w-3 h-3 mr-1"}),"Disable"]}):e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"w-3 h-3 mr-1"}),"Enable"]})}),e.jsx(r,{variant:"outline",size:"sm",onClick:v,className:"text-destructive hover:text-destructive",children:e.jsx(Fe,{className:"w-3 h-3"})})]}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-border space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground font-medium mb-2",children:"Bulk Assign:"}),e.jsxs("div",{className:"flex gap-2",children:[n.slug==="blog-writer"?e.jsxs(r,{variant:"secondary",size:"sm",className:"flex-1 text-xs",onClick:()=>c("writers"),children:[e.jsx(Y,{className:"w-3 h-3 mr-1"}),"All Writers"]}):e.jsxs(r,{variant:"secondary",size:"sm",className:"flex-1 text-xs",onClick:()=>c("all"),children:[e.jsx(Q,{className:"w-3 h-3 mr-1"}),"All Users"]}),e.jsxs(r,{variant:"secondary",size:"sm",className:"flex-1 text-xs",onClick:()=>c("premium"),children:[e.jsx(De,{className:"w-3 h-3 mr-1"}),"PRO Users"]})]})]})]})]})})}function js(){const{user:n}=he(),{data:l,isLoading:D}=ue(),{data:z}=pe(),v=je(),c=ve(),f=fe(),N=Ne(),I=Ce(),[P,m]=u.useState(!1),[x,y]=u.useState(null),[C,w]=u.useState(null),[g,_]=u.useState(null),[U,K]=u.useState(""),[i,S]=u.useState(null),{data:L,isLoading:ae}=be(U),[t,d]=u.useState({name:"",slug:"",description:"",svg_content:"",tooltip:"",sort_order:0,display_size:"md"}),te=Oe($(He),$(Ge,{coordinateGetter:Re})),q=()=>{y(null),d({name:"",slug:"",description:"",svg_content:"",tooltip:"",sort_order:(l?.length||0)+1,display_size:"md"}),m(!0)},re=s=>{y(s),d({name:s.name,slug:s.slug,description:s.description||"",svg_content:s.svg_content,tooltip:s.tooltip||"",sort_order:s.sort_order,display_size:s.display_size||"md"}),m(!0)},ne=async()=>
1{if(!t.name||!t.svg_content){X.error("Name and SVG content are required");return}const s=(t.slug.trim()||t.name).toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"");try{x?await c.mutateAsync({id:x.id,...t,slug:s}):await v.mutateAsync({...t,slug:s}),m(!1)}catch{}},le=async()=>{if(C)try{await f.mutateAsync(C),w(null)}catch{}},ie=async s=>{await c.mutateAsync({id:s.id,is_active:!s.is_active})},de=s=>{const a=s.target.files?.[0];if(!a)return;if(!a.name.endsWith(".svg")){X.error("Please upload an SVG file");return}const p=new FileReader;p.onload=B=>{const A=B.target?.result;d(h=>({...h,svg_content:A}))},p.readAsText(a)},oe=async()=>{g&&(await N.mutateAsync({badgeId:g.badgeId,target:g.target,grantedBy:n?.id}),_(null))},ce=s=>z?.find(a=>a.id===s)?.user_count||0,me=s=>{S({id:s.id,name:s.display_name||s.username||s.email}),K("")},xe=s=>{const{active:a,over:p}=s;if(p&&a.id!==p.id&&l){const B=l.findIndex(h=>h.id===a.id),A=l.findIndex(h=>h.id===p.id);if(B!==-1&&A!==-1){const h=Xe(l,B,A);I.mutate(h.map(ge=>ge.id))}}};return e.jsxs($e,{title:"Badge Management",description:"Create and manage user badges",actions:e.jsxs(r,{onClick:q,children:[e.jsx(W,{className:"w-4 h-4 mr-2"}),"New Badge"]}
1),children:[e.jsxs(H,{className:"mb-8",children:[e.jsxs(J,{className:"pb-3",children:[e.jsxs(Z,{className:"text-lg flex items-center gap-2",children:[e.jsx(ye,{className:"w-5 h-5"}),"Assign Badges to User"]}),e.jsx(ee,{children:"Search for a user to manage their badges"})]}),e.jsxs(V,{children:[e.jsxs("div",{className:"flex gap-4 items-start",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsxs("div",{className:"relative",children:[e.jsx(we,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(j,{placeholder:"Search by name or email...",value:U,onChange:s=>K(s.target.value),className:"pl-10"})]}),U.length>=2&&e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-popover border border-border rounded-lg shadow-lg z-50 max-h-64 overflow-auto",children:ae?e.jsx("div",{className:"p-4 text-center text-muted-foreground",children:e.jsx(k,{className:"w-4 h-4 animate-spin mx-auto"})}):L&&L.length>0?L.map(s=>e.jsxs("button",{onClick:()=>me(s),className:"w-full flex items-center gap-3 p-3 hover:bg-muted transition-colors text-left",children:[e.jsxs(Ie,{className:"h-8 w-8",children:[e.jsx(Pe,{src:s.avatar_url||void 0}),e.jsx(Ue,{children:(s.display_name||s.username||s.email)?.[0]?.toUpperCase()})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm truncate",children:s.display_name||s.username||"No name"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.email})]}),s.is_premium&&e.jsx(se,{variant:"secondary",className:"text-xs",children:"PRO"})]},s.id)):e.jsx("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No users found"})})]}),e.jsx(r,{onClick:()=>i&&S(i),disabled:!i,children:"Manage Badges"})]}),i&&e.jsxs("div",{className:"mt-4 p-3 bg-muted/50 rounded-lg flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Selected:"}),e.jsx("span",{className:"font-medium",children:i.name})]}),e.jsx(r,{size:"sm",onClick:()=>S(i),children:"Open Badge Manager"})]})]})]}),D?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[...Array(3)].map((s,a)=>e.jsx(_e,{className:"h-48"},a))}):l&&l.length>0?e.jsx(Ve,{sensors:te,collisionDetection:Ke,onDragEnd:xe,children:e.jsx(qe,{items:l.map(s=>s.id),strategy:We,children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:l.map(s=>e.jsx(Ze,{badge:s,userCount:ce(s.id),onEdit:()=>re(s),onToggleActive:()=>ie(s),onDelete:()=>w(s.id),onBulkAssign:a=>_({badgeId:s.id,badgeName:s.name,target:a})},s.id))})})}):e.jsx(H,{children:e.jsxs(V,{className:"flex flex-col items-center justify-center py-16",children:[e.jsx(Je,{className:"w-12 h-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"Nenhum badge ainda"}),e.jsx("p",{className:"text-muted-foreground text-sm mb-4",children:"Create your first badge to get started"}),e.jsxs(r,{onClick:q,children:[e.jsx(W,{className:"w-4 h-4 mr-2"}),"Create Badge"]})]})}),e.jsx(M,{open:P,onOpenChange:m,children:e.jsxs(E,{className:"max-w-lg",children:[e.jsxs(T,{children:[e.jsx(O,{children:x?"Edit Badge":"Create Badge"}),e.jsx(R,{children:x?"Update badge details and appearance":"Create a new badge that can be assigned to users"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(o,{htmlFor:"name",children:"Name *"}),e.jsx(j,{id:"name",value:t.name,onChange:s=>d(a=>({...a,name:s.target.value})),placeholder:"e.g., PRO Crown"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"slug",children:"Slug (auto-generated if empty)"}),e.jsx(j,{id:"slug",value:t.slug,onChange:s=>d(a=>({...a,slug:s.target.value})),placeholder:"e.g., pro-crown"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"tooltip",children:"Tooltip"}),e.jsx(j,{id:"tooltip",value:t.tooltip,onChange:s=>d(a=>({...a,tooltip:s.target.value})),placeholder:"Text shown on hover"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"description",children:"Descrição"}),e.jsx(j,{id:"description",value:t.description,onChange:s=>d(a=>({...a,description:s.target.value})),placeholder:"Internal description"})]}),e.jsxs("div",{children:[e.jsx(o,{children:"SVG Content *"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("textarea",{className:"w-full h-32 p-3 text-sm font-mono border border-border rounded-lg bg-background resize-none",value:t.svg_content,onChange:s=>d(a=>({...a,svg_content:s.target.value})),placeholder:"<svg ...>...</svg>"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(o,{htmlFor:"svg-upload",className:"flex items-center gap-2 px-3 py-2 text-sm border border-border rounded-lg cursor-pointer hover:bg-muted transition-colors",children:[e.jsx(Se,{className:"w-4 h-4"}),"Upload SVG"]}),e.jsx("input",{id:"svg-upload",type:"file",accept:".svg",className:"hidden",onChange:de})]})]})]}),t.svg_content&&e.jsxs("div",{children:[e.jsx(o,{children:"Preview"}),e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-muted rounded-lg",children:[e.jsx("div",{className:"w-8 h-8 overflow-hidden [&_svg]:w-full [&_svg]:h-full",style:{color:"#F0FF00"},dangerouslySetInnerHTML:{__html:F(t.svg_content)}}),e.jsx("div",{className:"w-6 h-6 overflow-hidden [&_svg]:w-full [&_svg]:h-full",style:{color:"#F0FF00"},dangerouslySetInnerHTML:{__html:F(t.svg_content)}}),e.jsx("div",{className:"w-4 h-4 overflow-hidden [&_svg]:w-full [&_svg]:h-full",style:{color:"#F0FF00"},dangerouslySetInnerHTML:{__html:F(t.svg_content)}}),e.jsx("span",{className:"text-sm text-muted-foreground ml-4",children:"lg / md / sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(o,{htmlFor:"display_size",children:"Display Size"}),e.jsxs(Le,{value:t.display_size,onValueChange:s=>d(a=>({...a,display_size:s})),children:[e.jsx(Me,{id:"display_size",children:e.jsx(Ee,{placeholder:"Select size"})}),e.jsxs(Te,{children:[e.jsx(b,{value:"sm",children:"Small (16px)"}),e.jsx(b,{value:"md",children:"Medium (20px)"}),e.jsx(b,{value:"lg",children:"Large (24px)"}),e.jsx(b,{value:"xl",children:"Extra Large (28px)"}),e.jsx(b,{value:"2xl",children:"2XL (32px)"})]})]})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"sort_order",children:"Sort Order"}),e.jsx(j,{id:"sort_order",type:"number",value:t.sort_order,onChange:s=>d(a=>({...a,sort_order:parseInt(s.target.value)||0}))})]})]})]}),e.jsxs(G,{children:[e.jsx(r,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),e.jsxs(r,{onClick:ne,disabled:v.isPending||c.isPending,children:[(v.isPending||c.isPending)&&e.jsx(k,{className:"w-4 h-4 mr-2 animate-spin"}),x?"Save Changes":"Create Badge"]})]})]})}),e.jsx(M,{open:!!C,onOpenChange:()=>w(null),children:e.jsxs(E,{children:[e.jsxs(T,{children:[e.jsx(O,{children:"Delete Badge"}),e.jsx(R,{children:"Are you sure you want to delete this badge? This will also remove it from all users who have it."})]}),e.jsxs(G,{children:[e.jsx(r,{variant:"outline",onClick:()=>w(null),children:"Cancel"}),e.jsxs(r,{variant:"destructive",onClick:le,disabled:f.isPending,children:[f.isPending&&e.jsx(k,{className:"w-4 h-4 mr-2 animate-spin"}),"Delete Badge"]})]})]})}),e.jsx(M,{open:!!g,onOpenChange:()=>_(null),children:e.jsxs(E,{children:[e.jsxs(T,{children:[e.jsx(O,{children:"Bulk Assign Badge"}),e.jsx(R,{children:g&&e.jsxs(e.Fragment,{children:["Assign ",e.jsxs("strong",{children:['"',g.badgeName,'"']})," to"," ",g.target==="all"?"all users":"all PRO users","?",e.jsx("br",{}),e.jsx("br",{}),"Users who already have this badge will be skipped."]})})]}),e.jsxs(G,{children:[e.jsx(r,{variant:"outline",onClick:()=>_(null),children:"Cancel"}),e.jsxs(r,{onClick:oe,disabled:N.isPending,children:[N.isPending&&e.jsx(k,{className:"w-4 h-4 mr-2 animate-spin"}),"Assign Badge"]})]})]})}),i&&e.jsx(ze,{userId:i.id,userName:i.name,isOpen:!!i,onClose:()=>S(null)})]})}export{js 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.