PageSourceSearch

https://app.backstagebaton.com/app/assets/UsersPage-D5iHKLR5.js

js backstagebaton.com collected 2026-10-07 08:50:35 UTC 9,168 bytes, 1 lines download raw bytes

1import{v as y,O,r as u,j as e,B as d,S as N,a4 as p,d as D,M as C}from"./index-_aijvlUq.js";import{P as M}from"./PageHeader-DCofr6qo.js";import{I as j}from"./Input-ysTyZFq5.js";import{b as B,c as _,T as b,d as P,e as q,a as h}from"./Table-Yng-lqpt.js";import{B as F}from"./Badge-DJIi163x.js";const f={list(l={}){const r=Object.fromEntries(Object.entries(l).filter(([,s])=>s!==""&&s!=null));return y.get("/users",{params:r})},getById(l){return y.get(`/users/${l}`)},create(l){return y.post("/users",l)},update(l,r){return y.put(`/users/${l}`,r)},resetPassword(l,r){return y.post(`/users/${l}/reset-password`,{password:r})}},z=O((l,r)=>({users:[],pagination:{page:1,limit:20,total:0,totalPages:1},filters:{search:"",role:"",isActive:"",sortBy:"displayName",sortDir:"asc"},isLoading:!1,error:null,setFilters:s=>l({filters:{...r().filters,...s}}),fetchUsers:async(s={})=>{l({isLoading:!0,error:null});try{const t={...r().filters,page:r().pagination.page,...s},i=await f.list(t);l({users:i.users,pagination:i.pagination,isLoading:!1})}catch(t){l({error:t.message,isLoading:!1})}},createUser:async s=>{const t=await f.create(s);return await r().fetchUsers(),t},updateUser:async(s,t)=>{const i=await f.update(s,t);return l(n=>({users:n.users.map(m=>m.id===s?i:m)})),i},resetPassword:async(s,t)=>{await f.resetPassword(s,t)}})),E=[{value:p.SUPERADMIN,label:"Superadmin"},{value:p.PRESIDENT,label:"President"},{value:p.VICE_PRESIDENT,label:"Vice President"},{value:p.MUSIC_DIRECTOR,label:"Music Director"},{value:p.BAND_MANAGER,label:"Band Manager"},{value:p.LIBRARIAN,label:"Librarian"},{value:p.SECTION_LEADER,label:"Section Leader"},{value:p.MEMBER,label:"Member"}],$=[{value:"",label:"All Roles"},...E],H=[{value:"",label:"All Statuses"},{value:"true",label:"Active"},{value:"false",label:"Inactive"}],V=[{key:"email",label:"Email"},{key:"displayName",label:"Display Name"},{key:"memberName",label:"Linked Member"},{key:"role",label:"Role"},{key:"lastLoginAt",label:"Last Login"},{key:"isActive",label:"Status"}];function G({label:l,sortKey:r,currentSort:s,currentDir:t,onSort:i}){const n=s===r;return e.jsx(P,{className:"cursor-pointer select-none hover:text-gray-700 group",onClick:()=>i(r,n&&t==="asc"?"desc":"asc"),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[l,e.jsx("span",{className:`text-xs ${n?"text-band-600":"text-gray-300 group-hover:text-gray-400"}`,children:n?t==="asc"?"▲":"▼":"▲"})]})})}function ae(){const{users:l,pagination:r,filters:s,isLoading:t,fetchUsers:i,setFilters:n,createUser:m,updateUser:x,resetPassword:g}=z(),[o,c]=u.useState(!1),[v,S]=u.useState(null),[w,A]=u.useState(null);u.useEffect(()=>{i()},[]);function L(a){n({search:a.target.value}),i({search:a.target.value,page:1})}function U(a){n({role:a.target.value}),i({role:a.target.value,page:1})}function I(a){n({isActive:a.target.value}),i({isActive:a.target.value,page:1})}function T(a,R){n({sortBy:a,sortDir:R}),i({sortBy:a,sortDir:R,page:1})}async function k(a){await x(a.id,{isActive:!a.isActive})}return e.jsxs("div",{className:"px-4 md:px-0",children:[e.jsx(M,{title:"User Accounts",subtitle:"Manage login credentials and roles for members",breadcrumbs:[{label:"Home",to:"/"},{label:"Settings"},{label:"Users"}],actions:e.jsx(d,{onClick:()=>c(!0),children:"New user"})}),e.jsxs("div",{className:"flex flex-wrap gap-3 mb-4",children:[e.jsx("div",{className:"w-64",children:e.jsx(j,{placeholder:"Search by name or email...",value:s.search,onChange:L})}),e.jsx("div",{className:"w-44",children:e.jsx(N,{options:$,value:s.role,onChange:U})}),e.jsx("div",{className:"w-44",children:e.jsx(N,{options:H,value:s.isActive,onChange:I})}),(s.search||s.role||s.isActive)&&e.jsx(d,{variant:"ghost",size:"sm",onClick:()=>{n({search:"",role:"",isActive:""}),i({search:"",role:"",isActive:"",page:1})},children:"Clear filters"})]}),e.jsxs(B,{children:[e.jsx(_,{children:e.jsxs(b,{children:[V.map(a=>e.jsx(G,{label:a.label,sortKey:a.key,currentSort:s.sortBy,currentDir:s.sortDir,onSort:T},a.key)),e.jsx(P,{className:"text-right",children:"Actions"})]})}),e.jsxs(q,{children:[t&&e.jsx(b,{children:e.jsx(h,{colSpan:7,className:"text-center text-gray-400 py-8",children:"Loading..."})}),!t&&l.length===0&&e.jsx(b,{children:e.jsx(h,{colSpan:7,className:"text-center text-gray-400 py-8",children:"No users found"})}),!t&&l.map(a=>e.jsxs(b,{children:[e.jsx(h,{className:"font-medium",children:a.email}),e.jsx(h,{children:a.displayName}),e.jsx(h,{className:"text-gray-500",children:a.memberName||"—"}),e.jsx(h,{children:e.jsx(F,{color:a.role===p.SUPERADMIN?"purple":a.role===p.PRESIDENT?"blue":"gray",children:a.role?.replace("_"," ")})}),e.jsx(h,{className:"text-gray-500 text-sm",children:a.lastLoginAt?D(a.lastLoginAt):"Never"}),e.jsx(h,{children:e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs font-medium ${a.isActive?"text-green-700":"text-red-600"}`,children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${a.isActive?"bg-green-500":"bg-red-400"}`}),a.isActive?"Active":"Inactive"]})}),e.jsx(h,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(d,{variant:"ghost",size:"sm",onClick:()=>S(a),children:"Edit"}),e.jsx(d,{variant:"ghost",size:"sm",onClick:()=>A(a),children:"Reset PW"}),e.jsx(d,{variant:"ghost",size:"sm",onClick:()=>k(a),children:a.isActive?"Deactivate":"Activate"})]})})]},a.id))]})]}),r.totalPages>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4 text-sm text-gray-600",children:[e.jsxs("span",{children:["Page ",r.page," of ",r.totalPages," (",r.total," users)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(d,{variant:"secondary",size:"sm",disabled:r.page<=1,onClick:()=>i({page:r.page-1}),children:"Previous"}),e.jsx(d,{variant:"secondary",size:"sm",disabled:r.page>=r.totalPages,onClick:()=>i({page:r.page+1}),children:"Next"})]})]}),o&&e.jsx(W,{onClose:()=>c(!1),onCreate:async a=>
1{await m(a),c(!1)}}),v&&e.jsx(J,{user:v,onClose:()=>S(null),onSave:async a=>{await x(v.id,a),S(null)}}),w&&e.jsx(K,{user:w,onClose:()=>A(null),onReset:async a=>{await g(w.id,a),A(null)}})]})}function W({onClose:l,onCreate:r}){const[s,t]=u.useState({email:"",displayName:"",password:"",role:"member"}),[i,n]=u.useState(null),[m,x]=u.useState(!1);async function g(o){o.preventDefault(),x(!0),n(null);try{await r(s)}catch(c){n(c.message),x(!1)}}return e.jsx(C,{isOpen:!0,onClose:l,title:"Create User",children:e.jsxs("form",{onSubmit:g,className:"space-y-4",children:[i&&e.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-700",children:i}),e.jsx(j,{label:"Email",type:"email",required:!0,value:s.email,onChange:o=>t({...s,email:o.target.value})}),e.jsx(j,{label:"Display Name",required:!0,value:s.displayName,onChange:o=>t({...s,displayName:o.target.value})}),e.jsx(j,{label:"Password",type:"password",required:!0,minLength:8,value:s.password,onChange:o=>t({...s,password:o.target.value})}),e.jsx(N,{label:"Role",options:E,value:s.role,onChange:o=>t({...s,role:o.target.value})}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(d,{variant:"secondary",type:"button",onClick:l,children:"Cancel"}),e.jsx(d,{type:"submit",isLoading:m,children:"Create"})]})]})})}function J({user:l,onClose:r,onSave:s}){const[t,i]=u.useState({displayName:l.displayName,email:l.email,role:l.role}),[n,m]=u.useState(null),[x,g]=u.useState(!1);async function o(c){c.preventDefault(),g(!0),m(null);try{await s(t)}catch(v){m(v.message),g(!1)}}return e.jsx(C,{isOpen:!0,onClose:r,title:"Edit User",children:e.jsxs("form",{onSubmit:o,className:"space-y-4",children:[n&&e.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-700",children:n}),e.jsx(j,{label:"Email",type:"email",required:!0,value:t.email,onChange:c=>i({...t,email:c.target.value})}),e.jsx(j,{label:"Display Name",required:!0,value:t.displayName,onChange:c=>i({...t,displayName:c.target.value})}),e.jsx(N,{label:"Role",options:E,value:t.role,onChange:c=>i({...t,role:c.target.value})}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(d,{variant:"secondary",type:"button",onClick:r,children:"Cancel"}),e.jsx(d,{type:"submit",isLoading:x,children:"Save changes"})]})]})})}function K({user:l,onClose:r,onReset:s}){const[t,i]=u.useState(""),[n,m]=u.useState(null),[x,g]=u.useState(!1);async function o(c){c.preventDefault(),g(!0),m(null);try{await s(t)}catch(v){m(v.message),g(!1)}}return e.jsx(C,{isOpen:!0,onClose:r,title:"Reset Password",children:e.jsxs("form",{onSubmit:o,className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-gray-600",children:["Reset password for ",e.jsx("strong",{children:l.displayName})," (",l.email,")"]}),n&&e.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-700",children:n}),e.jsx(j,{label:"New Password",type:"password",required:!0,minLength:8,value:t,onChange:c=>i(c.target.value)}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(d,{variant:"secondary",type:"button",onClick:r,children:"Cancel"}),e.jsx(d,{type:"submit",isLoading:x,children:"Reset password"})]})]})})}export{ae as UsersPage};

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.