12 |
- "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9738],{20374:(e,s,n)=>{n.r(s),n.d(s,{default:()=>m});var a,r,t=n(68404),i=n(18745),o=n(42326),l=n(90923),c=n(69783),d=n(33801),u=n(57497),g=n(77058),h=n(98163),b=n(58170),p=n(8674),v=n(45916);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.acc5efcb810b8ea01ff8.js.map
|