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