"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9738],{32404:(K,_,n)=>{n.r(_),n.d(_,{ServiceAccountCreatePage:()=>A,default:()=>T});var t=n(39953),d=n(4148),R=n(13601),v=n(85830),D=n(2827),u=n(96227),C=n(38637),I=n(4919),P=n(13253),M=n(10639),g=n(4171),o=n(21308),i=n(57721),p=n(65741);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.None,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.6f8bc67b763eebf32db1.js.map