mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 23:40:56 +00:00
9 lines
28 KiB
JavaScript
9 lines
28 KiB
JavaScript
import{y as Te,ad as $e,K as F,N as _,j as e,bw as Le,bx as Fe,by as _e,bz as Ge,bA as He,bB as Re,aq as Ve,V as Ke,bC as Ze,ai as We,ap as J,W as qe,X as Qe,_ as Je,as as Xe,r as g,bD as Ye,aF as le,v as w,b8 as K,az as be,u as X,k as ea,I as xe,B as M,b6 as aa,t as I,f as ra,aA as ta,aB as sa,aC as na,aD as ia,aE as Q,bn as oa,aH as la,aR as da,bE as ca,aI as ma,aJ as ua,L as pa}from"./index-7T7TTikv.js";import{u as ve}from"./useOrganizations-CPt4mkXS.js";import{A as ga}from"./AdvancedTable-vWyUWUDX.js";import{A as je,h as Ne,a as Ce,b as we,c as ke,d as ze,e as Se,f as Ae,g as Oe}from"./alert-dialog-DwppaTz4.js";import{S as ha,a as xa,b as fa,c as ya,d as ba}from"./select--i8koVXg.js";import{a as va,u as ja,b as Na,c as Ca,d as wa,e as ka,f as za,g as Sa,h as Aa,i as Oa,j as Da}from"./useConfig-DEF3qQqh.js";import{u as Ba}from"./useUnit-CRt6YBLp.js";import{R as Pa,a as fe}from"./radio-group-C9tEhs3a.js";import{S as De}from"./switch-D9hx8CZw.js";import{u as Ea}from"./useArchived-5V0W60Gf.js";import{E as Ia}from"./ellipsis-DBW5EePE.js";import{E as Ma}from"./eye-DYwZYJcQ.js";import{S as Ua}from"./square-pen-Dh1zj83N.js";import{B as ye}from"./badge-D4t6Wb1T.js";import{S as Ta}from"./StatusCell-BAmClBhM.js";import{f as $a}from"./format-DvwV82px.js";import{U as La}from"./users-bn5-xqQf.js";import{C as Fa,a as _a,b as Ga,d as Ha}from"./card-_ldW-koX.js";import{L as Ra}from"./loader-CLp1W4Fa.js";import{P as Va}from"./plus-CC3ol2sL.js";import"./organizationsService-DIFVjoLn.js";import"./table-D_B7hhqb.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"./unitService-DTtkt-Pb.js";import"./Radio-D43EoWlg.js";import"./get-auto-contrast-value-Da6zqqWm.js";import"./InputsGroupFieldset-B16dMH0P.js";import"./Switch-ByfhjkDo.js";import"./positionService-BwPU5sNe.js";import"./useOrganizationAdmins-a9snXrfR.js";import"./use-toast-mIxmYSs4.js";import"./phone-w_VmAt3l.js";import"./en-US-Cc-9gH5A.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 Ka=[["path",{d:"M10 5a2 2 0 0 0-1.344.519l-6.328 5.74a1 1 0 0 0 0 1.481l6.328 5.741A2 2 0 0 0 10 19h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2z",key:"1yo7s0"}],["path",{d:"m12 9 6 6",key:"anjzzh"}],["path",{d:"m18 9-6 6",key:"1fp51s"}]],Za=Te("delete",Ka),[Wa,Z]=$e("Drawer component was not found in tree");var T={root:"m_f11b401e",header:"m_5a7c2c9",content:"m_b8a05bbd",inner:"m_31cd769a"};const qa={},Y=F((a,r)=>{const t=_("DrawerBody",qa,a),{classNames:i,className:l,style:m,styles:d,vars:u,...h}=t,n=Z();return e.jsx(Le,{ref:r,...n.getStyles("body",{classNames:i,style:m,styles:d,className:l}),...h})});Y.classes=T;Y.displayName="@mantine/core/DrawerBody";const Qa={},ee=F((a,r)=>{const t=_("DrawerCloseButton",Qa,a),{classNames:i,className:l,style:m,styles:d,vars:u,...h}=t,n=Z();return e.jsx(Fe,{ref:r,...n.getStyles("close",{classNames:i,style:m,styles:d,className:l}),...h})});ee.classes=T;ee.displayName="@mantine/core/DrawerCloseButton";const Ja={},ae=F((a,r)=>{const t=_("DrawerContent",Ja,a),{classNames:i,className:l,style:m,styles:d,vars:u,children:h,radius:n,__hidden:N,...j}=t,o=Z(),k=o.scrollAreaComponent||_e;return e.jsx(Ge,{...o.getStyles("content",{className:l,style:m,styles:d,classNames:i}),innerProps:o.getStyles("inner",{className:l,style:m,styles:d,classNames:i}),ref:r,...j,radius:n||o.radius||0,"data-hidden":N||void 0,children:e.jsx(k,{style:{height:"calc(100vh - var(--drawer-offset) * 2)"},children:h})})});ae.classes=T;ae.displayName="@mantine/core/DrawerContent";const Xa={},re=F((a,r)=>{const t=_("DrawerHeader",Xa,a),{classNames:i,className:l,style:m,styles:d,vars:u,...h}=t,n=Z();return e.jsx(He,{ref:r,...n.getStyles("header",{classNames:i,style:m,styles:d,className:l}),...h})});re.classes=T;re.displayName="@mantine/core/DrawerHeader";const Ya={},te=F((a,r)=>{const t=_("DrawerOverlay",Ya,a),{classNames:i,className:l,style:m,styles:d,vars:u,...h}=t,n=Z();return e.jsx(Re,{ref:r,...n.getStyles("overlay",{classNames:i,style:m,styles:d,className:l}),...h})});te.classes=T;te.displayName="@mantine/core/DrawerOverlay";function er(a){switch(a){case"top":return"flex-start";case"bottom":return"flex-end";default:return}}function ar(a){if(a==="top"||a==="bottom")return"0 0 calc(100% - var(--drawer-offset, 0rem) * 2)"}const rr={top:"slide-down",bottom:"slide-up",left:"slide-right",right:"slide-left"},tr={top:"slide-down",bottom:"slide-up",right:"slide-right",left:"slide-left"},sr={closeOnClickOutside:!0,withinPortal:!0,lockScroll:!0,trapFocus:!0,returnFocus:!0,closeOnEscape:!0,keepMounted:!1,zIndex:J("modal"),position:"left"},nr=qe((a,{position:r,size:t,offset:i})=>({root:{"--drawer-size":Je(t,"drawer-size"),"--drawer-flex":ar(r),"--drawer-height":r==="left"||r==="right"?void 0:"var(--drawer-size)","--drawer-align":er(r),"--drawer-justify":r==="right"?"flex-end":void 0,"--drawer-offset":Qe(i)}})),se=F((a,r)=>{const t=_("DrawerRoot",sr,a),{classNames:i,className:l,style:m,styles:d,unstyled:u,vars:h,scrollAreaComponent:n,position:N,transitionProps:j,radius:o,...k}=t,{dir:C}=Ve(),B=Ke({name:"Drawer",classes:T,props:t,className:l,style:m,classNames:i,styles:d,unstyled:u,vars:h,varsResolver:nr}),c=(C==="rtl"?tr:rr)[N];return e.jsx(Wa,{value:{scrollAreaComponent:n,getStyles:B,radius:o},children:e.jsx(Ze,{ref:r,...B("root"),transitionProps:{transition:c,...j},"data-offset-scrollbars":n===We.Autosize||void 0,unstyled:u,...k})})});se.classes=T;se.displayName="@mantine/core/DrawerRoot";const[ir,or]=Xe();function Be({children:a}){const[r,t]=g.useState([]),[i,l]=g.useState(J("modal"));return e.jsx(ir,{value:{stack:r,addModal:(m,d)=>{t(u=>[...new Set([...u,m])]),l(u=>typeof d=="number"&&typeof u=="number"?Math.max(u,d):u)},removeModal:m=>t(d=>d.filter(u=>u!==m)),getZIndex:m=>`calc(${i} + ${r.indexOf(m)} + 1)`,currentId:r[r.length-1],maxZIndex:i},children:a})}Be.displayName="@mantine/core/DrawerStack";const lr={},ne=F((a,r)=>{const t=_("DrawerTitle",lr,a),{classNames:i,className:l,style:m,styles:d,vars:u,...h}=t,n=Z();return e.jsx(Ye,{ref:r,...n.getStyles("title",{classNames:i,style:m,styles:d,className:l}),...h})});ne.classes=T;ne.displayName="@mantine/core/DrawerTitle";const dr={closeOnClickOutside:!0,withinPortal:!0,lockScroll:!0,trapFocus:!0,returnFocus:!0,closeOnEscape:!0,keepMounted:!1,zIndex:J("modal"),withOverlay:!0,withCloseButton:!0},E=F((a,r)=>{const{title:t,withOverlay:i,overlayProps:l,withCloseButton:m,closeButtonProps:d,children:u,opened:h,stackId:n,zIndex:N,...j}=_("Drawer",dr,a),o=or(),k=!!t||m,C=o&&n?{closeOnEscape:o.currentId===n,trapFocus:o.currentId===n,zIndex:o.getZIndex(n)}:{},B=i===!1?!1:n&&o?o.currentId===n:h;return g.useEffect(()=>{o&&n&&(h?o.addModal(n,N||J("modal")):o.removeModal(n))},[h,n,N]),e.jsxs(se,{ref:r,opened:h,zIndex:o&&n?o.getZIndex(n):N,...j,...C,children:[i&&e.jsx(te,{visible:B,transitionProps:o&&n?{duration:0}:void 0,...l}),e.jsxs(ae,{__hidden:o&&n&&h?n!==o.currentId:!1,children:[k&&e.jsxs(re,{children:[t&&e.jsx(ne,{children:t}),m&&e.jsx(ee,{...d})]}),e.jsx(Y,{children:u})]})]})});E.classes=T;E.displayName="@mantine/core/Drawer";E.Root=se;E.Overlay=te;E.Content=ae;E.Body=Y;E.Header=re;E.Title=ne;E.CloseButton=ee;E.Stack=Be;const cr=({organizationName:a,isActive:r,onConfirm:t,isLoading:i,trigger:l})=>e.jsxs(je,{children:[e.jsx(Ne,{asChild:!0,children:l}),e.jsxs(Ce,{children:[e.jsxs(we,{children:[e.jsxs(ke,{children:[r?"Deactivate":"Activate"," Organization"]}),e.jsxs(ze,{children:["Are you sure you want to ",r?"deactivate":"activate"," ",e.jsx("span",{className:"font-medium",children:a}),"? This action can be reversed later."]})]}),e.jsxs(Se,{children:[e.jsx(Ae,{disabled:i,className:"cursor-pointer",children:"Cancel"}),e.jsxs(Oe,{onClick:t,disabled:i,className:r?"bg-red-600 hover:bg-red-700 cursor-pointer":"",children:[i&&e.jsx(le,{className:"h-4 w-4 animate-spin"}),i?r?"Deactivating...":"Activating...":r?"Deactivate":"Activate"]})]})]})]}),mr=({organizationName:a,onDelete:r,onCancel:t,isLoading:i,trigger:l})=>e.jsxs(je,{children:[e.jsx(Ne,{asChild:!0,children:l}),e.jsxs(Ce,{children:[e.jsxs(we,{children:[e.jsx(ke,{children:w("organization.deleteOrganization")}),e.jsxs(ze,{children:[w("organization.confirmDelete")," ",e.jsx("strong",{children:a}),"? ",w("organization.cannotUndo")]})]}),e.jsxs(Se,{children:[e.jsx(Ae,{onClick:t,disabled:i,className:"cursor-pointer",children:w("common.Cancel")}),e.jsx(Oe,{className:"bg-red-600 hover:bg-red-700 text-white cursor-pointer",disabled:i,onClick:r,children:i?w("organization.deleting"):w("organization.delete")})]})]})]}),de=g.createContext({open:!1,setOpen:()=>{}});function ur({children:a,open:r,onOpenChange:t,defaultOpen:i=!1}){const[l,m]=g.useState(i),d=r!==void 0,u=d?r:l,h=g.useCallback(n=>{d||m(n),t==null||t(n)},[d,t]);return e.jsx(de.Provider,{value:{open:u,setOpen:h},children:a})}function pr({children:a,className:r,...t}){const{open:i,setOpen:l}=g.useContext(de);return e.jsx(E,{opened:i,onClose:()=>l(!1),position:"right",size:400,withCloseButton:!0,classNames:{content:K("p-6",r),overlay:"bg-black/50"},...t,children:a})}function gr({className:a,children:r,...t}){return e.jsx("div",{className:K("mb-4",a),...t,children:r})}function hr({className:a,children:r,...t}){return e.jsx("h2",{className:K("text-lg font-semibold",a),...t,children:r})}function xr({className:a,children:r,...t}){return e.jsx("p",{className:K("text-sm text-muted-foreground",a),...t,children:r})}function fr({className:a,children:r,...t}){return e.jsx("div",{className:K("mt-4 flex justify-end gap-2",a),...t,children:r})}function yr({children:a,asChild:r,className:t,...i}){const{setOpen:l}=g.useContext(de);return r&&g.isValidElement(a)?g.cloneElement(a,{onClick:m=>{var d,u;(u=(d=a.props).onClick)==null||u.call(d,m),l(!1)}}):e.jsx("button",{type:"button",className:K("cursor-pointer",t),onClick:()=>l(!1),...i,children:a})}const br=ur;function vr({manageOrgConfigOpen:a,setManageOrgConfigOpen:r,organizationId:t}){var me,ue,pe,ge;const{getList:i}=Ba(),[l,m]=g.useState(""),[d,u]=g.useState(""),[h,n]=g.useState(""),[N,j]=g.useState(!1),[o,k]=g.useState(null),{data:C}=t?i(t,{take:300,skip:0}):{data:void 0},B=be(),{t:c}=X(),{handleError:$}=ea(c),S=va(t),P=ja(t),[p,ie]=g.useState(!1),G=p?S.data:P.data,W=p?S.isLoading:P.isLoading,L=p?S.refetch:P.refetch,R=Na(),q=Ca(),oe=wa(),x=ka(),y=za(),f=Sa(),O=p?R.isPending||q.isPending:x.isPending||y.isPending,U=p?oe:f,b=(()=>{var D,A;const s=((A=(D=P.data)==null?void 0:D.data)==null?void 0:A.items)??[];return Array.isArray(s)?s.find(v=>((v==null?void 0:v.organizationId)??(v==null?void 0:v.organization_id))===t)??s[0]??null:null})(),z=(()=>{var D,A;if(!l)return null;const s=((A=(D=S.data)==null?void 0:D.data)==null?void 0:A.items)??[];return Array.isArray(s)?s.find(v=>((v==null?void 0:v.unitId)??(v==null?void 0:v.unit_id))===l)??null:null})();g.useEffect(()=>{p||(b!=null&&b.id&&o!==b.id?(k(b.id),u((b.maximumNumberOfUnits??0).toString()),j(!!b.canCreateBranchByItself)):b||j(!1))},[p,b,o]),g.useEffect(()=>{p&&z!=null&&z.id&&o!==z.id&&(k(z.id),u((z.numberOfSubUnits??0).toString()),n((z.numberOfEmployeesPerUnit??0).toString()))},[p,z,o]);const Pe=()=>{if(p&&!l){I.warning(c("superAdmin.messages.selectUnitWarning"));return}if(p?!d||!h:!d){I.warning(c("superAdmin.messages.fillAllFields"));return}if(p){const A={unitId:l,numberOfSubUnits:Number(d),numberOfEmployeesPerUnit:Number(h)},v=o||(z==null?void 0:z.id)||null;v?q.mutate({id:v,data:A},{onSuccess:()=>{I.success(c("superAdmin.messages.configUpdated")),H(),L()},onError:$}):R.mutate(A,{onSuccess:()=>{I.success(c("superAdmin.messages.configAdded")),H(),L()},onError:V=>ce(V)});return}const s={organizationId:t,maximumNumberOfUnits:Number(d),canCreateBranchByItself:N,...(b==null?void 0:b.canStartReceivingRecord)!==void 0&&{canStartReceivingRecord:b.canStartReceivingRecord}},D=o||(b==null?void 0:b.id)||null;D?y.mutate({id:D,data:s},{onSuccess:()=>{I.success(c("superAdmin.messages.configUpdated")),H(),L()},onError:$}):x.mutate(s,{onSuccess:()=>{I.success(c("superAdmin.messages.configAdded")),H(),L()},onError:A=>ce(A)})},ce=s=>{var v,V,he;const D=(v=s==null?void 0:s.response)==null?void 0:v.status,A=((he=(V=s==null?void 0:s.response)==null?void 0:V.data)==null?void 0:he.message)??(s==null?void 0:s.message)??"";if(D===400&&/duplicate/i.test(A)){I.warning(c("superAdmin.messages.configAlreadyExists")),L();return}$(s)},H=()=>{m(""),u(""),n(""),j(!!(b!=null&&b.canCreateBranchByItself)),k(null)},Ee=s=>{p?(k(s.id),m(s.unitId??""),u((s.numberOfSubUnits??0).toString()),n((s.numberOfEmployeesPerUnit??0).toString())):(k(s.id),u((s.maximumNumberOfUnits??0).toString()),j(!!s.canCreateBranchByItself))},Ie=s=>{s!=null&&s.id&&U.mutate(s.id,{onSuccess:()=>{I.success(c("superAdmin.messages.configDeleted")),o===s.id&&H(),L()},onError:$})},Me=c(p?"superAdmin.manageConfig.unit":"superAdmin.manageConfig.organization"),Ue=c(p?"superAdmin.manageConfig.unitBased":"superAdmin.manageConfig.organizationLevel");return e.jsx(br,{open:a,onOpenChange:r,children:e.jsxs(pr,{className:"max-h-[85vh] overflow-hidden flex flex-col top-1/6 bg-white dark:bg-gray-900",children:[e.jsxs("div",{className:"overflow-y-auto flex-1",children:[e.jsxs(gr,{className:"pb-4",children:[e.jsx(hr,{className:"text-lg text-primary-700 dark:text-primary-400",children:c("superAdmin.manageConfig.title",{type:Me})}),e.jsxs(xr,{className:"text-primary-600/80 dark:text-primary-300/80 space-y-3",children:[e.jsx("div",{children:c("superAdmin.manageConfig.description",{level:Ue})}),e.jsxs(Pa,{value:p?"unit":"org",onValueChange:s=>{ie(s==="unit"),H()},className:"inline-flex rounded-md bg-gray-100 dark:bg-gray-800 p-1",children:[e.jsx(fe,{value:"org",id:"org-radio",className:"hidden"}),e.jsx("label",{htmlFor:"org-radio",className:`cursor-pointer px-4 py-1 rounded-md text-sm font-medium transition-all
|
|
${p?"text-primary-700 dark:text-primary-300 hover:bg-primary-200 dark:hover:bg-primary-900/30":"bg-primary-600 text-white"}`,children:c("superAdmin.manageConfig.organization")}),e.jsx(fe,{value:"unit",id:"unit-radio",className:"hidden"}),e.jsx("label",{htmlFor:"unit-radio",className:`cursor-pointer px-4 py-1 rounded-md text-sm font-medium transition-all
|
|
${p?"bg-primary-600 text-white":"text-primary-700 dark:text-primary-300 hover:bg-primary-200 dark:hover:bg-primary-900/30"}`,children:c("superAdmin.manageConfig.unit")})]}),p&&((ue=(me=C==null?void 0:C.data)==null?void 0:me.items)==null?void 0:ue.length)>0&&e.jsxs("div",{className:"pt-2",children:[e.jsx("label",{className:"block text-sm font-medium text-primary-700 dark:text-primary-300",children:c("superAdmin.manageConfig.selectUnit")}),e.jsxs(ha,{value:l,onValueChange:s=>m(s),children:[e.jsx(xa,{className:"mt-1 border-primary-400 dark:border-primary-700 dark:bg-gray-800 dark:text-gray-100 focus:ring-primary-500",children:e.jsx(fa,{placeholder:c("superAdmin.manageConfig.selectUnitPlaceholder")})}),e.jsx(ya,{children:C==null?void 0:C.data.items.map(s=>e.jsx(ba,{value:s.id,children:B(s.name)},s.id))})]})]})]})]}),e.jsxs("div",{className:"px-6 space-y-4 pb-4",children:[e.jsxs("div",{className:`grid gap-4 ${p?"grid-cols-2":"grid-cols-1"}`,children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-primary-700 dark:text-primary-300",children:p?c("superAdmin.manageConfig.subOrganizations"):c("superAdmin.manageConfig.maxUnits","Maximum Number of Units")}),e.jsx(xe,{type:"number",min:"0",value:d,onChange:s=>u(s.target.value),placeholder:c("superAdmin.manageConfig.subOrgsPlaceholder"),className:"border-primary-400 dark:border-primary-700 dark:bg-gray-800 dark:text-gray-100 focus:ring-primary-500"})]}),p&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-primary-700 dark:text-primary-300",children:c("superAdmin.manageConfig.employeesPerOrg")}),e.jsx(xe,{type:"number",min:"0",value:h,onChange:s=>n(s.target.value),placeholder:c("superAdmin.manageConfig.employeesPlaceholder"),className:"border-primary-400 dark:border-primary-700 dark:bg-gray-800 dark:text-gray-100 focus:ring-primary-500"})]})]}),!p&&e.jsx("div",{className:"rounded-lg border border-primary-200 dark:border-primary-800 bg-primary-50/40 dark:bg-primary-900/10 p-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium text-primary-700 dark:text-primary-300",children:"Allow organization to create branches"}),e.jsx("p",{className:"text-xs text-primary-600/80 dark:text-primary-300/80",children:"Enable this if the organization should be allowed to create branches by itself."})]}),e.jsx(De,{checked:N,onCheckedChange:j})]})}),e.jsxs(M,{onClick:Pe,className:"w-full flex items-center gap-2 bg-primary-600 hover:bg-primary-700 text-white",disabled:O,children:[O&&e.jsx(le,{className:"h-4 w-4 animate-spin"}),o||!p&&(b!=null&&b.id)||p&&(z!=null&&z.id)?c("superAdmin.manageConfig.updateConfiguration"):c("superAdmin.manageConfig.addConfiguration")]}),e.jsx("div",{className:"border border-primary-300 dark:border-primary-800 rounded-lg p-3 space-y-3 mt-4",children:W?e.jsx("p",{className:"text-sm text-primary-600/70 text-center py-4",children:c("superAdmin.manageConfig.loading")}):(ge=(pe=G==null?void 0:G.data)==null?void 0:pe.items)!=null&&ge.length?e.jsx("div",{className:"max-h-48 overflow-y-auto",children:G.data.items.map(s=>{var D,A,v;return e.jsxs("div",{className:"flex items-center justify-between border-b border-primary-100 pb-2 last:border-none py-2",children:[e.jsxs("div",{children:[p&&e.jsx("p",{className:"font-semibold capitalize text-primary-700 text-sm",children:B((v=(A=(D=C==null?void 0:C.data)==null?void 0:D.items)==null?void 0:A.find(V=>V.id===s.unitId))==null?void 0:v.name)||s.unitId}),e.jsx("p",{className:"text-xs text-primary-600/80",children:p?e.jsxs(e.Fragment,{children:[s.numberOfSubUnits," ",c("superAdmin.manageConfig.subOrganizations")," •"," ",s.numberOfEmployeesPerUnit," ",c("superAdmin.manageConfig.employeesPerOrg")]}):e.jsxs(e.Fragment,{children:[c("superAdmin.manageConfig.maxUnits","Maximum Number of Units"),": ",s.maximumNumberOfUnits??0," • ","Branch creation:"," ",s.canCreateBranchByItself?"Allowed":"Not allowed"]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(M,{variant:"ghost",size:"sm",onClick:()=>Ee(s),className:"h-8 px-2 text-xs text-primary-700 dark:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/30",children:c("superAdmin.manageConfig.edit")}),e.jsx(M,{variant:"ghost",size:"sm",onClick:()=>Ie(s),disabled:U.isPending&&U.variables===s.id,className:"h-8 w-8 p-0 text-primary-700 dark:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/30",children:U.isPending&&U.variables===s.id?e.jsx(le,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(aa,{size:14})})]})]},s.id)})}):e.jsx("p",{className:"text-sm text-primary-600/70 text-center py-4",children:c("superAdmin.manageConfig.noConfigurations")})})]})]}),e.jsx(fr,{className:"pt-4 border-t border-primary-200 dark:border-primary-800 bg-primary-50/40 dark:bg-primary-900/10",children:e.jsx(yr,{asChild:!0,children:e.jsx(M,{variant:"outline",onClick:H,className:"w-full border-primary-500 dark:border-primary-700 text-primary-700 dark:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/30",children:c("superAdmin.manageConfig.close")})})})]})})}const jr=({rowData:a})=>{const[r,t]=g.useState(!1),{t:i}=X(),l=ra(),[m,d]=g.useState(!1),{activateOrganization:u,deactivateOrganization:h,isOrganizationActivating:n,isOrganizationDeactivating:N,deleteOrganization:j,isOrganizationDeleting:o}=ve("Org"),{softDeleteOrganization:k,isArchivingOrganization:C}=Ea(),B=()=>{t(!1),l(`/user-management/organizations/edit/${a==null?void 0:a.id}`)},c=()=>{t(!1),l(`/user-management/organizations/detail/${a==null?void 0:a.id}`)},$=()=>{t(!1),d(!0)},S=a.status==="Active";return e.jsxs("div",{className:"flex gap-3 align-center",children:[e.jsx(cr,{organizationName:a.name.en,isActive:S,onConfirm:()=>{S?h({id:a.id}):u({id:a.id})},isLoading:n||N,trigger:S?e.jsx(M,{variant:"outline",className:S?"text-red-600 dark:text-red-400 border-red-600 dark:border-red-500 hover:bg-red-50 dark:hover:bg-red-900/30":"text-primary-600 dark:text-primary-400 border-primary-600 dark:border-primary-500 hover:bg-primary-50 dark:hover:bg-primary-900/30",children:i("statusBar.deactivate")}):e.jsx(M,{variant:"outline",size:"sm",className:S?"text-red-600 dark:text-red-400 border-red-600 dark:border-red-500 hover:bg-red-50 dark:hover:bg-red-900/30":"text-primary-600 dark:text-primary-400 border-primary-600 dark:border-primary-500 hover:bg-primary-50 dark:hover:bg-primary-900/30",children:i("statusBar.activate")})}),e.jsxs(ta,{open:r,onOpenChange:t,children:[e.jsx(sa,{asChild:!0,children:e.jsxs(M,{variant:"ghost",className:"flex h-8 w-8 p-0 data-[state=open]:bg-muted","aria-haspopup":"menu","aria-expanded":r,children:[e.jsx(Ia,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Open menu"})]})}),e.jsxs(na,{align:"end",className:"w-[200px]",onInteractOutside:P=>{P.target.closest('[role="dialog"]')||t(!1)},children:[e.jsx(ia,{children:"Actions"}),e.jsxs(Q,{onSelect:c,children:[e.jsx(Ma,{className:"mr-2 h-4 w-4"}),i("organization.viewOrganization")]}),e.jsxs(Q,{onSelect:B,children:[e.jsx(Ua,{className:"mr-2 h-4 w-4"}),i("organization.editOrganization")]}),e.jsxs(Q,{onSelect:$,children:[e.jsx(oa,{className:"mr-2 h-4 w-4"}),i("organization.editOrganization")]}),e.jsxs(Q,{onSelect:()=>{t(!1),k(a.id)},disabled:C,className:"text-amber-700 focus:text-amber-700",children:[e.jsx(la,{className:"mr-2 h-4 w-4"}),i("archive.archiveOrganization","Archive Organization")]}),e.jsx(mr,{organizationName:a.name.en,onDelete:()=>{j({id:a.id})},onCancel:()=>{},isLoading:o,trigger:e.jsxs(M,{variant:"destructive",children:[e.jsx(Za,{className:"mr-2 h-4 w-4"}),i("organization.deleteOrganization")]})})]}),m&&e.jsx(vr,{manageOrgConfigOpen:m,setManageOrgConfigOpen:d,organizationId:a.id,isUnitConfig:!1})]})]})},Nr=({organizationId:a})=>{const{t:r}=X(),[t,i]=g.useState(null),[l,m]=g.useState(!1),[d,u]=g.useState(!0);g.useEffect(()=>{(async()=>{try{u(!0);const o=(await Aa(a)).data;if(o.count>0&&o.items&&o.items.length>0){const k=o.items[0];i(k)}else i(null)}catch{i(null)}finally{u(!1)}})()},[a]);const h=async N=>{try{m(!0);const j={canStartReceivingRecord:N,organizationId:a};if(t&&t.id)await Oa(t.id,j),i(o=>o?{...o,canStartReceivingRecord:N}:null);else{const o=await Da(j);i(o.data)}I.success(r(N?"organization.visibilityEnabled":"organization.visibilityDisabled"))}catch{I.error(r("organization.visibilityUpdateFailed"))}finally{m(!1)}};if(d)return e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("div",{className:"w-4 h-4 border-2 border-gray-300 dark:border-gray-600 border-t-primary-600 rounded-full animate-spin"})});const n=t?t.canStartReceivingRecord:!0;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-300",children:r(n?"organization.visible":"organization.hidden")}),e.jsx(De,{checked:n,onCheckedChange:h,disabled:l,className:"data-[state=checked]:bg-primary-600"})]}),l&&e.jsx("div",{className:"w-4 h-4 border-2 border-gray-300 dark:border-gray-600 border-t-primary-600 rounded-full animate-spin"})]})},Cr=[{accessorKey:"name.en",header:()=>w("organization.organizationName"),size:300,minSize:200,maxSize:400,cell:({row:a})=>{const r=a.original;return da.language,e.jsxs("div",{className:"font-medium",children:[r.parentId&&e.jsx("span",{className:"text-gray-400 dark:text-gray-500 mr-2",children:"└─"}),r.name.am]})}},{accessorKey:"createdAt",header:()=>w("organization.createdOn"),cell:({row:a})=>e.jsx("div",{className:"font-medium",children:$a(new Date(a.original.createdAt),"MMM dd, yyyy")})},{accessorKey:"activeEmployeeCount",header:()=>w("organization.numberOfUsers"),cell:({row:a})=>e.jsxs("div",{className:"font-medium flex items-center",children:[e.jsx(La,{className:"h-4 w-4 mr-2 text-gray-500 dark:text-gray-400"}),a.original.activeEmployeeCount!==void 0?a.original.activeEmployeeCount:"-"]})},{accessorKey:"adminsCount",header:()=>w("organization.assignedAdmin"),cell:({row:a})=>e.jsx(Ta,{id:a.original.id,adminsCount:a.original.adminsCount||0})},{id:"status",header:()=>w("userRecord.Status"),cell:({row:a})=>{const r=a.original;return e.jsx("div",{children:e.jsx(ye,{className:`${r.status==="Active"?"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":"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"} rounded-full px-6 py-1 font-medium`,children:r.status==="Active"?w("statusBar.activate"):w("statusBar.deactivate")})})}},{id:"isGovernmentOrganization",header:()=>w("organization.isGovernmentOrganization"),cell:({row:a})=>{const r=a.original;return e.jsx("div",{children:e.jsx(ye,{className:`${r.isGovernmentOrganization?"bg-blue-600 text-white hover:bg-blue-400":"bg-red-600 text-white hover:bg-red-400"} rounded-full px-6 py-1 font-medium`,children:r.isGovernmentOrganization===!0?w("common.yes"):w("common.no")})})}},{id:"visibility",header:()=>w("organization.visibilityToOthers"),cell:({row:a})=>{const r=a.original;return e.jsx(Nr,{organizationId:r.id})}},{id:"Actions",header:()=>w("userRecord.Actions"),cell:({row:a})=>{const r=a.original;return e.jsx(jr,{rowData:r})}}],wr=a=>{const{permissions:r}=ca();return a.some(t=>r.includes(t))},kr=({perms:a,fallback:r=null,children:t})=>wr(a)?t:r;function zr(){const[a,r]=g.useState(0),[t,i]=g.useState(new Set),[l,m]=g.useState(""),d=10;g.useEffect(()=>{r(0)},[l]);const{t:u}=X(),h=be(),{organizationsResponse:n,isLoading:N,refetch:j}=ve("Org",{take:1e3,skip:0,orderBy:"createdAt",order:"createdAt:Desc"}),o=x=>{r(x)},k=x=>{i(y=>{const f=new Set(y);return f.has(x)?f.delete(x):f.add(x),f})},C=g.useMemo(()=>{const x=new Map;return((n==null?void 0:n.items)||[]).forEach(y=>{x.set(y.id,y)}),x},[n==null?void 0:n.items]),B=x=>{const y=[],f=new Map;return x.forEach(O=>{O.parentId?(f.has(O.parentId)||f.set(O.parentId,[]),f.get(O.parentId).push(O)):y.push(O)}),{root:y,children:f}},c=g.useMemo(()=>(n==null?void 0:n.items)||[],[n==null?void 0:n.items]),{root:$,children:S}=B(c),P=l.trim().toLowerCase(),p=P.length>0,ie=g.useMemo(()=>p?c.filter(x=>{var y,f;return(((y=x.name)==null?void 0:y.en)||"").toLowerCase().includes(P)||(((f=x.name)==null?void 0:f.am)||"").toLowerCase().includes(P)}):[],[c,p,P]),G=p?ie:$,W=a*d,L=W+d,R=G.slice(W,L),q=g.useMemo(()=>{const x=[];return p?(R.forEach(y=>{const f=y.parentId?C.get(y.parentId):null;x.push({...y,isChild:!!y.parentId,parentName:f?f.name.en:void 0})}),x):(R.forEach(y=>{x.push(y),t.has(y.id)&&(S.get(y.id)||[]).forEach(O=>{x.push({...O,isChild:!0,parentName:y.name.en})})}),x)},[R,S,t,p,C]),oe=g.useMemo(()=>Cr.map(x=>"accessorKey"in x&&x.accessorKey==="name.en"?{...x,cell:({row:y})=>{const f=y.original,O=f.isChild||!1,U=f.parentName,b=S.has(f.id),z=t.has(f.id);return e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[b&&e.jsx(M,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 flex-shrink-0",onClick:()=>k(f.id),children:z?e.jsx(ma,{className:"h-4 w-4"}):e.jsx(ua,{className:"h-4 w-4"})}),e.jsxs("div",{className:"font-medium flex items-center gap-2 min-w-0 flex-1 overflow-hidden",children:[O&&e.jsx("span",{className:"text-gray-400 dark:text-gray-500 flex-shrink-0",children:"└─"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate",title:f.name.en,children:h(f.name)}),U&&e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400 font-normal truncate",title:`under ${U}`,children:["(under ",U,")"]})]})]})]})}}:x),[S,t,h]);return N?e.jsx("div",{children:e.jsx(Ra,{})}):e.jsx("div",{className:"p-6 space-y-6",children:e.jsxs(Fa,{className:"col-span-2 shadow-none border-none bg-transparent px-0",children:[e.jsx(_a,{className:"flex flex-row justify-between items-center px-0",children:e.jsx(Ga,{className:"text-xl font-semibold ",children:u("organization.organizations")})}),e.jsx(Ha,{className:"px-0",children:e.jsx(ga,{columns:oe,data:q,tableName:"Organizations",toolBarPosition:"right",itemCount:G.length,pageSize:d,onGlobalFilterChange:m,extraToolbar:e.jsx(kr,{perms:["create:organization","activate:organization"],children:e.jsx(pa,{to:"/user-management/organizations/new",children:e.jsxs(M,{className:"px-5 py-2 rounded-md text-sm font-medium shadow-md",children:[e.jsx(Va,{className:"w-4 h-4 mr-2"}),u("organization.newOrganization")]})})}),pageIndex:a,onPageChange:o,nextFunction:()=>o(a+1),prevFunction:()=>o(Math.max(a-1,0)),refresh:j})})]})})}const gt=()=>e.jsx(zr,{});export{gt as default};
|