PageSourceSearch

https://app.lucideld.com/assets/Y6U2v8Jq.js

js lucideld.com collected 2026-09-24 14:00:49 UTC 7,813 bytes, 1 lines download raw bytes

1import{b7 as e,bY as s,J as a,b$ as i,F as r,W as n,ar as t,aI as l,eG as o,cu as c,cw as d,c4 as u,eH as m,ct as p,bg as h}from"./CTfik_ah.js";import{a6 as g,a7 as v,a8 as j,a9 as x,ab as y,ac as f,ad as _,B as S,D as b,aw as w,b as N,d as A,e as E,g as C,a4 as q,o as D,n as K,L as P,a1 as O,h as V,i as G,j as F,k as I,l as z,W as L,a2 as T}from"./BXdH43xV.js";import{a as U,b as H,d as R,c as k,e as B}from"./RwfFbXmq.js";import{M as Q}from"./amYw8O-P.js";import{z as $,u as W}from"./0fQSEvJx.js";import{T as J}from"./DJXJQea0.js";import{T as M}from"./WeLnxxuS.js";import{c as Y}from"./8YFBBFey.js";import"./YXAyaVaa.js";import"./C1d3p_g9.js";import"./CIlsnfBz.js";const X=$.object({name:$.string().min(1,"Name is required"),vehicle_ids:$.array($.string()).min(1,"Please select at least one vehicle"),user_ids:$.array($.string())}),Z=({defaultValues:o,closeDialog:c})=>{const{data:d,isFetching:u}=k({id:null==o?void 0:o.group_id}),{isPending:m,mutate:p}=(()=>{const i=e();return s({mutationKey:["update-vehicle-group"],mutationFn:U,onSuccess:(e,s)=>{a.success("Group updated successfully!"),i.invalidateQueries({predicate:e=>"vehicle-groups"===e.queryKey[0]||"vehicle-group"===e.queryKey[0]&&e.queryKey[1]===s.group_id||"company-list"===e.queryKey[0]||"vehicle-group-simple-list"===e.queryKey[0]})},onError:e=>{a.error("Failed to update group")}})})(),h=i({resolver:W(X),defaultValues:{name:(null==o?void 0:o.name)??"",vehicle_ids:[],user_ids:[]}}),b=Boolean(null==o?void 0:o.group_id),{isPending:w,mutate:N}=(()=>{const i=e();return s({mutationKey:["add-vehicle-group"],mutationFn:H,onSuccess:()=>{a.success("Group added successfully!"),i.invalidateQueries({predicate:e=>"vehicle-groups"===e.queryKey[0]||"company-list"===e.queryKey[0]||"vehicle-group-simple-list"===e.queryKey[0]})},onError:e=>{a.error("Failed to add group")}})})(),A=w||m;return r.useEffect(()=>{if(!b)return;const e=null==d?void 0:d.data;if(!e)return;const s=(e.vehicles||[]).map(e=>e.vehicle_id),a=(e.users||[]).map(e=>e.user_id);h.reset({name:e.name??"",vehicle_ids:s,user_ids:a})},[h,d,b]),n.jsx(g,{...h,children:n.jsx("form",{onSubmit:h.handleSubmit(e=>{if(b){const s=null==d?void 0:d.data,a=((null==s?void 0:s.vehicles)||[]).map(e=>e.vehicle_id),i=Array.isArray(e.vehicle_ids)?e.vehicle_ids:[],r=new Set(a),n=new Set(i),t=i.filter(e=>!r.has(e)),l=a.filter(e=>!n.has(e)),u=((null==s?void 0:s.users)||[]).map(e=>e.user_id),m=Array.isArray(e.user_ids)?e.user_ids:[],h=new Set(u),g=new Set(m),v=m.filter(e=>!h.has(e)),j=u.filter(e=>!g.has(e)),x={group_id:String((null==o?void 0:o.group_id)??""),name:e.name??"",to_add:t,to_add_user:v,to_remove:l,to_remove_user:j};p(x,{onSuccess:()=>{null==c||c()}})}else{const s={name:e.name,vehicle_ids:Array.isArray(e.vehicle_ids)?e.vehicle_ids:[],user_ids:Array.isArray(e.user_ids)?e.user_ids:[]};N(s,{onSuccess:()=>{null==c||c()}})}}),className:"-mx-6 max-h-[80vh] overflow-y-auto px-6",children:n.jsxs("fieldset",{disabled:b&&u,className:"space-y-4",children:[n.jsx(v,{name:"name",control:h.control,rules:{required:"Name is required"},render:({field:e})=>n.jsxs(j,{children:[n.jsx(x,{children:"Name"}),n.jsx(y,{children:n.jsx(f,{placeholder:"Enter group name",...e})}),n.jsx(_,{})]})}),n.jsx(Q,{fieldName:"vehicle_ids"}),n.jsx("div",{className:"flex flex-wrap items-center gap-1",children:n.jsxs(S,{size:"sm",type:"submit",className:"ml-auto flex",disabled:A,children:[A&&n.jsx(t,{icon:l,className:"animate-spin",size:20}),b?"Update group":"Add group"]})})]})})})};function ee({defaultValues:e,children:s,open:a,onOpenChange:i}){const[l,d]=r.useState(!1),u=a??l,m=i??d,p=Boolean(null==e?void 0:e.group_id),h=p?"Edit group":"Add group";return n.jsxs(b,{open:u,onOpenChange:m,children:[void 0===a&&n.jsx(w,{asChild:!0,children:s??n.jsxs(S,{size:p?"icon":"default",variant:p?"ghost":"default",className:p?"size-6":"",children:[n.jsx(t,{icon:c,altIcon:o,showAlt:p}),!p&&h]})}),n.jsxs(N,{className:"sm:max-w-[80vw]",children:[n.jsxs(A,{children:[n.jsx(E,{children:h}),n.jsx(C,{})]}),n.jsx(Z,{defaultValues:e,closeDialog:()=>m(!1)})]})]})}function se({id:i,open:t,onOpenChange:l}){const[o,c]=r.useState(!1),d=t??o,u=l??c,{mutate:m,isPending:p}=(()=>{const i=e();return s({mutationKey:["delete-vehicle-group"],mutationFn:R,onSuccess:()=>{a.success("Group deleted successfully!"),i.invalidateQueries({predicate:e=>"vehicle-groups"===e.queryKey[0]||"company-list"===e.queryKey[0]||"vehicle-group-simple-list"===e.queryKey[0]})},onError:e=>{a.error("Failed to delete group")}})})();return n.jsx(q,{isOpen:d,isLoading:p,setOpenChange:u,title:"Delete Vehicle Group",description:"Are you sure you want to delete this vehicle group? This action cannot be undone.",onConfirm:()=>m(i,{onSuccess:()=>u(!1)}),shouldCloseOnConfirm:!1})}const ae=({row:e,canUpdate:s,canDelete:a})=>{const[i,l]=r.useState(null),c=e.status,p=e.group_id,h=e.name;return n.jsxs(n.Fragment,{children:[n.jsxs(M,{children:[s&&n.jsxs(Y,{onSelect:()=>l("edit"),children:[n.jsx(t,{icon:o}),"Edit"]}),a&&n.jsxs(Y,{variant:"destructive",onSelect:()=>l("delete"),children:[n.jsx(t,{icon:d}),"Delete"]}),s&&n.jsxs(Y,{onSelect:()=>l("toggle"),children:[n.jsx(t,{icon:c?u:m}),c?"Deactivate":"Activate"]})]}),s&&n.jsx(ee,{defaultValues:{group_id:p,name:h},open:"edit"===i,onOpenChange:e=>!e&&l(null)}),a&&n.jsx(se,{id:p,open:"delete"===i,onOpenChange:e=>!e&&l(null)}),s&&n.jsx(J,{activationDescription:"Activating the vehicle group will restore access to its members and related resources.",deactivationDescription:"Deactivating the vehicle group will remove access to its members. Related resources may be deactivated.",id:p,keyName:"vehicle_group",isActive:c,invalidate:"vehicle-groups",open:"toggle"===i,onOpenChange:e=>!e&&l(null)})]})},ie=()=>{var e;const{search:s,limit:a,page:i,status:r}=p({from:"/_protected/$companyId/settings/groups"}),t=h(),l=D(e=>e.hasPermission)("CREATE_VEHICLE_GROUP"),o=(e,s)=>{t({to:".",search:a=>({...a,[s]:e,page:1})})},{data:c,isPending:d}=B({page:i,limit:a,search:s,status:r}),u=(()=>{const e=D.getState().hasPermission,s=e("UPDATE_VEHICLE_GROUP"),a=e("DELETE_VEHICLE_GROUP"),i=[{header:"No",size:10,
1cell:({row:e,table:s})=>{const a=s.getState().pagination.pageSize;return s.getState().pagination.pageIndex*a+e.index+1}},{header:"Name",cell:({row:e})=>e.original.name||"No Name"},{header:"Vehicles",cell:({row:e})=>e.original.vehicles_count&&`${e.original.vehicles_count} Vehicles`},{header:"Status",cell:({row:e})=>{const s=e.original.status;return n.jsx(K,{variant:s?"success-secondary":"destructive-secondary",children:s?"Active":"Inactive"})}}];return(s||a)&&i.push({header:"Actions",size:10,cell:({row:e})=>n.jsx(ae,{row:e.original,canUpdate:s,canDelete:a})}),i})();return n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"w-nested-table flex items-end justify-between gap-2",children:[n.jsxs("div",{className:"flex items-end gap-2",children:[n.jsxs("div",{className:"grid shrink-0 basis-45 gap-2 sm:flex-0 sm:basis-64",children:[n.jsx(P,{children:"Search (by Group name)"}),n.jsx(O,{className:"w-full",value:s,placeholder:"Search by Group name",onChange:e=>e!==s&&o(e,"search")})]}),n.jsxs("div",{className:"grid shrink-0 basis-45 gap-2 sm:flex-0 sm:basis-64",children:[n.jsx(P,{children:"Status"}),n.jsxs(V,{value:r,onValueChange:e=>o(e,"status"),children:[n.jsx(G,{className:"w-full",children:n.jsx(F,{placeholder:"Status"})}),n.jsxs(I,{children:[n.jsx(z,{value:"all",children:"All"}),n.jsx(z,{value:"active",children:"Active"}),n.jsx(z,{value:"inactive",children:"Inactive"})]})]})]}),n.jsx(L,{queryKeys:["vehicle-groups"]})]}),l&&n.jsx(ee,{})]}),n.jsx(T,{page:i,limit:a,isLoading:d,columns:u,data:(null==(e=null==c?void 0:c.data)?void 0:e.groups)||[],totalPages:null==c?void 0:c.data.paging.totalPages,isNestedTable:!0})]})};function re(){return n.jsx(ie,{})}export{re as component};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.