mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 14:20:58 +00:00
7 lines
9.1 KiB
JavaScript
7 lines
9.1 KiB
JavaScript
import{y as Y,j as e,B as c,v as E,m as Z,r as o,u as _,az as H,aK as B,aL as R,aM as ee,aN as ae,bo as se,aF as I,aP as O,I as te,ba as re,t as h,L as ie}from"./index-7T7TTikv.js";import{C as ne,a as oe,b as de,d as ce}from"./card-_ldW-koX.js";import{A as le}from"./AdvancedTable-vWyUWUDX.js";import{S as me,a as ue}from"./StatusCell-BAmClBhM.js";import{u as Q}from"./useOrganizations-CPt4mkXS.js";import{L as T}from"./label-CABYEcfW.js";import{S as L}from"./scroll-area-7Hggnc7C.js";import{u as xe}from"./useEmployees-DreGarUD.js";import{c as q}from"./utils-N2wtfq7C.js";import{u as ge}from"./useUnit-CRt6YBLp.js";import{U as pe}from"./user-plus-tzUBEFtH.js";import{P as he}from"./plus-CC3ol2sL.js";import"./table-D_B7hhqb.js";import"./select--i8koVXg.js";import"./chevron-left-G_a9-f9o.js";import"./badge-D4t6Wb1T.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"./useOrganizationAdmins-a9snXrfR.js";import"./use-toast-mIxmYSs4.js";import"./alert-dialog-DwppaTz4.js";import"./phone-w_VmAt3l.js";import"./eye-DYwZYJcQ.js";import"./organizationsService-DIFVjoLn.js";import"./unitService-DTtkt-Pb.js";/**
|
|
* @license lucide-react v0.513.0 - ISC
|
|
*
|
|
* This source code is licensed under the ISC license.
|
|
* See the LICENSE file in the root directory of this source tree.
|
|
*/const je=[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]],K=Y("arrow-up-down",je),fe=l=>[{accessorKey:"name",header:({column:s})=>e.jsxs(c,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),className:"p-0 hover:bg-transparent text-gray-700 dark:text-gray-300",style:{padding:0},children:[E("organization.name"),e.jsx(K,{className:"p-0 h-4 w-4"})]}),cell:({row:s})=>e.jsx("div",{className:"font-medium",children:l(s.original.name)})},{accessorKey:"status",header:({column:s})=>e.jsxs(c,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),className:"p-0 hover:bg-transparent text-gray-700 dark:text-gray-300",style:{padding:0},children:[E("dashboard.Status"),e.jsx(K,{className:"h-4 w-4"})]}),cell:({row:s})=>{const g=s.original.id;return e.jsx(me,{id:g,adminsCount:s.original.adminsCount})}}];function ye({onSuccess:l,onClose:s,isOpen:g}){var F;const d=Z(),[m,C]=o.useState(""),[x,n]=o.useState(""),[j,f]=o.useState(!1),[p,y]=o.useState(""),{t:r}=_(),[z,A]=o.useState(0),w=10,$=H(),{organizationsResponse:S,isLoading:V}=Q("Org",{take:300}),{employeesResponseByOrg:t,isLoading:G,refetch:J}=xe({organizationId:m||void 0,params:{take:w,skip:z*w}}),{data:b,isLoading:Ne}=ge().getList(m||"",{take:300,skip:0}),[D,U]=o.useState("");o.useEffect(()=>{var a,i;(i=(a=b==null?void 0:b.data)==null?void 0:a.items)!=null&&i.length?U(b.data.items[0].id):U("")},[m,b]);const W=async a=>{if(a.preventDefault(),!x||!m){h.error("All fields are required");return}const i=t==null?void 0:t.items.find(u=>u.user.id===x);if(!i)return h.error("User not found");if(!D){h.error("No unit available for this organization");return}f(!0);const N={unitId:D,userId:i.user.id};ue(N).then(()=>{d.invalidateQueries({queryKey:["organizationAdmins"]}),h.success(r("organization.userAssignedSuccess")),f(!1),s(),l()}).catch(u=>{var k,v;h.error(r("organization.userAssignFailed"),{description:(v=(k=u==null?void 0:u.response)==null?void 0:k.data)==null?void 0:v.message}),f(!1)})},X=()=>{C(""),n(""),J()},P=o.useMemo(()=>t!=null&&t.items?t.items.filter(a=>{var k,v,M;const i=((v=(k=a.user.name)==null?void 0:k.en)==null?void 0:v.toLowerCase())||"",N=((M=a.user.email)==null?void 0:M.toLowerCase())||"",u=p.toLowerCase();return i.includes(u)||N.includes(u)}):[],[t,p]);return e.jsx(B,{open:g,onOpenChange:s,children:e.jsxs(R,{className:"sm:max-w-[800px]",children:[e.jsxs(ee,{children:[e.jsx(ae,{children:r("organization.assignAdminToOrganization")}),e.jsx(se,{children:r("organization.assignAdminInstructions")})]}),e.jsxs("form",{onSubmit:W,className:"space-y-6",children:[e.jsxs(L,{className:"h-[450px] border border-gray-200 dark:border-gray-700 rounded-md p-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:r("organization.organizations")}),V?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(I,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsx(L,{className:"h-[200px] border border-gray-200 dark:border-gray-700 rounded-md p-2",children:e.jsx("div",{className:"space-y-1",children:(F=S==null?void 0:S.items)==null?void 0:F.map(a=>e.jsxs("button",{onClick:()=>{C(a.id),n(""),A(0)},type:"button",className:q("w-full flex items-center justify-between px-3 py-2 rounded-md text-left",m===a.id?"bg-primary-200 text-primary-800 dark:bg-primary-900/40 dark:text-primary-300":"hover:bg-primary-100 dark:hover:bg-primary-900/30"),children:[e.jsx("span",{children:$(a.name)}),m===a.id&&e.jsx(O,{className:"h-4 w-4"})]},`org-${a.id}`))})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:r("organization.users")}),G?e.jsx("div",{className:"flex items-center justify-center h-40",children:e.jsx(I,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(te,{placeholder:r("organization.searchUsers"),value:p,onChange:a=>y(a.target.value),className:"border border-gray-200 dark:border-gray-700 rounded-md dark:bg-gray-800 dark:text-gray-100"}),e.jsx(L,{className:"h-[200px] border border-gray-200 dark:border-gray-700 rounded-md p-2",children:e.jsxs("div",{className:"space-y-1",children:[P.map(a=>{var i;return e.jsxs("button",{onClick:()=>n(a.user.id),type:"button",className:q("w-full flex items-center justify-between px-3 py-2 rounded-md text-left",x===a.user.id?"bg-purple-200 text-purple-800 dark:bg-purple-900/40 dark:text-purple-300":"hover:bg-purple-100 dark:hover:bg-purple-900/30"),children:[e.jsx("span",{children:((i=a.user.name)==null?void 0:i.en)||a.user.email}),x===a.user.id&&e.jsx(O,{className:"h-4 w-4"})]},`emp-${a.id}`)}),P.length===0&&e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 text-center mt-2",children:r("organization.noUsersFound")})]})})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-2 px-2",children:[e.jsx(c,{type:"button",variant:"outline",size:"sm",onClick:()=>A(a=>Math.max(a-1,0)),disabled:z===0,children:"<"}),e.jsxs("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:[r("common.page")," ",z+1]}),e.jsx(c,{type:"button",variant:"outline",size:"sm",onClick:()=>{const a=(t==null?void 0:t.count)??0,i=Math.ceil(a/w)-1;A(N=>Math.min(N+1,i))},disabled:!(t!=null&&t.count)||(z+1)*w>=t.count,children:">"})]})]}),e.jsx(re,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c,{type:"button",variant:"outline",onClick:()=>{X(),s()},disabled:j,children:r("common.Cancel")}),e.jsx(c,{type:"submit",disabled:j,children:r(j?"organization.assigning":"organization.assignUser")})]})})]})]})})}function be(){const[l,s]=o.useState(0),g=10,{t:d}=_(),m=H(),[C,x]=o.useState(!1),{organizationsAdminsResponse:n,isLoading:j,isError:f,refetch:p}=Q("Admin",{take:g,skip:l*g,orderBy:"createdAt",order:"createdAt:Desc"}),y=r=>{s(r)};return j?e.jsx("div",{className:"p-6 flex items-center justify-center h-64",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(I,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:d("organization.loadingAdmins")})]})}):f?e.jsx("div",{className:"p-6 flex items-center justify-center h-64",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"text-red-500 font-medium",children:d("organization.errorLoadingAdmins")}),e.jsx(c,{variant:"outline",onClick:()=>p(),children:d("organization.retry")})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-6 space-y-6 dark:bg-gray-900",children:e.jsxs(ne,{className:"col-span-2 shadow-none border-none bg-transparent dark:bg-transparent px-0",children:[e.jsx(oe,{className:"flex flex-row justify-between items-center px-0",children:e.jsx(de,{className:"text-xl font-semibold dark:text-white",children:d("organization.organizationAdmins")})}),e.jsx(ce,{className:"px-0 dark:bg-transparent",children:e.jsx(le,{columns:fe(m),data:(n==null?void 0:n.items)||[],tableName:"Organization Admins",toolBarPosition:"right",extraToolbar:e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(c,{onClick:()=>x(!0),className:"bg-[#4A6CF7] hover:bg-[#3a5ad4] text-white px-5 py-2 rounded-md text-sm font-medium shadow-md",children:[e.jsx(pe,{className:"w-4 h-4 mr-2"}),d("organization.assignAdmin")]}),e.jsx(ie,{to:"/user-management/add_admin",children:e.jsxs(c,{className:"px-5 py-2 rounded-md text-sm font-medium shadow-md",children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),d("organization.addAdmin")]})})]}),itemCount:(n==null?void 0:n.count)||0,pageIndex:l,onPageChange:y,nextFunction:()=>y(l+1),prevFunction:()=>y(Math.max(l-1,0))})})]})}),e.jsx(ye,{isOpen:C,onClose:()=>x(!1),onSuccess:()=>{p(),h.success(d("organization.adminAssignedSuccess"))}})]})}const Be=()=>e.jsx(be,{});export{Be as default};
|