"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9738],{77662:(e,s,n)=>{n.r(s),n.d(s,{default:()=>m});var a,r,t=n(76687),i=n(46958),o=n(59163),l=n(10967),c=n(70534),d=n(36131),u=n(19017),g=n(9279),h=n(31271),b=n(99462),p=n(3276),v=n(52010);const m=(0,i.connect)((e=>({navModel:(0,p.h)(e.navIndex,"serviceaccounts")})))((e=>{let{navModel:s}=e;const[n,i]=(0,t.useState)([]),[p,m]=(0,t.useState)({}),[I,j]=(0,t.useState)([]),f=h.Vt.user.orgId,[k,x]=(0,t.useState)({id:0,orgId:h.Vt.user.orgId,role:b.B5.Viewer,tokens:0,name:"",login:"",isDisabled:!1,createdAt:"",teams:[]});(0,t.useEffect)((()=>{h.Vt.licensedAccessControlEnabled()&&async function(){try{if(h.Vt.hasPermission(b.bW.ActionRolesList)){let e=await(0,g.ul)(f);i(e)}if(h.Vt.hasPermission(b.bW.ActionBuiltinRolesList)){const e=await(0,g.fh)(f);m(e)}}catch(e){console.error("Error loading options",e)}}()}),[f]);const y=(0,o.k6)(),R=(0,t.useCallback)((async e=>{e.role=k.role;const s=await(async e=>(0,l.getBackendSrv)().post("/api/serviceaccounts/",e))(e);try{const n={avatarUrl:s.avatarUrl,id:s.id,isDisabled:s.isDisabled,login:s.login,name:s.name,orgId:s.orgId,role:s.role,tokens:s.tokens};await(async(e,s)=>(0,l.getBackendSrv)().patch(`/api/serviceaccounts/${e}`,s))(s.id,e),await(0,g.hB)(I,n.id,n.orgId)}catch(e){console.error(e)}y.push("/org/serviceaccounts/")}),[y,k.role,I]),C=(e,s,n)=>{j(e)};return(0,v.jsx)(d.Z,{navModel:s,children:(0,v.jsxs)(d.Z.Contents,{children:[a||(a=(0,v.jsx)("h1",{children:"Create service account"})),(0,v.jsx)(c.Form,{onSubmit:R,validateOn:"onBlur",children:e=>{let{register:s,errors:a}=e;return(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(c.Field,{label:"Display name",required:!0,invalid:!!a.name,error:a.name?"Display name is required":void 0,children:(0,v.jsx)(c.Input,Object.assign({id:"display-name-input"},s("name",{required:!0})))}),h.Vt.accessControlEnabled()&&(0,v.jsx)(c.Field,{label:"Role",children:(0,v.jsx)(u.R,{userId:k.id||0,orgId:k.orgId,builtInRole:k.role,builtInRoles:p,onBuiltinRoleChange:e=>{return s=e,void x(Object.assign({},k,{role:s}));var s},builtinRolesDisabled:!1,roleOptions:n,updateDisabled:!0,onApplyRoles:C,pendingRoles:I})}),r||(r=(0,v.jsx)(c.Button,{type:"submit",children:"Create"}))]})}})]})})}))}}]);
//# sourceMappingURL=ServiceAccountCreatePage.a5a2731d0137194246dd.js.map