"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2721],{"./public/app/features/admin/AdminEditOrgPage.tsx":(e,s,a)=>{a.r(s),a.d(s,{AdminEditOrgPage:()=>p,default:()=>j});var r,t,n,i=a("./node_modules/react/index.js"),l=a("./public/app/core/components/Page/Page.tsx"),d=a("./node_modules/react-redux/es/index.js"),c=a("./public/app/core/selectors/navModel.ts"),o=a("./public/app/features/users/UsersTable.tsx"),u=a("./node_modules/react-use/esm/useAsyncFn.js"),m=a("./packages/grafana-runtime/src/index.ts"),x=a("./packages/grafana-ui/src/index.ts"),g=a("./node_modules/@emotion/css/dist/emotion-css.esm.js"),h=a("./node_modules/react/jsx-runtime.js");const p=({match:e})=>{const s=(0,d.useSelector)((e=>e.navIndex)),a=(0,c.h)(s,"global-orgs"),p=parseInt(e.params.id,10),[j,b]=(0,i.useState)([]),[v,f]=(0,u.Z)((()=>(async e=>await(0,m.getBackendSrv)().get("/api/orgs/"+e))(p)),[]),[,N]=(0,u.Z)((()=>(async e=>await(0,m.getBackendSrv)().get("/api/orgs/"+e+"/users"))(p)),[]);(0,i.useEffect)((()=>{f(),N().then((e=>b(e)))}),[f,N]);return(0,h.jsx)(l.Z,{navModel:a,children:(0,h.jsx)(l.Z.Contents,{children:(0,h.jsxs)(h.Fragment,{children:[r||(r=(0,h.jsx)(x.Legend,{children:"Edit organization"})),v.value&&(0,h.jsx)(x.Form,{defaultValues:{orgName:v.value.name},onSubmit:async e=>await(async e=>await(0,m.getBackendSrv)().put("/api/orgs/"+p,Object.assign({},v.value,{name:e})))(e.orgName),children:({register:e,errors:s})=>(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x.Field,{label:"Name",invalid:!!s.orgName,error:"Name is required",children:(0,h.jsx)(x.Input,Object.assign({},e("orgName",{required:!0}),{id:"org-name-input"}))}),t||(t=(0,h.jsx)(x.Button,{children:"Update"}))]})}),(0,h.jsxs)("div",{className:g.css`
              margin-top: 20px;
            `,children:[n||(n=(0,h.jsx)(x.Legend,{children:"Organization users"})),!!j.length&&(0,h.jsx)(o.Z,{users:j,onRoleChange:(e,s)=>{(async(e,s)=>{await(0,m.getBackendSrv)().patch("/api/orgs/"+s+"/users/"+e.userId,e)})(Object.assign({},s,{role:e}),p),b(j.map((a=>s.userId===a.userId?Object.assign({},s,{role:e}):a))),N()},onRemoveUser:e=>{(async(e,s)=>{await(0,m.getBackendSrv)().delete("/api/orgs/"+s+"/users/"+e.userId)})(e,p),b(j.filter((s=>e.userId!==s.userId))),N()}})]})]})})})},j=p},"./public/app/features/users/UsersTable.tsx":(e,s,a)=>{a.d(s,{Z:()=>h});var r,t,n,i,l,d,c=a("./node_modules/react/index.js"),o=a("./public/app/types/index.ts"),u=a("./public/app/features/admin/OrgRolePicker.tsx"),m=a("./packages/grafana-ui/src/index.ts"),x=a("./public/app/core/core.ts"),g=a("./node_modules/react/jsx-runtime.js");const h=e=>{const{users:s,onRoleChange:a,onRemoveUser:h}=e,p=x.Vt.hasPermission(o.bW.OrgUsersRoleUpdate),j=x.Vt.hasPermission(o.bW.OrgUsersRemove),[b,v]=(0,c.useState)(!1);return(0,g.jsxs)("table",{className:"filter-table form-inline",children:[(0,g.jsx)("thead",{children:(0,g.jsxs)("tr",{children:[r||(r=(0,g.jsx)("th",{})),t||(t=(0,g.jsx)("th",{children:"Login"})),n||(n=(0,g.jsx)("th",{children:"Email"})),i||(i=(0,g.jsx)("th",{children:"Name"})),l||(l=(0,g.jsx)("th",{children:"Seen"})),d||(d=(0,g.jsx)("th",{children:"Role"})),(0,g.jsx)("th",{style:{width:"34px"}})]})}),(0,g.jsx)("tbody",{children:s.map(((e,s)=>(0,g.jsxs)("tr",{children:[(0,g.jsx)("td",{className:"width-2 text-center",children:(0,g.jsx)("img",{className:"filter-table__avatar",src:e.avatarUrl,alt:"User avatar"})}),(0,g.jsx)("td",{className:"max-width-6",children:(0,g.jsx)("span",{className:"ellipsis",title:e.login,children:e.login})}),(0,g.jsx)("td",{className:"max-width-5",children:(0,g.jsx)("span",{className:"ellipsis",title:e.email,children:e.email})}),(0,g.jsx)("td",{className:"max-width-5",children:(0,g.jsx)("span",{className:"ellipsis",title:e.name,children:e.name})}),(0,g.jsx)("td",{className:"width-1",children:e.lastSeenAtAge}),(0,g.jsx)("td",{className:"width-8",children:(0,g.jsx)(u.A,{"aria-label":"Role",value:e.role,disabled:!p,onChange:s=>a(s,e)})}),j&&(0,g.jsxs)("td",{children:[(0,g.jsx)(m.Button,{size:"sm",variant:"destructive",onClick:()=>v(e.login),icon:"times","aria-label":"Delete user"}),(0,g.jsx)(m.ConfirmModal,{body:`Are you sure you want to delete user ${e.login}?`,confirmText:"Delete",title:"Delete",onDismiss:()=>v(!1),isOpen:e.login===b,onConfirm:()=>{h(e)}})]})]},`${e.userId}-${s}`)))})]})}}}]);
//# sourceMappingURL=AdminEditOrgPage.8128b05ac04b15cbf98d.js.map