"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4176],{63606:(y,_,a)=>{a.r(_),a.d(_,{ServiceAccountCreatePage:()=>g,default:()=>f});var n=a(96540),P=a(17172),D=a(12131),R=a(51253),v=a(84167),d=a(88575),C=a(10354),I=a(55852),u=a(36830),M=a(89062),A=a(85927),o=a(10096),r=a(80348),p=a(5133);const T=async c=>{const l=await(0,P.AI)().post("/api/serviceaccounts/",c);return await o.TP.fetchUserPermissions(),l},U=async(c,l)=>(0,P.AI)().patch(`/api/serviceaccounts/${c}`,l),g=({})=>{const[c,l]=(0,n.useState)([]),[E,L]=(0,n.useState)([]),m=o.TP.user.orgId,[s,h]=(0,n.useState)({id:0,orgId:o.TP.user.orgId,role:o.TP.licensedAccessControlEnabled()?r.OrgRole.None:r.OrgRole.Viewer,tokens:0,name:"",login:"",isDisabled:!1,createdAt:"",teams:[]});(0,n.useEffect)(()=>{async function t(){try{if(o.TP.hasPermission(r.AccessControlAction.ActionRolesList)){let e=await(0,A.RL)(m);l(e)}}catch(e){console.error("Error loading options",e)}}o.TP.licensedAccessControlEnabled()&&t()},[m]);const B=(0,n.useCallback)(async t=>{t.role=s.role;const e=await T(t);try{const i={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 U(e.id,t),o.TP.licensedAccessControlEnabled()&&o.TP.hasPermission(r.AccessControlAction.ActionUserRolesAdd)&&o.TP.hasPermission(r.AccessControlAction.ActionUserRolesRemove)&&await(0,A.eA)(E,i.id,i.orgId)}catch(i){console.error(i)}D.Ny.push(`/org/serviceaccounts/${e.id}`)},[s.role,E]),O=t=>{h({...s,role:t})},W=(t,e,i)=>{L(t)};return n.createElement(u.Y,{navId:"serviceaccounts",pageNav:{text:"Create service account"}},n.createElement(u.Y.Contents,null,n.createElement(R.l,{onSubmit:B,validateOn:"onSubmit"},({register:t,errors:e})=>n.createElement(n.Fragment,null,n.createElement(v.n,null,n.createElement(d.D,{label:"Display name",required:!0,invalid:!!e.name,error:e.name?"Display name is required":void 0},n.createElement(C.p,{id:"display-name-input",...t("name",{required:!0}),autoFocus:!0})),n.createElement(d.D,{label:"Role"},o.TP.licensedAccessControlEnabled()?n.createElement(M.y,{apply:!0,userId:s.id||0,orgId:s.orgId,basicRole:s.role,onBasicRoleChange:O,roleOptions:c,onApplyRoles:W,pendingRoles:E,maxWidth:"100%"}):n.createElement(p.r,{"aria-label":"Role",value:s.role,onChange:O}))),n.createElement(I.$n,{type:"submit"},"Create")))))},f=g}}]);

//# sourceMappingURL=ServiceAccountCreatePage.4f989fb6cd2a41193ff0.js.map