Files
edr-platform/apps/edr-freight-web/backoffice/public/_um/assets/StatusCell-D7zi31G6.js
2026-06-13 14:32:26 +03:00

2 lines
7.1 KiB
JavaScript

import{l as m,w as u,m as V,u as X,k as Z,o as g,t as h,j as e,B as f,az as _,r as n,aJ as ee,aK as se,b7 as te,aL as re,aM as ae,aN as ne}from"./index-Db-xuq0b.js";import{u as ie}from"./useOrganizationAdmins-Bl-gbkwr.js";import{t as v}from"./use-toast-CdbbItn1.js";import{A as oe,h as ce,a as le,b as de,c as me,d as ue,e as ge,f as he,g as xe}from"./alert-dialog-B5Y0wlSz.js";import{u as pe}from"./useUnit-C4s9nepK.js";import{P as ye}from"./phone-Ce15UUGI.js";import{C as ve}from"./chevron-left-DCpEaNzo.js";import{E as fe}from"./eye-Bhud4znU.js";const Ue=async r=>m.post("/user-roles/assign-unit-admin-role",r,{headers:u()}),je=async r=>m.post("/user-roles/remove-unit-admin-role",r,{headers:u()}),Ne=async r=>m.post("/user-roles/assign-firsts-for-second",r,{headers:u()}),be=async r=>m.post("/user-roles/assign-seconds-for-first",r,{headers:u()}),Se=async r=>m.delete(`/user-roles/${r}`,{headers:u()}),Ae=async r=>m.post("/user-roles/remove-firsts-for-second",r,{headers:u()}),ke=async r=>m.post("/user-roles/remove-seconds-for-first",r,{headers:u()}),Fe=()=>{const r=V(),{t:a}=X(),{handleError:i}=Z(a),{mutateAsync:x,isPending:k}=g({mutationFn:t=>je(t),onSuccess:()=>{h.success("Unit admin role removed successfully"),r.invalidateQueries({queryKey:["organizationAdmins"]})},onError:t=>{i(t)}}),{mutate:F,isPending:p}=g({mutationFn:t=>Ne(t),onSuccess:()=>{h.success("Firsts assigned successfully")},onError:t=>{i(t)}}),{mutate:j,isPending:w}=g({mutationFn:t=>be(t),onSuccess:()=>{h.success("Seconds assigned successfully")},onError:t=>{i(t)}}),{mutate:R,isPending:N}=g({mutationFn:t=>Ae(t),onSuccess:()=>{h.success("Firsts removed successfully")},onError:t=>{i(t)}}),{mutate:b,isPending:S}=g({mutationFn:t=>ke(t),onSuccess:()=>{h.success("Seconds removed successfully")},onError:t=>{i(t)}}),{mutate:C,isPending:A}=g({mutationFn:t=>Se(t),onSuccess:()=>{h.success("Role deleted successfully")},onError:t=>{i(t)}});return{removeAdminRole:x,assignFirsts:F,assignSeconds:j,removeFirsts:R,removeSeconds:b,deleteRole:C,isRemoving:k,isAssigningFirsts:p,isAssigningSeconds:w,isRemovingFirsts:N,isRemovingSeconds:S,isDeleting:A}},we=({onConfirm:r,loading:a})=>e.jsxs(oe,{children:[e.jsx(ce,{asChild:!0,children:e.jsx(f,{variant:"destructive",size:"sm",disabled:a,children:"Remove"})}),e.jsxs(le,{children:[e.jsxs(de,{children:[e.jsx(me,{children:"Remove this admin?"}),e.jsx(ue,{children:"This action cannot be undone. This will permanently remove the admin from your organization."})]}),e.jsxs(ge,{children:[e.jsx(he,{disabled:a,children:"Cancel"}),e.jsx(xe,{onClick:r,disabled:a,className:"bg-red-600 hover:bg-red-700",children:a?"Removing...":"Yes, remove"})]})]})]}),Re=({organizationId:r})=>{var L,U,H;const{resendInvitation:a,getAllAdminById:i}=ie(),{removeAdminRole:x}=Fe(),k=_(),{getList:F}=pe(),{data:p}=F(r??"",{take:300,skip:0}),[j,w]=n.useState([]),[R,N]=n.useState(!0),[b,S]=n.useState(!0),[C,A]=n.useState(null),[t,T]=n.useState(null),[I,D]=n.useState(10),[c,P]=n.useState(0),[y,O]=n.useState(0),o=10,E=n.useRef(!1),z=(H=(U=(L=p==null?void 0:p.data)==null?void 0:L.items)==null?void 0:U[0])==null?void 0:H.id;n.useEffect(()=>{z&&r&&(async()=>{var l,M;try{N(!0);const d=await i(r||"",{take:I,skip:c});w(((l=d==null?void 0:d.data)==null?void 0:l.items)||[]),!E.current&&((M=d==null?void 0:d.data)!=null&&M.count)&&(O(d.data.count),E.current=!0)}catch{v({title:"Error",description:"Failed to fetch admins.",variant:"destructive"})}finally{N(!1)}})()},[I,c,z,r]);const $=()=>{const s=c+o;s<y&&(P(s),D(l=>l+o))},B=()=>{if(c>0){const s=Math.max(0,c-o);P(s),D(l=>Math.max(o,l-o))}},q=Math.floor(c/o)+1,K=Math.ceil(y/o),Q=c+o<y,W=c>0,J=()=>{D(10),P(0),E.current=!1},Y=async s=>{try{A(s),await x({unitId:z,userId:s}),J(),v({title:"Admin removed successfully.",variant:"success",style:{padding:"8px 16px",minHeight:"36px",color:"var(--primary-800)",backgroundColor:"var(--primary-100)",fontWeight:"600",fontSize:"14px"}})}catch{v({title:"Error",description:"Failed to remove admin.",variant:"destructive"})}finally{A(null)}},G=async s=>{try{S(!0),T(s.email||null),await a({email:s.email||"",phoneNumber:s.phoneNumber||""}),v({title:"Success",description:"Invitation sent successfully.",variant:"success",style:{padding:"8px 16px",minHeight:"36px",color:"var(--primary-800)",backgroundColor:"var(--primary-100)",fontWeight:"600",fontSize:"14px"}})}catch{v({title:"Error",description:"Failed to resend invitation.",variant:"destructive"})}finally{S(!1),T(null)}};return R?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading admins..."}):j.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No admins assigned."}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"space-y-3",children:j?.map(s=>e.jsxs("div",{className:"rounded-xl p-4 bg-white dark:bg-gray-800 shadow flex justify-between items-center border border-gray-200 dark:border-gray-700 transition hover:bg-primary-50 dark:hover:bg-primary-900/20",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:k(s==null?void 0:s.name)||"Unnamed"}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-300",children:s==null?void 0:s.email}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Username: ",s==null?void 0:s.username]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-gray-900 dark:text-gray-100",children:[e.jsx(ye,{className:"w-4 h-4 text-gray-500 dark:text-gray-400"}),e.jsx("span",{children:(s==null?void 0:s.phoneNumber)||"No phone number"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!s.hasSetPassword&&e.jsx(f,{className:"bg-white dark:bg-gray-900 text-primary-600 dark:text-primary-400 border border-primary-600 dark:border-primary-500 hover:bg-primary-600 dark:hover:bg-primary-700 hover:text-white",onClick:()=>G(s),disabled:b&&t===s.email,children:b&&t===s.email?"Sending...":"Resend"}),e.jsx(we,{onConfirm:()=>Y(s.id),loading:C===s.id})]})]},s.id))}),y>o&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs(f,{variant:"outline",size:"sm",onClick:B,disabled:!W,className:"flex items-center gap-2",children:[e.jsx(ve,{className:"w-4 h-4"}),"Previous"]}),e.jsxs("span",{className:"text-sm text-gray-600 dark:text-gray-300",children:["Page ",q," of ",K," (",y," total)"]}),e.jsxs(f,{variant:"outline",size:"sm",onClick:$,disabled:!Q,className:"flex items-center gap-2",children:["Next",e.jsx(ee,{className:"w-4 h-4"})]})]})]})},He=({id:r,adminsCount:a})=>{const[i,x]=n.useState(!1);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-medium",children:a>0?`${a} Admin${a!==1?"s":""}`:"No Admin"}),a>0&&e.jsxs(se,{open:i,onOpenChange:x,children:[e.jsx(te,{asChild:!0,children:e.jsx(f,{variant:"ghost",className:"p-1 h-auto w-auto",children:e.jsx(fe,{className:"h-4 w-4 text-gray-500 dark:text-gray-400 hover:text-primary"})})}),e.jsxs(re,{className:"max-w-md max-h-[80vh] overflow-y-auto",children:[e.jsx(ae,{children:e.jsx(ne,{children:"Assigned Admins"})}),e.jsx("div",{className:"max-h-[60vh] overflow-y-auto pr-2",children:e.jsx(Re,{organizationId:r})})]})]})]})};export{He as S,Ue as a};