PageSourceSearch

https://endoftenancycleaning.site/assets/AdminDispatch-d66Xb3Yi.js

js endoftenancycleaning.site collected 2026-10-07 00:54:46 UTC 7,066 bytes, 1 lines download raw bytes

1import{r as c,J as e}from"./vendor-BES_ooCv.js";import{J as N,C as n,B as y}from"./index-Bvy0P6lC.js";import{C as p}from"./card-DYLuWcbP.js";import w from"./AdminMap-CqfpbaWR.js";import{an as _,ac as E,m as k}from"./icons-wPotDBXb.js";import"./maplibre--9FVgYzZ.js";import"./datefns-DVp9_6zc.js";import"./radix-CiT1R7ZI.js";import"./query-XefPi0rm.js";import"./router-lIC-Scp8.js";import"./helmet-BmunKl-J.js";import"./supabase-B2M7Kmhn.js";import"./geocode-CD4m0DfR.js";const C=[{key:"pending",label:"Pending",activeBg:"bg-amber-100",activeText:"text-amber-800"},{key:"confirmed",label:"Scheduled",activeBg:"bg-blue-100",activeText:"text-blue-800"},{key:"in_progress",label:"En Route",activeBg:"bg-[#0E5E5C]/15",activeText:"text-[#0E5E5C]"},{key:"completed",label:"Completed",activeBg:"bg-green-100",activeText:"text-green-800"}];function z(){const{toast:d}=N(),[o,u]=c.useState([]),[m,f]=c.useState([]),[g,x]=c.useState(null),l=async()=>{const[{data:s},{data:t}]=await Promise.all([n.from("bookings").select("*").order("preferred_date",{ascending:!0}).limit(200),n.from("staff").select("*").eq("is_active",!0)]);u(s||[]),f(t||[])};c.useEffect(()=>{l();const s=n.channel("dispatch-board").on("postgres_changes",{event:"*",schema:"public",table:"bookings"},l).on("postgres_changes",{event:"INSERT",schema:"public",table:"dispatch_events"},t=>{var r;const a=t.new;a.event_type==="ai_suggestion"&&d({title:"AI suggestion ready",description:(r=a.metadata)==null?void 0:r.reason})}).subscribe();return()=>{n.removeChannel(s)}},[]);const h=async(s,t)=>{var r;const a=(r=o.find(i=>i.id===s))==null?void 0:r.status;await n.from("bookings").update({status:t}).eq("id",s),await n.from("dispatch_events").insert({booking_id:s,event_type:"status_change",from_value:a,to_value:t})},b=async s=>{x(s);const{data:t,error:a}=await n.functions.invoke("ai-dispatch-suggest",{body:{booking_id:s}});if(x(null),a)return d({title:"AI error",description:a.message,variant:"destructive"});t!=null&&t.recommendation&&d({title:`AI suggests ${t.recommendation.staff_name}`,description:t.recommendation.reason})},v=async(s,t)=>{if(!confirm(`Delete service for ${t}? This cannot be undone.`))return;const{error:a}=await n.from("bookings").delete().eq("id",s);if(a)return d({title:"Delete failed",description:a.message,variant:"destructive"});d({title:"Service deleted"})};return e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"rounded-lg border border-admin-border bg-[#0E5E5C]/5 p-5 mb-6 flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-heading text-3xl text-foreground",children:"Dispatch Board"}),e.jsxs("p",{className:"text-muted-foreground text-sm mt-1",children:["Realtime job pipeline · ",o.length," bookings"]})]}),e.jsx("button",{onClick:l,className:"text-muted-foreground hover:text-foreground p-2 rounded hover:bg-white",children:e.jsx(_,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[420px_1fr] gap-4",children:[e.jsxs(p,{className:"border-admin-border p-0 overflow-hidden flex flex-col max-h-[calc(100vh-200px)]",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-admin-border bg-[#0E5E5C]/5 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Dispatched Staff"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[o.filter(s=>s.assigned_staff_id&&s.status!=="completed").length," active assignments"]})]}),e.jsxs("span",{className:"text-xs bg-[#0E5E5C]/10 text-[#0E5E5C] px-2 py-0.5 rounded-full font-semibold",children:[m.length," staff"]})]}),e.jsxs("div",{className:"overflow-y-auto flex-1 divide-y divide-admin-border",children:[m.map(s=>{var a;const t=o.filter(r=>r.assigned_staff_id===s.id&&r.status!=="completed");return e.jsxs("div",{className:"p-3 hover:bg-[#0E5E5C]/5 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-[#0E5E5C
1] text-white flex items-center justify-center text-xs font-semibold shrink-0",children:(a=s.name)==null?void 0:a.split(" ").map(r=>r[0]).slice(0,2).join("")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-foreground truncate",children:s.name}),e.jsx("div",{className:"text-[11px] text-muted-foreground truncate",children:s.phone||s.email})]})]}),e.jsx("span",{className:"text-[10px] bg-[#0E5E5C]/10 text-[#0E5E5C] px-1.5 py-0.5 rounded font-semibold",children:t.length})]}),t.length===0?e.jsx("div",{className:"text-[11px] text-muted-foreground italic pl-10",children:"No active jobs"}):e.jsx("div",{className:"space-y-2 pl-10",children:t.map(r=>e.jsxs("div",{className:"rounded border border-admin-border bg-white/40 p-2 group",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-1",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] text-foreground truncate font-medium",children:r.customer_name}),e.jsxs("div",{className:"text-[10px] text-muted-foreground truncate",children:[new Date(r.preferred_date).toLocaleDateString(),r.preferred_time?` · ${r.preferred_time.slice(0,5)}`:""]})]}),e.jsx("button",{onClick:()=>v(r.id,r.customer_name),className:"opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-red-600 p-0.5 rounded",children:e.jsx(E,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:C.map(i=>{const j=(r.status||"pending")===i.key;return e.jsx("button",{onClick:()=>h(r.id,i.key),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${j?`${i.activeBg} ${i.activeText} border-transparent`:"bg-white text-muted-foreground border-admin-border hover:bg-[#0E5E5C]/5"}`,children:i.label},i.key)})})]},r.id))})]},s.id)}),(()=>{const s=o.filter(t=>!t.assigned_staff_id&&t.status!=="completed");return s.length?e.jsxs("div",{className:"p-3 bg-amber-50/40",children:[e.jsxs("div",{className:"text-xs font-semibold text-amber-700 mb-2 flex items-center justify-between",children:["Unassigned ",e.jsx("span",{className:"text-[10px] bg-amber-200 text-amber-800 px-1.5 py-0.5 rounded",children:s.length})]}),e.jsx("div",{className:"space-y-1",children:s.slice(0,8).map(t=>e.jsxs("div",{className:"text-[11px] flex items-center justify-between gap-2 group",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-foreground truncate font-medium",children:t.customer_name}),e.jsx("div",{className:"text-muted-foreground truncate",children:new Date(t.preferred_date).toLocaleDateString()})]}),e.jsxs(y,{size:"sm",variant:"outline",className:"h-6 text-[10px] px-2",onClick:()=>b(t.id),disabled:g===t.id,children:[e.jsx(k,{className:"h-2.5 w-2.5 mr-0.5"}),"AI"]})]},t.id))})]}):null})()]})]}),e.jsx(p,{className:"border-admin-border p-0 overflow-hidden max-h-[calc(100vh-200px)]",children:e.jsx(w,{})})]})]})}export{z 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.