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

//# sourceMappingURL=CreateTeam.12203042ce60c5dd399c.js.map