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