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

//# sourceMappingURL=ServiceAccountCreatePage.d66cfa855673be3036d5.js.map