mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 21:20:57 +00:00
2 lines
6.1 KiB
JavaScript
2 lines
6.1 KiB
JavaScript
import{n as T,m as w,o as B,u as D,k as P,j as e,B as h,t as F,v as d,az as R,r as j,f as K,aF as S}from"./index-7T7TTikv.js";import{A as q}from"./AdvancedTable-vWyUWUDX.js";import{C as L,a as I,b as M,d as Q}from"./card-_ldW-koX.js";import{b as _,c as H}from"./userService-CFvyXTYe.js";import{B as O}from"./badge-D4t6Wb1T.js";import{A as y,h as b,a as v,b as f,c as C,d as A,e as N,f as U,g as k}from"./alert-dialog-DwppaTz4.js";import{f as V}from"./format-DvwV82px.js";import{R as $,a as z}from"./radio-group-C9tEhs3a.js";import{L as E}from"./label-CABYEcfW.js";import"./table-D_B7hhqb.js";import"./select--i8koVXg.js";import"./chevron-left-G_a9-f9o.js";import"./utils-N2wtfq7C.js";import"./command-B6S1IvD4.js";import"./search-y8VSu0lZ.js";import"./popover-CSKEA8hg.js";import"./Popover-BSKEfTKH.js";import"./use-uncontrolled-tg0LIUAX.js";import"./separator-BXi_hr72.js";import"./refresh-cw-B7fipPS4.js";import"./en-US-Cc-9gH5A.js";import"./Radio-D43EoWlg.js";import"./get-auto-contrast-value-Da6zqqWm.js";import"./InputsGroupFieldset-B16dMH0P.js";const m={pendingUsers:["external-users","pending"],allExternalUsers:["external-users","all"]};var g=(s=>(s.external="external_organization",s.individual="individual",s))(g||{});const G=s=>T({queryKey:[...m.allExternalUsers,s],queryFn:async()=>(await H(s)).data}),J=()=>{const s=w();return B({mutationFn:({id:t,status:a})=>_(t,a),onSuccess:()=>{s.invalidateQueries({queryKey:m.pendingUsers}),s.invalidateQueries({queryKey:m.allExternalUsers})}})},W=({userId:s,userStatus:t})=>{const a=J(),{t:r}=D(),{handleError:l}=P(r),n=a.isPending,o=t==="pending"||t==="rejected"||t==="submitted",c=i=>{a.mutate({id:s,status:i},{onSuccess:()=>{F.success(i==="accepted"?"User successfully approved":"User successfully rejected")},onError:u=>{l(u)}})};return e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{children:[e.jsx(b,{asChild:!0,children:e.jsx(h,{className:"bg-primary-600 text-white hover:bg-primary-700",size:"sm",disabled:n||!o,children:r("statusBar.Approve")})}),e.jsxs(v,{children:[e.jsxs(f,{children:[e.jsx(C,{children:r("organization.approveUserPrompt")}),e.jsx(A,{children:r("organization.approveUserDescription")})]}),e.jsxs(N,{children:[e.jsx(U,{disabled:n,children:r("common.Cancel")}),e.jsx(k,{onClick:()=>c("accepted"),disabled:n,children:r(n?"organization.approving":"organization.yesApprove")})]})]})]}),t==="accepted"&&e.jsxs(y,{children:[e.jsx(b,{asChild:!0,children:e.jsx(h,{className:"bg-red-600 text-white hover:bg-red-700",size:"sm",disabled:n,children:r("statusBar.Reject")})}),e.jsxs(v,{children:[e.jsxs(f,{children:[e.jsx(C,{children:r("organization.rejectUserPrompt")}),e.jsx(A,{children:r("organization.rejectUserDescription")})]}),e.jsxs(N,{children:[e.jsx(U,{disabled:n,children:r("common.Cancel")}),e.jsx(k,{onClick:()=>c("rejected"),disabled:n,children:r(n?"organization.rejecting":"organization.yesReject")})]})]})]})]})},X=(s,t)=>[{accessorKey:"name.en",header:()=>d("organization.username"),cell:({row:a})=>e.jsx("div",{className:"font-medium",children:s(a.original.name)})},{accessorKey:"updatedAt",header:()=>d("organization.updatedOn"),cell:({row:a})=>e.jsx("div",{className:"font-medium",children:V(new Date(a.original.updatedAt),"MMM dd, yyyy")})},{accessorKey:"userType",header:()=>"User Type",cell:({row:a})=>{const r=a.original.userType,l=r==="external_organization"?"External Organization":"Employee";return e.jsx("div",{className:"font-medium",children:e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${r==="external_organization"?"bg-purple-100 text-purple-800 dark:bg-purple-900/40 dark:text-purple-300":"bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300"}`,children:l})})}},{id:"status",header:()=>d("dashboard.Status"),cell:({row:a})=>{const{status:r}=a.original,l=o=>{switch(o){case"accepted":return"bg-primary-100 text-primary-600 hover:bg-primary-100 dark:bg-primary-900/40 dark:text-primary-300 dark:hover:bg-primary-900/50";case"rejected":return"bg-red-100 text-red-600 hover:bg-red-100 dark:bg-red-900/40 dark:text-red-300 dark:hover:bg-red-900/50";case"pending":default:return"bg-blue-100 text-blue-600 hover:bg-blue-100 dark:bg-blue-900/40 dark:text-blue-300 dark:hover:bg-blue-900/50"}},n=o=>{switch(o){case"accepted":return"Accepted";case"rejected":return"Rejected";case"pending":default:return d("statusBar.Pending")}};return e.jsx("div",{children:e.jsx(O,{className:`${l(r)} rounded-full px-6 py-1 font-medium`,children:n(r)})})}},{id:"actions",header:()=>d("userRecord.Actions"),cell:({row:a})=>{const{id:r,status:l}=a.original,n=()=>{t(`/user-management/external_users/view/${r}`)};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{userId:r,userStatus:l}),e.jsx("button",{onClick:n,className:"px-2 py-1 bg-gray-100 dark:bg-gray-800 rounded hover:bg-gray-200 dark:hover:bg-gray-700 text-sm font-medium text-gray-800 dark:text-gray-200",children:d("View")})]})}}];function Ce(){const s=R(),[t,a]=j.useState(0),r=10,{t:l}=D(),n=K(),[o,c]=j.useState(void 0),{data:i,isLoading:u}=G({take:r,skip:t*r,orderBy:"updatedAt:Desc",userType:o}),p=x=>{a(x)};return u?e.jsx("div",{className:"flex justify-center p-6",children:e.jsx(S,{className:"animate-spin w-6 h-6 text-gray-500 dark:text-gray-400"})}):e.jsx("div",{className:"p-6 space-y-6",children:e.jsxs(L,{className:"col-span-2 shadow-none border-none bg-transparent px-0",children:[e.jsxs(I,{className:"flex flex-row justify-between items-center px-0",children:[e.jsx(M,{className:"text-xl font-semibold",children:"All Users"}),e.jsxs($,{value:o,onValueChange:x=>{c(x),a(0)},className:"flex gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(z,{value:g.external,id:"external"}),e.jsx(E,{htmlFor:"external",children:"External Organization"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(z,{value:g.individual,id:"individual"}),e.jsx(E,{htmlFor:"individual",children:"Individual"})]})]})]}),e.jsx(Q,{className:"px-0",children:e.jsx(q,{columns:X(s,n),data:(i==null?void 0:i.items)||[],tableName:"ExternalUsers",toolBarPosition:"right",itemCount:(i==null?void 0:i.count)||0,pageIndex:t,onPageChange:p,nextFunction:()=>p(t+1),prevFunction:()=>p(Math.max(t-1,0))})})]})})}export{Ce as default};
|