"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9738],{43456:(K,_,n)=>{n.r(_),n.d(_,{ServiceAccountCreatePage:()=>A,default:()=>T});var t=n(27702),d=n(73289),R=n(26129),v=n(23839),D=n(5229),u=n(22209),C=n(1128),I=n(66670),P=n(44644),M=n(75574),g=n(11349),o=n(66574),i=n(18771),p=n(8237);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.eca40b62f750269fc25a.js.map