1import{r as b,j as e}from"./react-vendor-QlMg5G0i.js";import{u as N,a as w,b as p}from"./query-vendor-7bKRow_J.js";import{e as C,L as D,J as R,Z as T,_ as P,$ as A,K as S,D as E,f as F,W as k,g as L,h as q,I as B,Y as M,B as l}from"./app-entry-C64IZ4Vk.js";import{B as i}from"./index-D8uw7Gn1.js";import{T as O,a as _,b as n,c as o,d as H,e as s}from"./table-Ef_bjV17.js";import{L as h}from"./label-HC6KUHtN.js";import{j}from"./fortifySecureScoreTiers-DlgAw-ZI.js";import{P as I}from"./plus-DJEuodrN.js";import{T as K}from"./trash-2-Cyp4cLN2.js";import"./index-WpFs0KKI.js";import"./router-vendor-CiP11j9Q.js";import"./helmet-vendor-BkSo4FTL.js";import"./WhiteLabelContext-7faOb9VJ.js";function se(){const[f,r]=b.useState(!1),{toast:t}=C(),d=N(),{data:v,isLoading:g}=w({queryKey:["/api/admin/platform-roles"]}),c=v?.roles||[],m=p({mutationFn:async a=>j("POST","/api/admin/platform-roles",a),onSuccess:()=>{t({title:"Platform role added successfully"}),d.invalidateQueries({queryKey:["/api/admin/platform-roles"]}),r(!1)},onError:()=>{t({title:"Failed to add platform role",variant:"destructive"})}}),u=p({mutationFn:async a=>j("DELETE",`/api/admin/platform-roles/${a}`),onSuccess:()=>{t({title:"Platform role removed"}),d.invalidateQueries({queryKey:["/api/admin/platform-roles"]})},onError:()=>{t({title:"Failed to remove platform role",variant:"destructive"})}}),y=a=>{switch(a){case"super_admin":return e.jsx(l,{className:"bg-[var(--clr-shell)]",children:"Super Admin"});case"admin":return e.jsx(l,{className:"bg-[var(--clr-sky-600)]",children:"Admin"});case"viewer":return e.jsx(l,{variant:"secondary",children:"Read Only"});default:return e.jsx(l,{variant:"outline",children:a})}};return e.jsx(D,{children:e.jsxs("div",{className:"space-y-6","data-testid":"platform-roles-page",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Platform Roles"}),e.jsx("p",{className:"text-[var(--clr-ink-3)]",children:"Manage super admin and support roles"})]}),e.jsxs(i,{onClick:()=>r(!0),"data-testid":"button-add-role",children:[e.jsx(I,{className:"mr-2 h-4 w-4"}),"Add Role"]})]}),e.jsxs(R,{"data-analytics-section":"admin_platform_roles_list",children:[e.jsxs(T,{className:"bg-[var(--clr-sky)] text-[var(--clr-navy)] rounded-t-lg py-2 px-4 border-b border-[var(--clr-rule)]",children:[e.jsx(P,{className:"text-[var(--clr-navy)] text-sm uppercase tracking-widest font-mono",style:{fontFamily:"var(--font-mono)"},children:"All Platform Roles"}),e.jsx(A,{children:"Users with platform-wide administrative access"})]}),e.jsx(S,{children:e.jsxs(O,{children:[e.jsx(_,{children:e.jsxs(n,{children:[e.jsx(o,{children:"Email"}),e.jsx(o,{children:"Role"}),e.jsx(o,{children:"Created"}),e.jsx(o,{className:"text-right",children:"Actions"})]})}),e.jsx(H,{children:g?e.jsx(n,{children:e.jsx(s,{colSpan:4,className:"text-center",children:"Loading..."})}):c?.length===0?e.jsx(n,{children:e.jsx(s,{colSpan:4,className:"text-center",children:"No platform roles configured"})}):c?.map(a=>e.jsxs(n,{"data-testid":`row-role-${a.id}`,children:[e.jsx(s,{className:"font-medium",children:a.user?.email||a.userId}),e.jsx(s,{children:y(a.role)}),e.jsx(s,{children:new Date(a.createdAt).toLocaleDateString()}),e.jsx(s,{className:"text-right",children:e.jsx(i,{variant:"ghost",size:"sm",onClick:()=>u.mutate(a.userId),disabled:u.isPending,"data-testid":`button-remove-${a.id}`,children:e.jsx(K,{className:"h-4 w-4 text-[var(--clr-shell)]"})})})]},a.id))})]})})]}),e.jsx(E,{open:f,onOpenChange:r,children:e.jsxs(F,{children:[e.jsxs(k,{children:[e.jsx(L,{children:"Add Platform Role"}),e.jsx(q,{children:"Grant platform-wide administrative access to a user"})]}),e.jsxs("form",{onSubmit:a=>{a.preventDefault();const x=new FormData(a.currentTarget);m.mutate({email:x.get("email"),role:x.get("role")})},children:[e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"email",children:"User Email"}),e.jsx(B,{id:"email",name:"email",type:"email",placeholder:"[email protected]",required:!0,"data-testid":"input-email"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"role",children:"Role"}),e.jsxs("select",{name:"role",className:"flex h-10 w-full rounded-md border border-input bg-white px-3 py-2 text-sm",defaultValue:"admin","data-testid":"select-role",children:[e.jsx("option",{value:"super_admin",children:"Super Admin"}),e.jsx("option",{value:"admin",children:"Admin"}),e.jsx("option",{value:"viewer",children:"Read Only"})]})]})]}),e.jsxs(M,{children:[e.jsx(i,{type:"button",variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(i,{type:"submit",disabled:m.isPending,"data-testid":"button-save",children:"Add Role"})]})]})]})})]})})}export{se as PlatformRolesPage};
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.