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

//# sourceMappingURL=CreateTeam.1015e69c7296d19cf41d.js.map