(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[693],{7873:function(e,n,s){(window.__NEXT_P=window.__NEXT_P||[]).push(["/user-management",function(){return s(8632)}])},8632:function(e,n,s){"use strict";s.r(n),s.d(n,{default:function(){return y}});var i=s(24246),t=s(27378),r=s(5702),l=s(45007),d=s(44296),a=s(31756),h=s(20133),c=s(86677),o=s(36223),p=s(11032),x=s(38615),u=s(49646),g=s(10284),j=s(72763),m=e=>{var n,s;let{user:t}=e,l=(0,c.useRouter)(),m=(0,r.qY0)(),b=(0,d.C)(o.dy),T=!!b&&b.id===t.id,f=(0,x.Tg)([g.Sh.USER_UPDATE])||T,v=()=>{f&&l.push("".concat(p.e3,"/profile/").concat(t.id))},{data:C}=(0,a.gU)(null!==(n=t.id)&&void 0!==n?n:"",{skip:!t.id}),{data:_}=(0,a.d6)(null!==(s=t.id)&&void 0!==s?s:"",{skip:!t.id}),w=[];return C&&C.roles&&C.roles.forEach(e=>{let n=u.K.find(n=>n.roleKey===e);n&&w.push(n.permissions_label)}),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(r.Tr,{_hover:{bg:"gray.50",cursor:f?"pointer":void 0},height:"36px","data-testid":"row-".concat(t.id),children:[(0,i.jsxs)(r.Td,{pl:0,py:1,onClick:v,children:[t.username," ",t.disabled&&(0,i.jsx)(r.Cts,{bg:"green.500",color:"white",paddingLeft:"2",textTransform:"none",paddingRight:"8px",height:"18px",lineHeight:"18px",borderRadius:"6px",fontWeight:"500",textAlign:"center","data-testid":"invite-sent-badge",children:"Invite sent"})]}),(0,i.jsx)(r.Td,{pl:0,py:1,onClick:v,children:t.email_address}),(0,i.jsx)(r.Td,{pl:0,py:1,onClick:v,children:t.first_name}),(0,i.jsx)(r.Td,{pl:0,py:1,onClick:v,children:t.last_name}),(0,i.jsx)(r.Td,{pl:0,py:1,onClick:v,children:w.map(e=>(0,i.jsx)(r.Cts,{bg:"gray.500",color:"white",paddingLeft:"2",textTransform:"none",paddingRight:"8px",height:"18px",lineHeight:"18px",borderRadius:"6px",fontWeight:"500",textAlign:"center","data-testid":"user-permissions-badge",children:e},e))}),(0,i.jsx)(r.Td,{pl:0,py:1,onClick:v,children:(0,i.jsx)(r.Cts,{bg:"gray.500",color:"white",paddingLeft:"2",textTransform:"none",paddingRight:"8px",height:"18px",lineHeight:"18px",borderRadius:"6px",fontWeight:"500",textAlign:"center","data-testid":"user-systems-badge",children:_?_.length:0})}),(0,i.jsx)(r.Td,{pl:0,py:1,onClick:v,children:t.created_at?new Date(t.created_at).toUTCString():null}),(0,i.jsx)(x.ZP,{scopes:[g.Sh.USER_DELETE],children:(0,i.jsx)(r.Td,{pr:0,py:1,textAlign:"end",position:"relative",children:(0,i.jsx)(r.wpx,{"aria-label":"delete",icon:(0,i.jsx)(h.l,{}),onClick:m.onOpen,"data-testid":"delete-user-btn"})})})]},t.id),(0,i.jsx)(j.Z,{user:t,...m})]})};let b=()=>{var e,n;let s=(0,l.I0)(),i=(0,l.v9)(a.lq),{data:t,isLoading:r}=(0,a.wv)(i),d=null!==(e=null==t?void 0:t.items)&&void 0!==e?e:[],h=null!==(n=null==t?void 0:t.total)&&void 0!==n?n:0;return{...i,isLoading:r,users:d,total:h,handleNextPage:()=>{s((0,a.YA)(i.page+1))},handlePreviousPage:()=>{s((0,a.YA)(i.page-1))}}},T=()=>{let{users:e,total:n,page:s,size:l,handleNextPage:h,handlePreviousPage:c}=b(),o=(s-1)*l+1,p=Math.min(n,s*l),x=(0,d.T)();return(0,t.useEffect)(()=>{x((0,a.Vv)(void 0))},[x]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(r.iA_,{size:"sm","data-testid":"user-management-table",children:[(0,i.jsx)(r.hrZ,{children:(0,i.jsxs)(r.Tr,{children:[(0,i.jsx)(r.Th,{pl:0,children:"Username"}),(0,i.jsx)(r.Th,{pl:0,children:"Email"}),(0,i.jsx)(r.Th,{pl:0,children:"First Name"}),(0,i.jsx)(r.Th,{pl:0,children:"Last Name"}),(0,i.jsx)(r.Th,{pl:0,children:"Permissions"}),(0,i.jsx)(r.Th,{pl:0,children:"Assigned Systems"}),(0,i.jsx)(r.Th,{pl:0,children:"Created At"})]})}),(0,i.jsx)(r.p3B,{children:null==e?void 0:e.map(e=>(0,i.jsx)(m,{user:e},e.id))})]}),(0,i.jsxs)(r.kCb,{justifyContent:"space-between",mt:6,children:[(0,i.jsx)(r.xvT,{fontSize:"xs",color:"gray.600",children:n>0?(0,i.jsxs)(i.Fragment,{children:["Showing ",Number.isNaN(o)?0:o," to"," ",Number.isNaN(p)?0:p," of"," ",Number.isNaN(n)?0:n," results"]}):"0 results"}),(0,i.jsxs)("div",{children:[(0,i.jsx)(r.wpx,{disabled:s<=1,onClick:c,className:"mr-2",children:"Previous"}),(0,i.jsx)(r.wpx,{disabled:s*l>=n,onClick:h,children:"Next"})]})]})]})};T.defaultProps={users:[]};var f=s(33312);let v=()=>{let e=(0,l.v9)(a.lq),n=(0,l.I0)();return{handleSearchChange:e=>{n((0,a.SY)(e))},...e}};var C=()=>{let{handleSearchChange:e,username:n}=v(),s=(0,c.useRouter)();return(0,i.jsxs)(r.Kqy,{direction:"row",spacing:4,mb:6,children:[(0,i.jsx)(f.Z,{search:n,onChange:e,placeholder:"Search by Username"}),(0,i.jsx)(x.ZP,{scopes:[g.Sh.USER_CREATE],children:(0,i.jsx)(r.wpx,{onClick:()=>s.push("".concat(p.e3,"/new")),type:"primary",className:"shrink-0","data-testid":"add-new-user-btn",children:"Add new user"})})]})},_=s(43124),w=s(37541),y=()=>(0,i.jsxs)(_.Z,{title:"User Management",children:[(0,i.jsx)(w.Z,{heading:"Users",breadcrumbItems:[{title:"All users"}]}),(0,i.jsx)(C,{}),(0,i.jsx)(T,{})]})}},function(e){e.O(0,[53,2888,9774,179],function(){return e(e.s=7873)}),_N_E=e.O()}]);