"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9738],{36497:(K,_,n)=>{n.r(_),n.d(_,{ServiceAccountCreatePage:()=>A,default:()=>T});var t=n(66111),d=n(54899),R=n(37932),v=n(94270),D=n(13393),u=n(24799),C=n(46967),I=n(31403),P=n(8412),M=n(66226),g=n(11630),o=n(77582),i=n(27876),p=n(65135);const U=async r=>{const c=await(0,d.i)().post("/api/serviceaccounts/",r);return await o.Vt.fetchUserPermissions(),c},f=async(r,c)=>(0,d.i)().patch(`/api/serviceaccounts/${r}`,c),A=({})=>{const[r,c]=(0,t.useState)([]),[E,h]=(0,t.useState)([]),m=o.Vt.user.orgId,[s,B]=(0,t.useState)({id:0,orgId:o.Vt.user.orgId,role:i.OrgRole.Viewer,tokens:0,name:"",login:"",isDisabled:!1,createdAt:"",teams:[]});(0,t.useEffect)(()=>{async function a(){try{if(o.Vt.hasPermission(i.AccessControlAction.ActionRolesList)){let e=await(0,g.ul)(m);c(e)}}catch(e){console.error("Error loading options",e)}}o.Vt.licensedAccessControlEnabled()&&a()},[m]);const L=(0,t.useCallback)(async a=>{a.role=s.role;const e=await U(a);try{const l={avatarUrl:e.avatarUrl,id:e.id,isDisabled:e.isDisabled,login:e.login,name:e.name,orgId:e.orgId,role:e.role,tokens:e.tokens};await f(e.id,a),o.Vt.licensedAccessControlEnabled()&&o.Vt.hasPermission(i.AccessControlAction.ActionUserRolesAdd)&&o.Vt.hasPermission(i.AccessControlAction.ActionUserRolesRemove)&&await(0,g.hB)(E,l.id,l.orgId)}catch(l){console.error(l)}R.E1.push(`/org/serviceaccounts/${e.id}`)},[s.role,E]),O=a=>{B({...s,role:a})},W=(a,e,l)=>{h(a)};return t.createElement(P.T,{navId:"serviceaccounts",pageNav:{text:"Create service account"}},t.createElement(P.T.Contents,null,t.createElement(v.l,{onSubmit:L,validateOn:"onSubmit"},({register:a,errors:e})=>t.createElement(t.Fragment,null,t.createElement(D.C,null,t.createElement(u.g,{label:"Display name",required:!0,invalid:!!e.name,error:e.name?"Display name is required":void 0},t.createElement(C.I,{id:"display-name-input",...a("name",{required:!0}),autoFocus:!0})),t.createElement(u.g,{label:"Role"},o.Vt.licensedAccessControlEnabled()?t.createElement(M.R,{apply:!0,userId:s.id||0,orgId:s.orgId,basicRole:s.role,onBasicRoleChange:O,roleOptions:r,onApplyRoles:W,pendingRoles:E,maxWidth:"100%"}):t.createElement(p.A,{"aria-label":"Role",value:s.role,onChange:O}))),t.createElement(I.zx,{type:"submit"},"Create")))))},T=A}}]);

//# sourceMappingURL=ServiceAccountCreatePage.faebc5b65f0a3594b587.js.map