PageSourceSearch

https://avelin.ai/assets/users-CpS8PKR_.js

js avelin.ai collected 2026-10-05 11:50:36 UTC 6,222 bytes, 1 lines download raw bytes

1import{c as y,a as j,b as g,u as U,r as n,j as e}from"./index-sgSfjifN.js";import{A as L,a as M,P as O}from"./ProtectedRoute-q_h_0f4x.js";import{u as I}from"./useQuery-2-H2S6ou.js";import{u as F}from"./useMutation-CrXVLeTJ.js";import{u as b}from"./useServerFn-O2B3-A-s.js";import{B as p,L as f}from"./button-CT9MAbSS.js";import{I as S}from"./input-JkfPPWsM.js";import{L as P}from"./label-DmH4s5SO.js";import{A as Q,b as K,c as R,d as _,e as B,f as H,g as $,h as z}from"./alert-dialog-CWlBILag.js";import{u as G}from"./use-toast-rWNhTCit.js";import{c as J}from"./createLucideIcon-CqDAjb50.js";import{T as V}from"./trash-2-DmaSSv4f.js";import{o as W,s as T}from"./types-S6BgsT1r.js";import"./useLocation-DyITBuJ7.js";import"./AuthProvider-C3Lr1ywG.js";import"./avelin-logo-DO3lQK0C.js";import"./x-D4xGCX5L.js";import"./menu-BufiHOjS.js";import"./file-text-BPzJoX4u.js";import"./book-open-BQZZeJy8.js";import"./message-square-BZBOtmsY.js";import"./users-8nkHfPj5.js";import"./index-CafXeeuk.js";import"./index-UXMOMVcH.js";import"./ut
1ils-BQHNewu7.js";import"./index-CW0oqbKJ.js";import"./index-CZm5yeTX.js";import"./index-RbpR4YhY.js";import"./index-CqNhXQwl.js";const X=[["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:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],Y=J("user-plus",X),Z=y({method:"POST"}).middleware([j]).handler(g("392804649a7ada2fdee0597dc35f31b4c801d9f28e2d2a70c1a0ca8d817cfe5f")),ee=y({method:"POST"}).middleware([j]).handler(g("dfed4d3b7170b2a44ccdd3121c91f139b718e1f1d433960119cbc7fc6a04414f")),se=y({method:"POST"}).middleware([j]).handler(g("6825df580faeca88f7d9ef3e1218c16ef32fd7ee1ff3bd0b96717bcccd44ccfb"));function te(){const t=b(Z);return I({queryKey:["admin-users"],queryFn:async()=>{const{users:r}=await t();return r},staleTime:3e4})}function re(){const t=U(),r=b(ee);return F({mutationFn:async a=>r({data:a}),onSuccess:()=>{t.invalidateQueries({queryKey:["admin-users"]})}})}function ae(){const t=U(),r=b(se);return F({mutationFn:async a=>r({data:{userId:a}}),onSuccess:()=>{t.invalidateQueries({queryKey:["admin-users"]})}})}const ie=W({email:T().trim().email("Invalid email address").max(255),password:T().min(12,"Password must be at least 12 characters").max(200)}),ne=()=>{const{data:t,isLoading:r,refetch:a}=te(),l=re(),v=ae(),{toast:m}=G(),[u,N]=n.useState(!1),[c,w]=n.useState(""),[h,A]=n.useState(""),[C,x]=n.useState(null),[i,o]=n.useState(null),q=async s=>{s.preventDefault(),x(null);const d=ie.safeParse({email:c,password:h});if(!d.success){x(d.error.errors[0].message);return}try{await l.mutateAsync({email:c,password:h}),m({title:"Admin created",description:`${c} has been added.`}),w(""),A(""),N(!1),a()}catch(D){const k=D instanceof Error?D.message:"Failed to create admin";x(k)}},E=async()=>{if(i)try{await v.mutateAsync(i.id),m({title:"User deleted",description:`${i.email} has been removed.`}),o(null),a()}catch(s){const d=s instanceof Error?s.message:"Failed to delete user";m({title:"Error",description:d,variant:"destructive"}),o(null)}};return e.jsxs(L,{title:"User Management",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-muted-foreground",children:"Manage admin accounts."}),e.jsx(p,{onClick:()=>N(!u),children:u?"Cancel":e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4 mr-2"}),"Add Admin"]})})]}),u&&e.jsxs("form",{onSubmit:q,className:"bg-card border border-border rounded-xl p-6 space-y-4",children:[e.jsxs("h2",{className:"font-semibold flex items-center gap-2",children:[e.jsx(M,{className:"w-5 h-5"})," Create New Admin"]}),C&&e.jsx("div",{className:"text-destructive text-sm",children:C}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"email",children:"Email"}),e.jsx(S,{id:"email",type:"email",value:c,onChange:s=>w(s.target.value),placeholder:"[email protected]",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"password",children:"Temporary Password"}),e.jsx(S,{id:"password",type:"text",value:h,onChange:s=>A(s.target.value),placeholder:"At least 12 characters",required:!0})]})]}),e.jsxs(p,{type:"submit",disabled:l.isPending,children:[l.isPending&&e.jsx(f,{className:"w-4 h-4 mr-2 animate-spin"}),"Create Admin"]})]}),r?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(f,{className:"w-6 h-6 animate-spin text-primary"})}):t&&t.length>0?e.jsx("div",{className:"bg-card border border-border rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{className:"bg-secondary",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-sm font-medium",children:"Email"}),e.jsx("th",{className:"px-4 py-3 text-sm font-medium",children:"Created"}),e.jsx("th",{className:"px-4 py-3 text-sm font-medium text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:t.map(s=>e.jsxs("tr",{className:"hover:bg-secondary/50",children:[e.jsx("td",{className:"px-4 py-3",children:s.email}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:new Date(s.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx(p,{variant:"ghost",size:"icon",onClick:()=>o(s),children:e.jsx(V,{className:"w-4 h-4 text-destructive"})})})]},s.id))})]})}):e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"No users found."})]}),e.jsx(Q,{open:!!i,onOpenChange:s=>!s&&o(null),children:e.jsxs(K,{children:[e.jsxs(R,{children:[e.jsx(_,{children:"Delete User"}),e.jsxs(B,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium",children:i?.email}),"? This action cannot be undone."]})]}
1),e.jsxs(H,{children:[e.jsx($,{children:"Cancel"}),e.jsx(z,{onClick:E,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:v.isPending?e.jsx(f,{className:"w-4 h-4 animate-spin"}):"Delete"})]})]})})]})},Me=()=>e.jsx(O,{requireAdmin:!0,children:e.jsx(ne,{})});export{Me as component};

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.