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

//# sourceMappingURL=CreateTeam.f48cb8ef95f7ced9c0c9.js.map