PageSourceSearch

https://deliverimates-production.up.railway.app/assets/IncidentDetail-P3T2LeU6.js

js deliverimates-production.up.railway.app collected 2026-10-03 12:12:44 UTC 18,214 bytes, 18 lines download raw bytes

1import{bC as de,u as le,l as oe,bQ as me,bR as xe,bS as he,bT as ue,bU as je,bV as pe,bW as fe,bX as Ne,r as h,j as e,B as o,b4 as ge,C as i,d,e as l,b as n,G as ve,T as _e,ad as U,ae as V,af as Y,ag as G,ah as u,b5 as L,s as be,a8 as ye}from"./index-Db4qfLtJ.js";import{C as we}from"./CreateWriteupWizard-DyOoVVXM.js";import{T as Ce,a as Se,b as _,c as b}from"./tabs-C0SDnV8_.js";import{I as H,S as X,L as k}from"./LmetTimer-aNyp4g-g.js";import{F as De}from"./file-exclamation-point-D3TmDOdg.js";import{S as Q}from"./send-BKG_37I8.js";import{C as Le}from"./circle-check-big-BYdW0JZP.js";import{C as ke}from"./copy-DajIPwGS.js";import{D as j}from"./download-CboRdteu.js";import"./badge-B13RZfEt.js";import"./use-writeups-B6fjI3Nf.js";import"./use-drivers-viEKgcBv.js";import"./use-station-scoped-query-DTYNhmkw.js";import"./useInfiniteQuery-BgOip7ok.js";import"./trending-down-DsAo7AF6.js";import"./chevron-right-D4zIy9sL.js";import"./format-DyStx0k9.js";import"./chevron-left-J4GbtB-v.js";function Qe(){const{id:a}=de(),x=le(),{toast:c}=oe(),{data:m,isLoading:y}=me(a||null),A=xe(),w=he(),q=ue(),T=je(),I=pe(),J=fe(),R=Ne(),[p,E]=h.useState(""),[f,$]=h.useState(""),[C,K]=h.useState(!1),[P,Z]=h.useState(""),[ee,z]=h.useState(!1);if(y||!m)return e.jsx("div",{className:"p-8 text-center text-muted-foreground",children:"Loading..."});const t=m.incident,r=m.driver_report,se=m.notes||[],S=m.photos||[],O=m.witnesses||[],M=m.sms_log||[],W=m.submission_hash,B=m.corrective_actions||[],te=async()=>{if(!(!p.trim()||!a))try{await A.mutateAsync({id:a,note_text:p}),E(""),c({title:"Note added"})}catch(s){c({title:"Error",description:s.message,variant:"destructive"})}},F=async()=>{if(a)try{await w.mutateAsync(a),c({title:"SMS sent",description:"New driver form link sent."})}catch(s){c({title:"Error",description:s.message,variant:"destructive"})}},ae=async()=>{if(!(!a||!C))try{const s=Ae(t,r);await I.mutateAsync({id:a,lmet_packet_snapshot:s}),c({title:"LMET marked as notified"})}catch(s){c({title:"Error",description:s.message,variant:"destructive"})}},re=async()=>{if(a)try{await T.mutateAsync({id:a,status:"closed",closing_notes:P}),c({title:"Incident closed"})}catch(s){c({title:"Error",description:s.message,variant:"destructive"})}},N=async s=>{try{const{data:{session:g}}=await be.auth.getSession();if(!g)throw new Error("Not authenticated");const ie=`${ye}/api/incidents/${a}/wc-doc?state=${s}`,D=await fetch(ie,{headers:{Authorization:`Bearer ${g.access_token}`}});if(!D.ok){const ce=await D.json();throw new Error(ce.error||"Failed to generate document")}const ne=await D.blob(),v=document.createElement("a");v.href=URL.createObjectURL(ne),v.download=s==="ca"?`DWC-5020-${t.incident_number}.pdf`:`ACORD-FROI-${t.incident_number}.pdf`,v.click(),URL.revokeObjectURL(v.href),c({title:"Document downloaded"})}catch(g){c({title:"Error",description:g.message,variant:"destructive"})}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(o,{variant:"ghost",size:"sm",onClick:()=>x("/dashboard/incidents"),children:e.jsx(ge,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold font-mono",children:t.incident_number}),e.jsx(H,{status:t.status}),e.jsx(X,{severity:t.severity}),t.completed_by==="dispatcher"&&e.jsx("span",{className:"text-xs bg-amber-100 text-amber-700 px-2 py-1 rounded",children:"Dispatcher-entered"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[t.delivery_associates?.full_name," — ",t.incident_type,t.injury_subtype?` (${t.injury_subtype.replace("_"," ")})`:"",t.vehicle_subtype?` (${t.vehicle_subtype.replace("_"," ")})`:""]})]}),t.driver_id&&e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>z(!0),children:[e.jsx(De,{className:"h-4 w-4 mr-1"}),"Create writeup"]}),e.jsx(k,{state:t.lmet_state})]}),t.driver_id&&e.jsx(we,{open:ee,onOpenChange:z,prefilledDriverId:t.driver_id,prefilledViolationId:t.id,prefilledViolationSource:"safety"}),t.completed_by==="dispatcher"&&e.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-4 text-sm text-amber-800",children:[e.jsx("p",{className:"font-medium",children:"Dispatcher-entered — driver did not complete mobile form"}),t.dispatcher_entry_reason&&e.jsxs("p",{className:"mt-1",children:["Reason: ",t.dispatcher_entry_reason]})]}),e.jsxs(Ce,{defaultValue:"details",children:[e.jsxs(Se,{children:[e.jsx(_,{value:"details",children:"Details"}),e.jsx(_,{value:"report",children:"Driver Report"}),e.jsx(_,{value:"actions",children:"Actions"}),e.jsx(_,{value:"timeline",children:"Timeline"})]}),e.jsxs(b,{value:"details",className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"Incident Info"})}),e.jsxs(n,{className:"text-sm space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Type"}),e.jsx("span",{className:"capitalize",children:t.incident_type})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Severity"}),e.jsx(X,{severity:t.severity})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Location"}),e.jsx("span",{children:t.address_raw||"Not provided"})]}),t.vehicle_id&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Vehicle"}),e.jsx("span",{children:t.vehicle_id})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Reported at"}),e.jsx("span",{children:new Date(t.incident_reported_at).toLocaleStr
1ing()})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Record created"}),e.jsx("span",{children:new Date(t.record_created_at).toLocaleString()})]}),t.driver_submitted_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Driver submitted"}),e.jsx("span",{children:new Date(t.driver_submitted_at).toLocaleString()})]})]})]}),e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"Status"})}),e.jsxs(n,{className:"text-sm space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Status"}),e.jsx(H,{status:t.status})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"RTW"}),e.jsx("span",{className:"capitalize",children:t.rtw_status?.replace("_"," ")})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"LMET"}),e.jsx(k,{state:t.lmet_state})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"OSHA Recordable"}),e.jsx("span",{children:t.osha_recordable===!0?"Yes":t.osha_recordable===!1?"No":"Not set"})]}),W&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Report Integrity"}),e.jsxs("span",{className:"font-mono text-xs",children:["SHA-256 ",W.hash_value.substring(0,12),"..."]})]})]})]})]}),S.length>0&&e.jsxs(i,{children:[e.jsx(d,{children:e.jsxs(l,{className:"text-sm",children:["Photos (",S.length,")"]})}),e.jsx(n,{children:e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:S.map(s=>e.jsxs("div",{className:"bg-slate-100 rounded-md p-2 text-center text-xs text-muted-foreground",children:[s.file_name,e.jsx("span",{className:"block text-xs",children:s.uploaded_by})]},s.id))})})]}),O.length>0&&e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"Witnesses"})}),e.jsx(n,{children:O.map(s=>e.jsxs("div",{className:"text-sm",children:[s.name||"Unnamed"," ",s.phone&&`— ${s.phone}`," ",e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",s.added_by,")"]})]},s.id))})]})]}),e.jsx(b,{value:"report",className:"space-y-4",children:r?e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"Driver Report"})}),e.jsxs(n,{className:"text-sm space-y-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground block text-xs mb-1",children:"Description"}),e.jsx("p",{className:"bg-slate-50 rounded p-3",children:r.description})]}),r.body_part_affected&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Body Part"}),e.jsx("span",{className:"capitalize",children:r.body_part_affected.replace("_"," ")})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Medical Decision"}),e.jsx("span",{children:r.medical_decision.replace("_"," ")})]}),r.medical_facility_name&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Facility"}),e.jsx("span",{children:r.medical_facility_name})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Language"}),e.jsx("span",{children:r.language_used?.toUpperCase()})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Rights Notice Shown"}),e.jsx("span",{children:r.rights_notice_shown?"Yes":"No"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"ESIGN Consent Shown"}),e.jsx("span",{children:r.esign_consent_shown?"Yes":"No"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Driver Confirmed"}),e.jsx("span",{children:r.driver_confirmed?"Yes":"No"})]}),r.gps_lat&&r.gps_lng&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"GPS"}),e.jsxs("span",{children:[r.gps_lat,", ",r.gps_lng]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Submitted"}
1),e.jsx("span",{children:new Date(r.submitted_at).toLocaleString()})]})]})]}):e.jsx(i,{children:e.jsxs(n,{className:"py-8 text-center text-muted-foreground",children:[e.jsx(ve,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"Waiting for driver to submit report..."}),t.status==="pending_driver"&&e.jsxs(o,{variant:"outline",size:"sm",className:"mt-3",onClick:F,disabled:w.isPending,children:[e.jsx(Q,{className:"h-3 w-3 mr-1"})," Re-send SMS Link"]})]})})}),e.jsxs(b,{value:"actions",className:"space-y-4",children:[e.jsxs(i,{children:[e.jsx(d,{children:e.jsxs(l,{className:"text-sm flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"})," Notify LMET"]})}),e.jsx(n,{children:t.lmet_notified_at?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-emerald-700",children:[e.jsx(Le,{className:"h-4 w-4"}),"LMET notified at ",new Date(t.lmet_notified_at).toLocaleString()]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{state:t.lmet_state}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:C,onChange:s=>K(s.target.checked),className:"mt-1"}),e.jsx("span",{className:"text-xs text-slate-600",children:"I have reviewed this notification and verified the information is accurate to the best of my knowledge. I understand this notification will be sent to Amazon LMET by me as the DSP dispatcher."})]}),e.jsxs(o,{size:"sm",disabled:!C||I.isPending,onClick:ae,children:[e.jsx(ke,{className:"h-3 w-3 mr-1"})," Copy LMET Packet"]})]})})]}),e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"Return-to-Work Status"})}),e.jsx(n,{children:e.jsxs(U,{value:t.rtw_status,onValueChange:s=>a&&q.mutate({id:a,rtw_status:s}),children:[e.jsx(V,{className:"w-[250px]",children:e.jsx(Y,{})}),e.jsxs(G,{children:[e.jsx(u,{value:"not_returned",children:"Not Returned"}),e.jsx(u,{value:"modified_duty",children:"Modified Duty"}),e.jsx(u,{value:"returned",children:"Fully Returned"})]})]})})]}),e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"OSHA Recordable"})}),e.jsx(n,{children:e.jsxs(U,{value:t.osha_recordable===!0?"true":t.osha_recordable===!1?"false":"",onValueChange:s=>a&&J.mutate({id:a,osha_recordable:s==="true"}),children:[e.jsx(V,{className:"w-[200px]",children:e.jsx(Y,{placeholder:"Not set"})}),e.jsxs(G,{children:[e.jsx(u,{value:"true",children:"Yes"}),e.jsx(u,{value:"false",children:"No"})]})]})})]}),e.jsxs(i,{children:[e.jsx(d,{children:e.jsxs(l,{className:"text-sm flex items-center gap-2",children:[e.jsx(j,{className:"h-4 w-4"})," Workers' Comp Document"]})}),e.jsxs(n,{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generate a pre-filled workers' comp form. Blank fields (SSN, DOB, wages) must be filled before submission."}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>N("acord"),children:[e.jsx(j,{className:"h-3 w-3 mr-1"})," ACORD FROI"]}),e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>N("ca"),children:[e.jsx(j,{className:"h-3 w-3 mr-1"})," CA DWC 5020"]}),e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>N("tx"),children:[e.jsx(j,{className:"h-3 w-3 mr-1"})," TX DWC-001S"]}),e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>N("ny"),children:[e.jsx(j,{className:"h-3 w-3 mr-1"})," NY WCB C-2"]})]}),t.wc_doc_generated_at&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last generated: ",new Date(t.wc_doc_generated_at).toLocaleString()]})]})]}),t.status==="pending_driver"&&e.jsx(i,{children:e.jsx(n,{className:"pt-6",children:e.jsxs(o,{variant:"outline",onClick:F,disabled:w.isPending,children:[e.jsx(Q,{className:"h-4 w-4 mr-2"})," Re-send Driver SMS"]})})}),e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"Corrective Actions"})}),e.jsxs(n,{className:"space-y-3",children:[B.length>0?e.jsx("div",{className:"space-y-2",children:B.map(s=>e.jsxs("div",{className:"bg-slate-50 rounded p-3 text-sm flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.action_type||"Corrective Action"}),s.coaching_notes&&e.jsx("p",{className:"text-muted-foreground mt-1",children:s.coaching_notes}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[s.da_name||"Driver"," — ",new Date(s.created_at).toLocaleDateString()]})]}),e.jsx("span",{className:`text-xs px-2 py-1 rounded ${s.completed?"bg-emerald-100 text-emerald-700":"bg-amber-100 text-amber-700"}`,children:s.completed?"Complete":s.urgency||"Pending"})]},s.id))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No corrective actions linked to this incident."}),e.jsxs("div",{className:"space-y-2 pt-2 border-t",children:[e.jsx(L,{placeholder:"Coaching notes for new corrective action...",value:f,onChange:s=>$(s.target.value),rows:2}),e.jsx(o,{variant:"outline",size:"sm",disabled:!f.trim()||R.isPending,onClick:async()=>
1{if(!(!a||!f.trim()))try{await R.mutateAsync({incident_id:a,da_name:t.delivery_associates?.full_name,action_type:"incident_followup",urgency:"high",coaching_notes:f}),$(""),c({title:"Corrective action created"})}catch(s){c({title:"Error",description:s.message,variant:"destructive"})}},children:"Create Corrective Action"})]})]})]}),t.status!=="closed"&&e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"Close Incident"})}),e.jsxs(n,{className:"space-y-3",children:[e.jsx(L,{placeholder:"Closing notes (optional)",value:P,onChange:s=>Z(s.target.value)}),e.jsx(o,{variant:"outline",onClick:re,disabled:T.isPending,children:"Close Incident"})]})]})]}),e.jsxs(b,{value:"timeline",className:"space-y-4",children:[e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"Notes"})}),e.jsxs(n,{className:"space-y-3",children:[se.map(s=>e.jsxs("div",{className:"bg-slate-50 rounded p-3 text-sm",children:[e.jsx("p",{children:s.note_text}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[s.users?.email||"System"," — ",new Date(s.created_at).toLocaleString()]})]},s.id)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{placeholder:"Add a note (cannot be edited after saving)...",value:p,onChange:s=>E(s.target.value),className:"flex-1",rows:2}),e.jsx(o,{size:"sm",onClick:te,disabled:!p.trim()||A.isPending,children:"Add"})]})]})]}),M.length>0&&e.jsxs(i,{children:[e.jsx(d,{children:e.jsx(l,{className:"text-sm",children:"SMS Log"})}),e.jsx(n,{children:e.jsx("div",{className:"space-y-2",children:M.map(s=>e.jsxs("div",{className:"text-sm flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-mono text-xs bg-slate-100 px-1 rounded",children:s.message_type}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:s.to_number})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[s.status," — ",new Date(s.sent_at).toLocaleString()]})]},s.id))})})]})]})]})]})}function Ae(a,x){const c=a.delivery_associates||{},m=a.incident_reported_at?new Date(a.incident_reported_at).toLocaleString():"N/A",y=a.record_created_at?new Date(a.record_created_at).toLocaleString():"N/A";return`LMET INCIDENT NOTIFICATION
2
3INCIDENT DETAILS
4Date/Time of Incident (driver reported): ${m}
5Date/Time Logged in System: ${y}
6Location: ${a.address_raw||"Not provided"}
7
8DRIVER INFORMATION
9Driver Name: ${c.full_name||"N/A"}
10
11INCIDENT
12Type: ${a.incident_type}${a.injury_subtype?` — ${a.injury_subtype}`:""}${a.vehicle_subtype?` — ${a.vehicle_subtype}`:""}
13Severity: ${a.severity}
14Description: ${x?x.description:"Driver report pending"}
15Body Part Affected: ${x&&x.body_part_affected||"N/A"}
16Medical Treatment: ${x?x.medical_decision:"Pending"}
17
18Notification prepared and certified accurate by the DSP dispatcher.`}export{Qe 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.