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

//# sourceMappingURL=ServiceAccountCreatePage.30d4d986fce59d3efb58.js.map