Files
edr-platform/apps/edr-freight-web/backoffice/public/_um/assets/index-Ccb-1Emz.js
2026-06-20 09:52:24 +03:00

8 lines
17 KiB
JavaScript

import{y as be,r as c,az as me,k as ue,v as s,j as e,aS as Ce,I as ve,t as P,l as X,w as Y,m as fe,u as we,n as he,o as ge,f as Ne,aA as Se,aB as Me,B as te,aC as Pe,aD as Ae,aE as Z,b6 as Te,d as ke,L as De}from"./index-7T7TTikv.js";import{A as Ee}from"./AdvancedTable-vWyUWUDX.js";import{C as Le,a as Ie,b as Be,d as qe}from"./card-_ldW-koX.js";import{u as se,p as ye}from"./usePositionTypes-BnS1UB0m.js";import{A as ne,h as pe,a as ae,b as oe,c as ie,d as re,e as le,f as ce,g as de}from"./alert-dialog-DwppaTz4.js";import{u as ze}from"./useSettings-CvxIOArb.js";import{S as V,a as $,b as _,c as G,d as F}from"./select--i8koVXg.js";import{L as ee}from"./label-CABYEcfW.js";import{B as Ke}from"./badge-D4t6Wb1T.js";import{S as Ue}from"./search-y8VSu0lZ.js";import{S as He}from"./switch-D9hx8CZw.js";import{E as Oe}from"./ellipsis-vertical-CoMd89ns.js";import{S as Re}from"./square-pen-Dh1zj83N.js";import{E as Fe}from"./eye-DYwZYJcQ.js";import{f as xe}from"./format-DvwV82px.js";import{u as Qe}from"./useUnit-CRt6YBLp.js";import{P as Ve}from"./plus-CC3ol2sL.js";import"./table-D_B7hhqb.js";import"./chevron-left-G_a9-f9o.js";import"./utils-N2wtfq7C.js";import"./command-B6S1IvD4.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"./organizationService-B_C-b9EH.js";import"./Switch-ByfhjkDo.js";import"./InputsGroupFieldset-B16dMH0P.js";import"./en-US-Cc-9gH5A.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 $e=[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]],_e=be("arrow-left-right",$e),Ge=({isOpen:n,onClose:u,fromId:j,fromName:b,toId:g,toName:d,unitId:K,positionTypeOptions:v=[]})=>{var q,z;const[m,N]=c.useState([]),[C,a]=c.useState(""),[i,w]=c.useState(1),S=20,[r,A]=c.useState(j||""),[l,U]=c.useState(g||""),{updatePositionTypeFromTo:H,migratePositionsByPositions:L}=se(),{allScopedDepartments:y}=ze(),I=me(),{handleError:O}=ue(s),M=c.useMemo(()=>{const t=[...v],f=(x,J)=>{x&&(t.some(W=>W.value===x)||t.push({value:x,label:J||x}))};return f(j,b),f(g,d),t},[v,j,b,g,d]),T=((q=M.find(t=>t.value===r))==null?void 0:q.label)||b||r,k=((z=M.find(t=>t.value===l))==null?void 0:z.label)||d||l,R=()=>{A(l),U(r)},E=c.useMemo(()=>Array.isArray(y)?y.map(t=>({id:t.id,name:I(t.name)||"N/A"})):[],[y,I]),D=c.useMemo(()=>C.trim()?E.filter(t=>t.name.toLowerCase().includes(C.toLowerCase())):E,[E,C]),p=t=>{const{scrollTop:f,scrollHeight:x,clientHeight:J}=t.currentTarget;f+J>=x-5&&i*S<D.length&&w(W=>W+1)},B=t=>{m.includes(t)||(N(f=>[...f,t]),a(""),w(1))},Q=t=>{N(f=>f.filter(x=>x!==t))},o=()=>{if(!r||!l){P.error(s("migration.selectBothPositionTypes"));return}H.mutate({toId:l,fromId:r},{onSuccess:()=>{P.success(s("migration.allPositionsMigratedSuccess")),u()},onError:t=>{O(t)}})},h=()=>{if(!r||!l){P.error(s("migration.selectBothPositionTypes"));return}if(m.length===0){P.error(s("migration.selectAtLeastOnePosition"));return}L.mutate({id:l,data:{positionIds:m}},{onSuccess:()=>{P.success(s("migration.selectedPositionsMigratedSuccess",{count:m.length})),u()},onError:t=>{O(t)}})};return n?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-lg w-[500px] max-h-[80vh] overflow-y-auto p-6",children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:s("migration.title")}),M.length>0&&e.jsxs("div",{className:"mb-4 flex items-end gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(ee,{className:"text-sm font-medium",children:s("migration.fromPositionType")}),e.jsxs(V,{value:r,onValueChange:A,children:[e.jsx($,{className:"w-full mt-1",children:e.jsx(_,{placeholder:s("migration.selectSourcePositionType")})}),e.jsx(G,{children:M.filter(t=>t.value!==l).map(t=>e.jsx(F,{value:t.value,children:t.label},t.value))})]})]}),e.jsx("button",{type:"button",onClick:R,disabled:!r&&!l,title:s("migration.swap")||"Swap","aria-label":s("migration.swap")||"Swap from and to",className:"mb-0.5 p-2 rounded border border-gray-300 hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsx(_e,{className:"h-4 w-4 text-gray-600"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(ee,{className:"text-sm font-medium",children:s("migration.toPositionType")}),e.jsxs(V,{value:l,onValueChange:U,children:[e.jsx($,{className:"w-full mt-1",children:e.jsx(_,{placeholder:s("migration.selectTargetPositionType")})}),e.jsx(G,{children:M.filter(t=>t.value!==r).map(t=>e.jsx(F,{value:t.value,children:t.label},t.value))})]})]})]}),r&&l&&e.jsxs("p",{className:"mb-4 p-3 bg-blue-50 rounded border border-blue-200",children:[e.jsxs("span",{className:"text-sm text-gray-600",children:[s("migration.migrationPath"),":"]}),e.jsx("br",{}),e.jsx("strong",{className:"text-blue-700",children:T}),e.jsx("span",{className:"mx-2",children:"→"}),e.jsx("strong",{className:"text-primary-700",children:k})]}),e.jsx("div",{className:"mb-4",children:e.jsxs(ne,{children:[e.jsx(pe,{asChild:!0,children:e.jsx("button",{className:"w-full bg-primary-600 text-white px-4 py-2 rounded hover:bg-primary-700 transition disabled:opacity-50 disabled:cursor-not-allowed",disabled:H.isPending||!r||!l,children:s("migration.migrateAllPositions")})}),e.jsxs(ae,{children:[e.jsxs(oe,{children:[e.jsx(ie,{children:s("migration.confirmMigration")}),e.jsx(re,{children:s("migration.migrateAllDescription",{fromName:T,toName:k})})]}),e.jsxs(le,{children:[e.jsx(ce,{children:s("common.Cancel")}),e.jsx(de,{onClick:o,className:"bg-primary-600 hover:bg-primary-700",children:s("migration.yesMigrateAll")})]})]})]})}),e.jsxs("div",{children:[e.jsx(ee,{className:"mb-2 font-medium",children:s("migration.migrateSelectedPositions")}),m.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-3 p-2 border rounded bg-gray-50",children:m.map(t=>{const f=E.find(x=>x.id===t);return e.jsxs(Ke,{variant:"secondary",className:"flex items-center gap-1",children:[(f==null?void 0:f.name)||t,e.jsx(Ce,{className:"h-3 w-3 cursor-pointer hover:text-red-600",onClick:()=>Q(t)})]},t)})}),e.jsxs(V,{onValueChange:B,children:[e.jsx($,{children:e.jsx(_,{placeholder:s("migration.selectPositionsToMigrate")})}),e.jsxs(G,{style:{maxHeight:"300px",overflowY:"auto"},onScroll:p,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-background p-2 border-b",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ue,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4"}),e.jsx(ve,{type:"text",placeholder:s("migration.searchPositions"),value:C,onChange:t=>{t.stopPropagation(),a(t.target.value),w(1)},onClick:t=>t.stopPropagation(),className:"pl-10 h-9 text-sm"})]})}),D.length>0?D.slice(0,i*S).map(t=>e.jsx(F,{value:t.id,disabled:m.includes(t.id),children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("span",{children:t.name}),m.includes(t.id)&&e.jsxs("span",{className:"text-xs text-primary-600 ml-2",children:["✓ ",s("migration.selected")]})]})},t.id)):e.jsx("div",{className:"text-center py-4 text-sm text-muted-foreground",children:C?s("migration.noPositionsFound"):s("migration.noPositionsAvailable")})]})]}),e.jsxs(ne,{children:[e.jsx(pe,{asChild:!0,children:e.jsx("button",{className:"w-full mt-3 bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 transition disabled:opacity-50 disabled:cursor-not-allowed",disabled:L.isPending||m.length===0||!r||!l,children:s("migration.migrateSelectedButton",{count:m.length})})}),e.jsxs(ae,{children:[e.jsxs(oe,{children:[e.jsx(ie,{children:s("migration.confirmSelectedMigration")}),e.jsx(re,{children:s("migration.migrateSelectedDescription",{count:m.length,fromName:T,toName:k})})]}),e.jsxs(le,{children:[e.jsx(ce,{children:s("common.Cancel")}),e.jsx(de,{onClick:h,className:"bg-blue-600 hover:bg-blue-700",children:s("common.Confirm")})]})]})]})]}),e.jsx("button",{className:"mt-4 text-gray-500 hover:underline",onClick:u,children:s("common.Cancel")})]})}):null},Xe=async n=>X.get(`/position-type-configurations/list/${n}`,{headers:Y()}),Ye=async n=>X.get(`/position-type-configurations/${n}`,{headers:Y()}),Je=async n=>X.post("/position-type-configurations",n,{headers:Y()}),We=async(n,u)=>X.put(`/position-type-configurations/${n}`,u,{headers:Y()}),je=n=>{const u=fe(),{t:j}=we(),{handleError:b}=ue(j),{data:g,isLoading:d,isError:K,refetch:v}=he({queryKey:["positionTypeConfigurations",n],queryFn:async()=>(await Xe(n)).data,enabled:!!n}),m=a=>he({queryKey:["positionTypeConfiguration",a],queryFn:async()=>(await Ye(a)).data,enabled:!!a}),N=ge({mutationFn:async a=>(await Je(a)).data,onSuccess:()=>{u.invalidateQueries({queryKey:["positionTypeConfigurations",n]})},onError:a=>{b(a)}}),C=ge({mutationFn:async({id:a,payload:i})=>(await We(a,i)).data,onSuccess:()=>{u.invalidateQueries({queryKey:["positionTypeConfigurations",n]})},onError:a=>{b(a)}});return{configurations:(g==null?void 0:g.items)||[],totalConfigurations:(g==null?void 0:g.count)||0,isLoadingConfigurations:d,isConfigurationsError:K,refetchConfigurations:v,getConfigurationById:m,createConfiguration:N.mutateAsync,isCreatingConfiguration:N.isPending,updateConfiguration:C.mutateAsync,isUpdatingConfiguration:C.isPending}},Ze=({row:n,globalPositionTypes:u,onDelete:j,onToggle:b,isGlobal:g=!1})=>{const d=Ne(),[K,v]=c.useState(!1),[m,N]=c.useState(!1),[C,a]=c.useState(!1),[i,w]=c.useState(!1),S=me(),{handleError:r}=ue(s),A=fe(),{configurations:l,isLoadingConfigurations:U,updateConfiguration:H,isUpdatingConfiguration:L}=je((n==null?void 0:n.id)??null),y=l[0],I=(y==null?void 0:y.canReceiveRecord)??!1,O=(u==null?void 0:u.items.filter(p=>!p.unitId).map(p=>({label:S(p.name),value:p.id})))||[],M=!!n.unitId,T=()=>{d(`/user-management/position-management/edit/${n.id}`)},k=p=>{p.preventDefault(),v(!1),N(!0)},R=async()=>{try{w(!0),await ye.delete(n.id),P.success(s("common.DeletedSuccessfully")),a(!1),j&&await j()}catch(p){r(p),P.error(s("common.FailedToDelete"))}finally{w(!1)}},E=async p=>{if(!g)try{y!=null&&y.id?(await H({id:y.id,payload:{organizationId:y.organizationId,positionTypeId:y.positionTypeId,canReceiveRecord:p,timeframe:y.timeframe}}),P.success(s("incomingRecord.UpdatedSuccessfully")),A.invalidateQueries({queryKey:["positionTypeConfigurations",n.id]}),A.invalidateQueries({queryKey:["positionTypeConfiguration",n.id]})):(await(b==null?void 0:b(n.id,p)),P.success(s("incomingRecord.UpdatedSuccessfully")),A.invalidateQueries({queryKey:["positionTypeConfigurations",n.id]}),A.invalidateQueries({queryKey:["positionTypeConfiguration",n.id]}))}catch(B){r(B),P.error(s("incomingRecord.FailedToUpdate"))}},D="name"in n?n.name:{am:"",en:""};return e.jsxs(e.Fragment,{children:[e.jsxs(Se,{open:K,onOpenChange:v,children:[e.jsx(Me,{asChild:!0,children:e.jsxs(te,{variant:"ghost",className:"h-8 w-8 p-0",children:[e.jsx(Oe,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Open actions menu"})]})}),e.jsxs(Pe,{align:"end",onInteractOutside:p=>{p.target.closest('[role="dialog"]')||v(!1)},children:[e.jsx(Ae,{children:"Actions"}),M&&e.jsxs(Z,{onSelect:k,className:"cursor-pointer hover:!text-primary-700 !bg-transparent !transition-colors duration-200",children:[e.jsx(Re,{className:"mr-2 h-4 w-4 group-hover:text-white transition-colors duration-200"}),e.jsxs("span",{children:[" ",s("common.Migrate")]})]}),e.jsxs(Z,{onSelect:T,className:"cursor-pointer hover:!text-primary-700 !bg-transparent !transition-colors duration-200",children:[e.jsx(Fe,{className:"mr-2 h-4 w-4 group-hover:text-white transition-colors duration-200"}),e.jsx("span",{children:s("common.View")})]}),M&&e.jsxs(Z,{onSelect:()=>{v(!1),a(!0)},className:"cursor-pointer hover:!text-red-500 !bg-transparent !transition-colors duration-200",children:[e.jsx(Te,{className:"mr-2 h-4 w-4 group-hover:text-white transition-colors duration-200"}),e.jsx("span",{children:s("common.Delete")})]}),!g&&e.jsx("div",{className:"px-2 py-2 border-t mt-1",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:s("contentManagement.CanReceiveRecord")}),e.jsx(He,{checked:I,disabled:U||L,onCheckedChange:E})]})})]})]}),m&&e.jsx(Ge,{isOpen:m,onClose:()=>{N(!1)},toId:n.id,toName:S(D),positionTypeOptions:O}),e.jsx(ne,{open:C,onOpenChange:a,children:e.jsxs(ae,{children:[e.jsxs(oe,{children:[e.jsx(ie,{children:s("common.ConfirmDelete")}),e.jsx(re,{children:s("common.DeleteConfirmationMessage",{defaultValue:`Are you sure you want to delete "${S(D)}"? This action cannot be undone.`})})]}),e.jsxs(le,{children:[e.jsx(ce,{children:s("common.Cancel")}),e.jsx(de,{onClick:R,disabled:i,className:"bg-red-500 hover:bg-red-600",children:i?s("common.Deleting"):s("common.Delete")})]})]})})]})},et=({name:n})=>{const u=me();return e.jsx("span",{children:u(n)})},tt=(n,u,j,b,g)=>[{accessorKey:"name",header:()=>s("contentManagement.permissionName"),cell:({row:d})=>e.jsx(et,{name:d.original.name})},{accessorKey:"key",header:()=>s("contentManagement.key"),cell:({row:d})=>e.jsx("span",{children:d.original.key})},{accessorKey:"createdAt",header:()=>s("contentManagement.createdAt"),cell:({row:d})=>e.jsx("span",{children:xe(new Date(d.original.createdAt),"MMM d, yyyy HH:mm")})},{accessorKey:"updatedAt",header:()=>s("contentManagement.updatedAt"),cell:({row:d})=>e.jsx("span",{children:xe(new Date(d.original.updatedAt),"MMM d, yyyy HH:mm")})},{id:"actions",header:()=>s("userRecord.Actions"),cell:({row:d})=>e.jsx(Ze,{row:d.original,globalPositionTypes:u,onDelete:j,onToggle:b,isGlobal:g})}];function st(){var D,p,B,Q;const[n,u]=c.useState(0),j=10,[b,g]=c.useState(!1),[d,K]=c.useState(""),{createConfiguration:v}=je(),{user:m}=ke(),{getList:N}=Qe(),C=(p=(D=m==null?void 0:m.employee)==null?void 0:D[0])==null?void 0:p.organizationId,{data:a}=N(C??"",{take:300,skip:0}),[i,w]=c.useState("All");c.useEffect(()=>{var o,h;i||((h=(o=a==null?void 0:a.data)==null?void 0:o.items)!=null&&h.length?w(a.data.items[0].id):w("All"))},[a,i]),c.useEffect(()=>{u(0)},[d,i]);const S=o=>{u(o)},{positionTypeResponse:r,isLoading:A,positionTypeByUnitId:l,refetch:U,refetchPosition:H}=se({params:{take:1e3,skip:0,orderBy:"updatedAt:DESC"},unitId:i==="All"?void 0:i}),{positionTypeResponse:L,refetch:y}=se({params:{take:1e3,skip:0,orderBy:"updatedAt:DESC"},unitId:void 0}),I=async()=>{await Promise.all([i==="All"?U():H(),y()])},O=async(o,h)=>{!i||i==="All"||(await v({positionTypeId:o,timeframe:"yearly",organizationId:C}),await I())},M=c.useMemo(()=>tt(i==="All"?r:l,L,I,O,i==="All"),[i,r,l,L]),T=c.useMemo(()=>(i==="All"?r==null?void 0:r.items:l==null?void 0:l.items)||[],[i,r==null?void 0:r.items,l==null?void 0:l.items]),k=c.useMemo(()=>{const o=d.trim().toLowerCase();return o?T.filter(h=>{var f,x;const q=(((f=h==null?void 0:h.name)==null?void 0:f.en)||"").toLowerCase(),z=(((x=h==null?void 0:h.name)==null?void 0:x.am)||"").toLowerCase(),t=((h==null?void 0:h.key)||"").toLowerCase();return q.includes(o)||z.includes(o)||t.includes(o)}):T},[T,d]),R=c.useMemo(()=>{const o=n*j;return k.slice(o,o+j)},[k,n,j]);if(A)return e.jsx("div",{children:s("contentManagement.addUser")});const E=()=>{g(!0),ye.getAll({take:3e3}).then(o=>{var q,z;const h=(z=(q=o.data)==null?void 0:q.items)==null?void 0:z.map(t=>t.key);if(h&&h.length>0){const t=h.join(`
`),f=new Blob([t],{type:"text/plain"}),x=document.createElement("a");x.href=URL.createObjectURL(f),x.download="position_keys.txt",x.click(),URL.revokeObjectURL(x.href)}g(!1)})};return e.jsx("div",{className:"p-6 space-y-6",children:e.jsxs(Le,{className:"col-span-2 shadow-none border-none bg-transparent px-0",children:[e.jsxs(Ie,{className:"flex flex-row justify-between items-center px-0",children:[e.jsx(Be,{className:"text-xl font-semibold ",children:s("contentManagement.permissionType")}),e.jsx(te,{onClick:E,children:b?s("contentManagement.exporting"):s("contentManagement.exportTypes")})]}),((Q=(B=a==null?void 0:a.data)==null?void 0:B.items)==null?void 0:Q.length)>0&&e.jsxs("div",{className:"mb-4 w-1/2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Select Unit"}),e.jsxs(V,{value:i,onValueChange:o=>w(o),children:[e.jsx($,{className:"mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm",children:e.jsx(_,{placeholder:"Select a Unit"})}),e.jsxs(G,{children:[e.jsx(F,{value:"All",children:"All"},"all"),a==null?void 0:a.data.items.map(o=>e.jsx(F,{value:o.id,children:o.name.en||o.name.am},o.id))]})]})]}),e.jsx(qe,{className:"px-0",children:e.jsx(Ee,{columns:M,data:R,tableName:"Positions",toolBarPosition:"right",itemCount:k.length,onGlobalFilterChange:K,extraToolbar:e.jsx(De,{to:"/user-management/position-management/new",children:e.jsxs(te,{className:"px-5 py-2 rounded-md text-sm font-medium shadow-md",children:[e.jsx(Ve,{className:"w-4 h-4 mr-2"}),s("contentManagement.newPermission")]})}),pageIndex:n,onPageChange:S,nextFunction:()=>S(n+1),prevFunction:()=>S(Math.max(n-1,0))})})]})})}const It=()=>e.jsxs("div",{className:"p-6",children:[e.jsx("h2",{className:"text-2xl font-bold mb-4",children:s("contentManagement.permissionManagement")}),e.jsx(st,{})]});export{It as default};