"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5436],{99929(f,m,a){a.d(m,{Y:()=>d});var e=a(74848),C=a(96540),O=a(41053),n=a(73427),E=a(11257),i=a(59812),P=a(34418);const d=({teamId:o,roleOptions:T,disabled:r,roles:t,onApplyRoles:l,pendingRoles:_,apply:c=!1,maxWidth:s,width:D,isLoading:I})=>{const[{loading:u,value:L=t||[]},A]=(0,O.A)(async()=>{try{if(t)return t;if(c&&_?.length)return _;if(n.TP.hasPermission(E.w.ActionTeamsRolesList)&&o>0)return await(0,P.xN)(o)}catch(M){console.error("Error loading options",M)}return[]},[o,_,t]);(0,C.useEffect)(()=>{A()},[A]);const v=async M=>{c?l&&l(M):(await(0,P.G3)(M,o),await A())},U=n.TP.hasPermission(E.w.ActionTeamsRolesAdd)&&n.TP.hasPermission(E.w.ActionTeamsRolesRemove);return(0,e.jsx)(i.n,{apply:c,onRolesChange:v,roleOptions:T,appliedRoles:L,isLoading:u||I,disabled:r,basicRoleDisabled:!0,canUpdateRoles:U,maxWidth:s,width:D})}},99686(f,m,a){a.d(m,{P:()=>T,o:()=>o});var e=a(2543),C=a.n(e),O=a(96540),n=a(45214),E=a(24705),i=a(73427),P=a(11257),d=a(34418);const o=r=>{const[t,l]=(0,O.useState)(r),{value:_=[]}=(0,E.A)(async()=>i.TP.licensedAccessControlEnabled()&&i.TP.hasPermission(P.w.ActionRolesList)?(0,d.RL)(t):Promise.resolve([]),[t]);return[{roleOptions:_},l]},T=r=>{const[t,l]=(0,O.useState)({});return(0,n.A)(()=>{if(!i.TP.licensedAccessControlEnabled()||!i.TP.hasPermission(P.w.ActionRolesList))return;const _=Object.keys(t).map(s=>typeof s=="number"?s:parseInt(s,10)),c=(0,e.difference)(r,_);Promise.all(c.map(s=>(0,d.RL)(s).then(D=>[s,D]))).then(s=>{l({...t,...Object.fromEntries(s)})})},[r]),t}},84974(f,m,a){a.r(m),a.d(m,{CreateTeam:()=>u,default:()=>L});var e=a(74848),C=a(96540),O=a(49785),n=a(92745),E=a(68143),i=a(36490),P=a(45861),d=a(41654),o=a(37386),T=a(16780),r=a(63527),t=a(40210),l=a(99929),_=a(34418),c=a(99686),s=a(73427),D=a(11257);const I={icon:"users-alt",id:"team-new",text:"New team",subTitle:"Create a new team. Teams let you grant permissions to a group of users."},u=()=>{const A=s.TP.user.orgId,[v,U]=(0,C.useState)([]),[{roleOptions:M}]=(0,c.o)(A),{handleSubmit:g,register:h,formState:{errors:B}}=(0,O.mN)(),W=s.TP.hasPermission(D.w.ActionUserRolesAdd)&&s.TP.hasPermission(D.w.ActionUserRolesRemove),K=async p=>{try{const R=await(0,E.AI)().post("/api/teams",p);R.teamId&&(await s.TP.fetchUserPermissions(),s.TP.licensedAccessControlEnabled()&&W&&await(0,_.G3)(v,R.teamId,R.orgId),i.Ny.push(`/org/teams/edit/${R.uid}`))}catch(R){console.error(R)}};return(0,e.jsx)(t.Y,{navId:"teams",pageNav:I,children:(0,e.jsx)(t.Y.Contents,{children:(0,e.jsxs)("form",{onSubmit:g(K),style:{maxWidth:"600px"},children:[(0,e.jsx)(T.n,{children:(0,e.jsxs)(d.B,{direction:"column",gap:2,children:[(0,e.jsx)(o.D,{noMargin:!0,label:(0,n.t)("teams.create-team.label-name","Name"),required:!0,invalid:!!B.name,error:"Team name is required",children:(0,e.jsx)(r.p,{...h("name",{required:!0}),id:"team-name"})}),s.TP.licensedAccessControlEnabled()&&(0,e.jsx)(o.D,{noMargin:!0,label:(0,n.t)("teams.create-team.label-role","Role"),children:(0,e.jsx)(l.Y,{teamId:0,roleOptions:M,disabled:!1,apply:!0,onApplyRoles:U,pendingRoles:v,maxWidth:"100%"})}),(0,e.jsx)(o.D,{noMargin:!0,label:(0,n.t)("teams.create-team.label-email","Email"),description:(0,n.t)("teams.create-team.description-email","This is optional and is primarily used for allowing custom team avatars"),children:(0,e.jsx)(r.p,{...h("email"),type:"email",id:"team-email",placeholder:"email@test.com"})})]})}),(0,e.jsx)(P.$n,{type:"submit",variant:"primary",children:(0,e.jsx)(n.x6,{i18nKey:"teams.create-team.create",children:"Create"})})]})})})},L=u}}]);

//# sourceMappingURL=CreateTeam.76697f7deae284358310.js.map