"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2721],{15419:(e,s,a)=>{a.r(s),a.d(s,{default:()=>w});var i,t,r,n=a(77813),l=a(76687),o=a(59076),d=a(5205),c=a(35562),h=a(79002),u=a(56481),m=a(45550),g=a(9120),x=a(55312),j=a(28781),b=a(31271),p=a(38927),v=a(352),f=a(26691),N=a(52010);function w(e){var s,a;let{match:w}=e;const y=parseInt(w.params.id,10),I=b.Vt.hasPermission(v.bW.OrgsWrite),O=b.Vt.hasPermission(v.bW.OrgUsersRead),[R,C]=(0,l.useState)([]),[U,V]=(0,o.Z)((()=>(async e=>await(0,d.i)().get("/api/orgs/"+e))(y)),[]),[,W]=(0,o.Z)((()=>(async e=>b.Vt.hasPermission(v.bW.OrgUsersRead)?await(0,d.i)().get(`/api/orgs/${e}/users`,(0,p.y)()):[])(y)),[]);(0,l.useEffect)((()=>{V(),W().then((e=>C(e)))}),[V,W]);const D={text:null!==(s=null==U||null===(a=U.value)||void 0===a?void 0:a.name)&&void 0!==s?s:"",icon:"shield",breadcrumbs:[{title:"Orgs",url:"admin/orgs"}],subTitle:"Manage settings and user roles for an organization."};return(0,N.jsx)(j.T,{navId:"global-orgs",pageNav:D,subTitle:"Manage settings for this specific org.",children:(0,N.jsx)(j.T.Contents,{children:(0,N.jsxs)(N.Fragment,{children:[t||(t=(0,N.jsx)(h.D,{children:"Edit organization"})),U.value&&(0,N.jsx)(u.l,{defaultValues:{orgName:U.value.name},onSubmit:async e=>await(async e=>await(0,d.i)().put("/api/orgs/"+y,Object.assign({},U.value,{name:e})))(e.orgName),children:e=>{let{register:s,errors:a}=e;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(m.g,{label:"Name",invalid:!!a.orgName,error:"Name is required",disabled:!I,children:(0,N.jsx)(g.I,Object.assign({},s("orgName",{required:!0}),{id:"org-name-input"}))}),(0,N.jsx)(x.zx,{type:"submit",disabled:!I,children:"Update"})]})}}),(0,N.jsxs)("div",{className:n.css`
              margin-top: 20px;
            `,children:[r||(r=(0,N.jsx)(h.D,{children:"Organization users"})),!O&&(i||(i=(0,N.jsx)(c.b,{severity:"info",title:"Access denied",children:"You do not have permission to see users in this organization. To update this organization, contact your server administrator."}))),O&&!!R.length&&(0,N.jsx)(f.Z,{users:R,orgId:y,onRoleChange:(e,s)=>{(async(e,s)=>{await(0,d.i)().patch("/api/orgs/"+s+"/users/"+e.userId,e)})(Object.assign({},s,{role:e}),y),C(R.map((a=>s.userId===a.userId?Object.assign({},s,{role:e}):a))),W()},onRemoveUser:e=>{(async(e,s)=>{await(0,d.i)().delete("/api/orgs/"+s+"/users/"+e.userId)})(e,y),C(R.filter((s=>e.userId!==s.userId))),W()}})]})]})})})}},26691:(e,s,a)=>{a.d(s,{Z:()=>f});var i,t,r,n,l,o,d,c,h=a(76687),u=a(55312),m=a(97867),g=a(19017),x=a(9279),j=a(31271),b=a(352),p=a(35333),v=a(52010);const f=e=>{const{users:s,orgId:a,onRoleChange:f,onRemoveUser:N}=e,[w,y]=(0,h.useState)(null),[I,O]=(0,h.useState)([]);return(0,h.useEffect)((()=>{j.Vt.licensedAccessControlEnabled()&&async function(){try{if(j.Vt.hasPermission(b.bW.ActionRolesList)){let e=await(0,x.ul)(a);O(e)}}catch(e){console.error("Error loading options")}}()}),[a]),(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)("table",{className:"filter-table form-inline",children:[(0,v.jsx)("thead",{children:(0,v.jsxs)("tr",{children:[i||(i=(0,v.jsx)("th",{})),t||(t=(0,v.jsx)("th",{children:"Login"})),r||(r=(0,v.jsx)("th",{children:"Email"})),n||(n=(0,v.jsx)("th",{children:"Name"})),l||(l=(0,v.jsx)("th",{children:"Seen"})),o||(o=(0,v.jsx)("th",{children:"Role"})),(0,v.jsx)("th",{style:{width:"34px"}}),d||(d=(0,v.jsx)("th",{}))]})}),(0,v.jsx)("tbody",{children:s.map(((e,s)=>(0,v.jsxs)("tr",{children:[(0,v.jsx)("td",{className:"width-2 text-center",children:(0,v.jsx)("img",{className:"filter-table__avatar",src:e.avatarUrl,alt:"User avatar"})}),(0,v.jsx)("td",{className:"max-width-6",children:(0,v.jsx)("span",{className:"ellipsis",title:e.login,children:e.login})}),(0,v.jsx)("td",{className:"max-width-5",children:(0,v.jsx)("span",{className:"ellipsis",title:e.email,children:e.email})}),(0,v.jsx)("td",{className:"max-width-5",children:(0,v.jsx)("span",{className:"ellipsis",title:e.name,children:e.name})}),(0,v.jsx)("td",{className:"width-1",children:e.lastSeenAtAge}),(0,v.jsx)("td",{className:"width-8",children:j.Vt.licensedAccessControlEnabled()?(0,v.jsx)(g.R,{userId:e.userId,orgId:a,roleOptions:I,basicRole:e.role,onBasicRoleChange:s=>f(s,e),basicRoleDisabled:!j.Vt.hasPermissionInMetadata(b.bW.OrgUsersWrite,e)}):(0,v.jsx)(p.A,{"aria-label":"Role",value:e.role,disabled:!j.Vt.hasPermissionInMetadata(b.bW.OrgUsersWrite,e),onChange:s=>f(s,e)})}),(0,v.jsx)("td",{className:"width-1 text-center",children:e.isDisabled&&(c||(c=(0,v.jsx)("span",{className:"label label-tag label-tag--gray",children:"Disabled"})))}),j.Vt.hasPermissionInMetadata(b.bW.OrgUsersRemove,e)&&(0,v.jsx)("td",{className:"text-right",children:(0,v.jsx)(u.zx,{size:"sm",variant:"destructive",onClick:()=>{y(e)},icon:"times","aria-label":"Delete user"})})]},`${e.userId}-${s}`)))})]}),Boolean(w)&&(0,v.jsx)(m.s,{body:`Are you sure you want to delete user ${null==w?void 0:w.login}?`,confirmText:"Delete",title:"Delete",onDismiss:()=>{y(null)},isOpen:!0,onConfirm:()=>{w&&(N(w),y(null))}})]})}}}]);
//# sourceMappingURL=AdminEditOrgPage.13f1ba852c0be84d20fc.js.map