"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9738],{36497:(K,d,a)=>{a.r(d),a.d(d,{ServiceAccountCreatePage:()=>m,default:()=>h});var e=a(68404),u=a(54899),v=a(37932),R=a(94270),C=a(13393),P=a(24799),D=a(46967),I=a(31403),E=a(79396),M=a(66226),g=a(11630),o=a(77582),i=a(81168),p=a(65135);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.4b032ad66d525c0efca2.js.map