1 line
8.7 KiB
JavaScript
1 line
8.7 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,6655,e=>{"use strict";let t=e.i(47167).default.env.NEXT_PUBLIC_API_URL??"/admin/api/v1";e.s(["ADMIN_API_BASE",0,t])},72661,e=>{"use strict";var t=e.i(43476),s=e.i(71645),i=e.i(6655);let n=["SUPER_ADMIN","ADMIN","SUPPORT","FINANCE","VIEWER"],a={firstName:"",lastName:"",email:"",password:"",role:"SUPPORT",isActive:!0};e.s(["default",0,function(){let[e,l]=(0,s.useState)([]),[c,r]=(0,s.useState)(!0),[d,x]=(0,s.useState)(null),[o,m]=(0,s.useState)(!1),[u,p]=(0,s.useState)(null),[h,f]=(0,s.useState)(a),[b,N]=(0,s.useState)(!1);async function g(){try{let e=await fetch(`${i.ADMIN_API_BASE}/admin/admins`,{cache:"no-store",credentials:"include"}),t=await e.json();if(!e.ok)throw Error(t?.message??"Failed");l(t.data??[])}catch(e){x(e.message)}finally{r(!1)}}function j(){m(!1),p(null),f(a)}async function v(e){e.preventDefault(),N(!0),x(null);try{let e=!!u,t={firstName:h.firstName,lastName:h.lastName,email:h.email,role:h.role,isActive:h.isActive,...h.password?{password:h.password}:{}},s=await fetch(`${i.ADMIN_API_BASE}/admin/admins${u?`/${u}`:""}`,{method:e?"PATCH":"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)}),n=await s.json();if(!s.ok)throw Error(n?.message??`Failed to ${e?"update":"create"} admin`);j(),await g()}catch(e){x(e.message)}finally{N(!1)}}(0,s.useEffect)(()=>{g()},[]);let z={SUPER_ADMIN:"text-emerald-400 bg-emerald-950/40",ADMIN:"text-sky-400 bg-sky-950/40",SUPPORT:"text-orange-400 bg-orange-950/40",FINANCE:"text-violet-400 bg-violet-950/40",VIEWER:"text-zinc-400 bg-zinc-800"};return(0,t.jsxs)("div",{className:"shell py-8 space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-xs uppercase tracking-[0.2em] text-emerald-400",children:"Platform"}),(0,t.jsx)("h1",{className:"mt-1 text-3xl font-black",children:"Admin Users"})]}),(0,t.jsx)("button",{onClick:function(){p(null),f(a),x(null),m(!0)},className:"px-4 py-2 rounded-xl bg-emerald-700 hover:bg-emerald-600 text-white text-sm font-semibold transition-colors",children:"+ New admin"})]}),d&&(0,t.jsx)("div",{className:"panel p-4 text-sm text-red-400",children:d}),(0,t.jsx)("div",{className:"panel overflow-hidden",children:(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)("table",{className:"w-full text-sm",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{className:"border-b border-zinc-800",children:[(0,t.jsx)("th",{className:"text-left px-6 py-3 text-xs font-medium text-zinc-500 uppercase tracking-wider",children:"Name"}),(0,t.jsx)("th",{className:"text-left px-6 py-3 text-xs font-medium text-zinc-500 uppercase tracking-wider",children:"Email"}),(0,t.jsx)("th",{className:"text-left px-6 py-3 text-xs font-medium text-zinc-500 uppercase tracking-wider",children:"Role"}),(0,t.jsx)("th",{className:"text-left px-6 py-3 text-xs font-medium text-zinc-500 uppercase tracking-wider",children:"Permissions"}),(0,t.jsx)("th",{className:"text-left px-6 py-3 text-xs font-medium text-zinc-500 uppercase tracking-wider",children:"Status"}),(0,t.jsx)("th",{className:"text-left px-6 py-3 text-xs font-medium text-zinc-500 uppercase tracking-wider",children:"Joined"}),(0,t.jsx)("th",{className:"text-left px-6 py-3 text-xs font-medium text-zinc-500 uppercase tracking-wider",children:"Actions"})]})}),(0,t.jsx)("tbody",{className:"divide-y divide-zinc-800/60",children:c?(0,t.jsx)("tr",{children:(0,t.jsx)("td",{colSpan:7,className:"px-6 py-12 text-center text-zinc-500",children:"Loading…"})}):0===e.length?(0,t.jsx)("tr",{children:(0,t.jsx)("td",{colSpan:7,className:"px-6 py-12 text-center text-zinc-500",children:"No admin users found"})}):e.map(e=>(0,t.jsxs)("tr",{className:"hover:bg-zinc-800/30 transition-colors",children:[(0,t.jsxs)("td",{className:"px-6 py-4 font-medium text-zinc-100",children:[e.firstName," ",e.lastName]}),(0,t.jsx)("td",{className:"px-6 py-4 text-zinc-400",children:e.email}),(0,t.jsx)("td",{className:"px-6 py-4",children:(0,t.jsx)("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${z[e.role]??"text-zinc-400 bg-zinc-800"}`,children:e.role})}),(0,t.jsx)("td",{className:"px-6 py-4 text-xs text-zinc-500",children:e.permissions&&e.permissions.length>0?e.permissions.map(e=>e.resource).join(", "):"Role-based only"}),(0,t.jsx)("td",{className:"px-6 py-4",children:(0,t.jsx)("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.isActive?"text-emerald-400 bg-emerald-950/40":"text-zinc-500 bg-zinc-800"}`,children:e.isActive?"Active":"Inactive"})}),(0,t.jsx)("td",{className:"px-6 py-4 text-zinc-500 text-xs",children:new Date(e.createdAt).toLocaleDateString()}),(0,t.jsx)("td",{className:"px-6 py-4",children:(0,t.jsx)("button",{type:"button",onClick:()=>{p(e.id),f({firstName:e.firstName,lastName:e.lastName,email:e.email,password:"",role:e.role,isActive:e.isActive}),x(null),m(!0)},className:"rounded-lg border border-zinc-700 px-3 py-1.5 text-xs font-medium text-zinc-300 transition-colors hover:border-zinc-500 hover:text-white",children:"Edit"})})]},e.id))})]})})}),o&&(0,t.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[#07101e]/60 backdrop-blur-sm",children:(0,t.jsxs)("div",{className:"w-full max-w-md rounded-2xl border border-zinc-700 bg-zinc-900 p-8 shadow-2xl",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold",children:u?"Edit admin user":"New admin user"}),(0,t.jsx)("button",{onClick:j,className:"text-zinc-500 hover:text-zinc-200",children:"✕"})]}),(0,t.jsxs)("form",{onSubmit:v,className:"space-y-4",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-xs font-medium text-zinc-400 mb-1",children:"First name"}),(0,t.jsx)("input",{required:!0,className:"w-full px-3 py-2 rounded-xl bg-zinc-800 border border-zinc-700 text-zinc-100 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500",value:h.firstName,onChange:e=>f({...h,firstName:e.target.value})})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-xs font-medium text-zinc-400 mb-1",children:"Last name"}),(0,t.jsx)("input",{required:!0,className:"w-full px-3 py-2 rounded-xl bg-zinc-800 border border-zinc-700 text-zinc-100 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500",value:h.lastName,onChange:e=>f({...h,lastName:e.target.value})})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-xs font-medium text-zinc-400 mb-1",children:"Email"}),(0,t.jsx)("input",{type:"email",required:!0,className:"w-full px-3 py-2 rounded-xl bg-zinc-800 border border-zinc-700 text-zinc-100 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500",value:h.email,onChange:e=>f({...h,email:e.target.value})})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("label",{className:"block text-xs font-medium text-zinc-400 mb-1",children:["Password ",u?(0,t.jsx)("span",{className:"text-zinc-500",children:"(leave blank to keep current)"}):null]}),(0,t.jsx)("input",{type:"password",required:!u,minLength:u?void 0:8,className:"w-full px-3 py-2 rounded-xl bg-zinc-800 border border-zinc-700 text-zinc-100 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500",value:h.password,onChange:e=>f({...h,password:e.target.value})})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-xs font-medium text-zinc-400 mb-1",children:"Role"}),(0,t.jsx)("select",{className:"w-full px-3 py-2 rounded-xl bg-zinc-800 border border-zinc-700 text-zinc-100 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500",value:h.role,onChange:e=>f({...h,role:e.target.value}),children:n.map(e=>(0,t.jsx)("option",{value:e,children:e},e))})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-xs font-medium text-zinc-400 mb-1",children:"Status"}),(0,t.jsxs)("select",{className:"w-full px-3 py-2 rounded-xl bg-zinc-800 border border-zinc-700 text-zinc-100 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500",value:h.isActive?"active":"inactive",onChange:e=>f({...h,isActive:"active"===e.target.value}),children:[(0,t.jsx)("option",{value:"active",children:"Active"}),(0,t.jsx)("option",{value:"inactive",children:"Inactive"})]})]}),(0,t.jsxs)("div",{className:"flex gap-3 pt-2",children:[(0,t.jsx)("button",{type:"button",onClick:j,className:"flex-1 py-2.5 rounded-xl bg-zinc-800 text-zinc-300 text-sm font-medium",children:"Cancel"}),(0,t.jsx)("button",{type:"submit",disabled:b,className:"flex-1 py-2.5 rounded-xl bg-emerald-700 hover:bg-emerald-600 text-white text-sm font-semibold disabled:opacity-50",children:b?u?"Saving…":"Creating…":u?"Save changes":"Create admin"})]})]})]})})]})}])}]); |