PageSourceSearch

https://bizvanguard.ai/assets/DeliveryTickets-DSEDX5Sb.js

js bizvanguard.ai collected 2026-10-05 13:48:02 UTC 11,292 bytes, 1 lines download raw bytes

1import{u as ue,r as a,j as e}from"./vendor-react-zwv87yMD.js";import{u as me,a as A,b as I}from"./vendor-query-DYq8g7OI.js";import{T as xe,a as he,b as u,c as pe}from"./tabs-Dd8Qm6LV.js";import{B as n}from"./button-DlBDuKbo.js";import{B as ge}from"./badge-QivbhJml.js";import{A as U,a as H,b as _,c as M,d as P,e as B,f as K,g as Q}from"./alert-dialog-P2RRIvov.js";import{d as b}from"./delivery-tickets-T0DTAAqI.js";import{d as ve}from"./drivers-DMmSfnK_.js";import{c as je}from"./contacts-DebKsgyA.js";import{u as fe}from"./authStore-Bv6p2Ne2.js";import{u as Ne}from"./useOrgTimezone-C1UagyKl.js";import{a as be}from"./timezoneFormatters-Lg56xFv0.js";import{c as De,b as ye,L as $}from"./vendor-router-DimZLiZb.js";import"./vendor-charts-CtrTLS4K.js";import"./vendor-i18n-BdYkS11p.js";import"./vendor-ui-CfDMlrKu.js";import"./vendor-pdf-DQuePnfN.js";import"./vendor-state-ByI9XJey.js";import"./vendor-editor-C_dhmuey.js";import"./utils-BXSzAfFa.js";import"./api-client-wl3SCNAO.js";import"./i18n-CwjSIy0a.js";import"./vendor-icons-bLSWzydc.js";import"./employeeAuthStore-lYSKMuhw.js";const Ce={DRAFT:"bg-gray-100 text-gray-700",SCHEDULED:"bg-blue-100 text-blue-700",IN_TRANSIT:"bg-yellow-100 text-yellow-700",DELIVERED:"bg-green-100 text-green-700",INVOICED:"bg-purple-100 text-purple-700",CANCELLED:"bg-red-100 text-red-700"};function Ye(){const{t}=ue("delivery"),m=De(),D=me(),[G]=ye(),{permissions:Y,currentOrganizationId:y}=fe(),J=Ne(),f=Y.includes("MANAGE_DELIVERY_TICKETS"),[x,W]=a.useState(G.get("status")||"all"),[N,L]=a.useState(""),[h,w]=a.useState(""),[p,F]=a.useState(""),[g,R]=a.useState(""),[v,z]=a.useState(""),[l,j]=a.useState(new Set),[C,E]=a.useState(null),[X,S]=a.useState(!1),{data:r=[],isLoading:Z}=A({queryKey:["delivery-tickets",y],queryFn:()=>b.getAll(),staleTime:60*1e3}),{data:ee=[]}=A({queryKey:["drivers",y],queryFn:()=>ve.getAll(),staleTime:300*1e3}),{data:se=[]}=A({queryKey:["contacts",y],queryFn:()=>je.getAll(),staleTime:300*1e3}),te=I({mutationFn:b.delete,onSuccess:()=>{D.invalidateQueries({queryKey:["delivery-tickets"]}),E(null)}}),V=I({mutationFn:b.cancel,onSuccess:()=>{D.invalidateQueries({queryKey:["delivery-tickets"]})}}),T=I({mutationFn:async s=>{await Promise.all(s.map(i=>b.cancel(i)))},onSuccess:()=>{D.invalidateQueries({queryKey:["delivery-tickets"]}),S(!1),j(new Set)}}),c=a.useMemo(()=>r.filter(s=>{var i,k,O,q;if(x!=="all"&&s.status!==x||h&&s.driverId!==h||p&&s.contactId!==p||g&&s.scheduledDate.split("T")[0]<g||v&&s.scheduledDate.split("T")[0]>v)return!1;if(N){const o=N.toLowerCase();return s.ticketNumber.toLowerCase().includes(o)||((i=s.contact)==null?void 0:i.name.toLowerCase().includes(o))||((O=(k=s.contact)==null?void 0:k.company)==null?void 0:O.toLowerCase().includes(o))||((q=s.deliveryAddress)==null?void 0:q.toLowerCase().includes(o))}return!0}),[r,x,h,p,g,v,N]),d=a.useMemo(()=>({all:r.length,DRAFT:r.filter(s=>s.status==="DRAFT").length,SCHEDULED:r.filter(s=>s.status==="SCHEDULED").length,IN_TRANSIT:r.filter(s=>s.status==="IN_TRANSIT").length,DELIVERED:r.filter(s=>s.status==="DELIVERED").length,INVOICED:r.filter(s=>s.status==="INVOICED").length,CANCELLED:r.filter(s=>s.status==="CANCELLED").length}),[r]),ae=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(s/100),le=s=>be(s,J),re=s=>{const i=new Set(l);i.has(s)?i.delete(s):i.add(s),j(i)},ne=()=>{l.size===c.length?j(new Set):j(new Set(c.map(s=>s.id)))},ie=()=>{C&&te.mutate(C)},ce=()=>{const s=Array.from(l);T.mutate(s)},de=()=>{w(""),F(""),R(""),z(""),L("")},oe=h||p||g||v;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between sm:items-start gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl sm:text-3xl font-bold",children:t("list.title")}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground mt-1",children:t("list.subtitle")})]}),f&&e.jsx(n,{onClick:()=>m("/dashboard/delivery-tickets/new"),children:t("list.newTicket")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx("input",{type:"text",placeholder:t("list.searchPlaceholder"),value:N,onChange:s=>L(s.target.value),className:"px-3 py-2 border rounded-md w-full max-w-xs"}),e.jsxs("select",{value:h,onChange:s=>w(s.target.value),className:"px-3 py-2 border rounded-md",children:[e.jsx("option",{value:"",children:t("list.allDrivers")}),ee.map(s=>e.jsxs("option",{value:s.id,children:[s.firstName," ",s.lastName]},s.id))]}),e.jsxs("select",{value:p,onChange:s=>F(s.target.value),className:"px-3 py-2 border rounded-md",children:[e.jsx("option",{value:"",children:t("list.allCustomers")}),se.filter(s=>s.type==="customer").map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("list.fromLabel")}),e.jsx("input",{type:"date",value:g,onChange:s=>R(s.target.value),className:"px-3 py-2 border rounded-md"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("list.toLabel")}
1),e.jsx("input",{type:"date",value:v,onChange:s=>z(s.target.value),className:"px-3 py-2 border rounded-md"})]}),oe&&e.jsx(n,{variant:"ghost",size:"sm",onClick:de,children:t("list.clearFilters")})]})]}),l.size>0&&e.jsxs("div",{className:"flex items-center gap-4 p-3 bg-muted/50 rounded-lg",children:[e.jsx("span",{className:"text-sm font-medium",children:t("list.selectedCount",{count:l.size})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(n,{variant:"outline",size:"sm",onClick:()=>S(!0),className:"text-destructive border-destructive hover:bg-destructive/10",children:t("list.cancelSelected")}),e.jsx(n,{variant:"ghost",size:"sm",onClick:()=>j(new Set),children:t("list.clearSelection")})]})]}),e.jsxs(xe,{value:x,onValueChange:s=>W(s),children:[e.jsxs(he,{className:"flex-wrap h-auto",children:[e.jsxs(u,{value:"all",children:[t("list.tabAll")," (",d.all,")"]}),e.jsxs(u,{value:"SCHEDULED",children:[t("status.SCHEDULED")," (",d.SCHEDULED,")"]}),e.jsxs(u,{value:"IN_TRANSIT",children:[t("status.IN_TRANSIT")," (",d.IN_TRANSIT,")"]}),e.jsxs(u,{value:"DELIVERED",children:[t("status.DELIVERED")," (",d.DELIVERED,")"]}),e.jsxs(u,{value:"INVOICED",children:[t("status.INVOICED")," (",d.INVOICED,")"]}),e.jsxs(u,{value:"DRAFT",children:[t("status.DRAFT")," (",d.DRAFT,")"]})]}),e.jsx(pe,{value:x,className:"mt-4",children:Z?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:t("list.loading")}):c.length===0?e.jsxs("div",{className:"py-12 text-center border rounded-lg bg-card",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:t("list.empty")}),f&&e.jsx(n,{onClick:()=>m("/dashboard/delivery-tickets/new"),children:t("list.createFirst")})]}):e.jsx("div",{className:"border rounded-lg bg-card",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"border-b bg-muted/30",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"px-4 py-3 font-medium w-10",children:e.jsx("input",{type:"checkbox",checked:l.size===c.length&&c.length>0,onChange:ne,className:"rounded"})}),e.jsx("th",{className:"px-4 py-3 font-medium",children:t("table.ticketNumber")}),e.jsx("th",{className:"px-4 py-3 font-medium",children:t("table.customer")}),e.jsx("th",{className:"px-4 py-3 font-medium",children:t("table.scheduled")}),e.jsx("th",{className:"px-4 py-3 font-medium",children:t("table.driver")}),e.jsx("th",{className:"px-4 py-3 font-medium",children:t("table.status")}),e.jsx("th",{className:"px-4 py-3 font-medium text-right",children:t("table.total")}),f&&e.jsx("th",{className:"px-4 py-3 font-medium text-right",children:t("table.actions")})]})}),e.jsx("tbody",{children:c.map(s=>e.jsxs("tr",{className:`border-b hover:bg-accent/50 ${l.has(s.id)?"bg-accent/30":""}`,children:[e.jsx("td",{className:"px-4 py-3",children:e.jsx("input",{type:"checkbox",checked:l.has(s.id),onChange:()=>re(s.id),className:"rounded"})}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx($,{to:`/dashboard/delivery-tickets/${s.id}`,className:"font-medium text-primary hover:underline",children:s.ticketNumber}),s.contract&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s.contract.name})]}),e.jsx("td",{className:"px-4 py-3",children:s.contact?e.jsxs($,{to:`/dashboard/contacts/${s.contactId}`,className:"hover:underline",children:[e.jsx("div",{children:s.contact.name}),s.contact.company&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s.contact.company})]}):e.jsx("span",{className:"text-muted-foreground",children:t("table.unknown")})}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{children:le(s.scheduledDate)}),s.scheduledTime&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s.scheduledTime})]}),e.jsx("td",{className:"px-4 py-3",children:s.driver?e.jsxs("span",{children:[s.driver.firstName," ",s.driver.lastName]}):e.jsx("span",{className:"text-muted-foreground",children:t("table.unassigned")})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(ge,{className:Ce[s.status],children:t(`status.${s.status}`)})}),e.jsx("td",{className:"px-4 py-3 text-right font-medium",children:ae(s.total)}),f&&e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex gap-2 justify-end",children:[s.status==="DRAFT"&&e.jsx(n,{variant:"outline",size:"sm",onClick:()=>m(`/dashboard/delivery-tickets/${s.id}/edit`),children:t("actions.edit")}),s.status==="SCHEDULED"&&e.jsx(n,{variant:"outline",size:"sm",onClick:()=>m(`/dashboard/delivery-tickets/${s.id}`),children:t("actions.view")}),["DRAFT","SCHEDULED"].includes(s.status)&&e.jsx(n,{variant:"outline",size:"sm",className:"text-destructive border-destructive hover:bg-destructive/10",onClick:()=>V.mutate(s.id),disabled:V.isPending,children:t("actions.cancel")}),s.status==="DRAFT"&&e.jsx(n,{variant:"outline",size:"sm",className:"text-destructive border-destructive hover:bg-destructive/10",onClick:()=>E(s.id),children:t("actions.delete")}),["DELIVERED","INVOICED","CANCELLED"].includes(s.status)&&e.jsx(n,{variant:"outline",size:"sm",onClick:()=>m(`/dashboard/delivery-tickets/${s.id}`),children:t("actions.view")})]})})]},s.id))})]})})})})]}),e.jsx(U,{open:!!C,onOpenChange:()=>
1E(null),children:e.jsxs(H,{children:[e.jsxs(_,{children:[e.jsx(M,{children:t("deleteDialog.title")}),e.jsx(P,{children:t("deleteDialog.description")})]}),e.jsxs(B,{children:[e.jsx(K,{children:t("actions.cancel")}),e.jsx(Q,{onClick:ie,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:t("actions.delete")})]})]})}),e.jsx(U,{open:X,onOpenChange:S,children:e.jsxs(H,{children:[e.jsxs(_,{children:[e.jsx(M,{children:t("bulkCancel.title",{count:l.size})}),e.jsx(P,{children:t("bulkCancel.description",{count:l.size})})]}),e.jsxs(B,{children:[e.jsx(K,{children:t("bulkCancel.keep")}),e.jsx(Q,{onClick:ce,disabled:T.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:T.isPending?t("bulkCancel.cancelling"):t("bulkCancel.confirmAll")})]})]})})]})}export{Ye as default};

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.