PageSourceSearch

https://getmelon.com.au/assets/AdminIncidentDetail-DVL6b25h.js

js getmelon.com.au collected 2026-09-30 06:39:07 UTC 13,005 bytes, 1 lines download raw bytes

1import{p as de,u as le,b as ce,r as l,d,j as e}from"./index-DjvjYx8D.js";import{B as u}from"./button-Cz5sYbhP.js";import{C as f,b as p,d as j,c as k,a as g}from"./card-BoeYN9zz.js";import{B as oe}from"./badge-Cl_SCNNJ.js";import{T as L}from"./textarea-BNnM3daC.js";import{S as $,a as B,b as V,c as q,d as N}from"./select-CfoOE7i0.js";import{D as me,f as ue,a as he,b as xe,c as fe,e as pe,d as je}from"./dialog-B9zYFgAh.js";import{I as ge}from"./input-vy9OFss5.js";import{L as _}from"./label-BVrYemgw.js";import{A as Ne}from"./arrow-left-DXjop1Hu.js";import{C as ve}from"./calendar-BTjk4LQO.js";import{M as be}from"./map-pin-Ct9JBX2s.js";import{F as O}from"./file-text-emM02cjn.js";import{C as we}from"./circle-alert-Ca4hl0la.js";import{C as _e}from"./car-0p7-OwRB.js";import{U as ye}from"./user-Cc2M9x8z.js";import{P as Ce}from"./phone-8lfvyRJ8.js";import{C as De}from"./circle-user-BwIIxL4y.js";import{D as Ae}from"./dollar-sign-BGSs-bu_.js";import{f as E}from"./format-BuON0pZi.js";import"./index-BdQq_4o_.js";import"./index-D8K3azz-.js";import"./Combination-Cmn8Mk01.js";import"./index-Dv7kNRC4.js";import"./chevron-down-BXueFYvF.js";import"./check-BUcFAsHw.js";import"./index-Dxopu1_s.js";function ss(){const{id:h}=de(),y=le(),{toast:c}=ce(),[t,I]=l.useState(null),[r,W]=l.useState(null),[C,H]=l.useState([]),[T,z]=l.useState([]),[Y,G]=l.useState(!0),[D,o]=l.useState(!1),[v,U]=l.useState(""),[J,A]=l.useState(!1),[i,b]=l.useState({type:"debit",amount:"",reason:""});l.useEffect(()=>{h&&R()},[h]);const R=async()=>{try{const{data:s,error:a}=await d.from("incidents").select("*").eq("id",h).single();if(a)throw a;I(s);const{data:m,error:x}=await d.from("profiles").select("first_name, last_name, email, mobile").eq("user_id",s.user_id
1).single();if(x)throw x;W(m);const{data:te,error:F}=await d.from("incident_attachments").select("*").eq("incident_id",h);if(F)throw F;const ae=await Promise.all((te||[]).map(async n=>{if(n.file_key){const{data:P}=await d.storage.from("incident-attachments").createSignedUrl(n.file_key,3600);return{...n,file_url:(P==null?void 0:P.signedUrl)??n.file_url}}return n}));H(ae);const{data:w,error:M}=await d.from("incident_notes").select("*").eq("incident_id",h).order("created_at",{ascending:!1});if(M)throw M;const re=[...new Set((w==null?void 0:w.map(n=>n.staff_user_id))||[])],{data:S}=await d.from("profiles").select("user_id, first_name, last_name").in("user_id",re),ie=new Map((S==null?void 0:S.map(n=>[n.user_id,n]))||[]),ne=(w||[]).map(n=>({...n,profiles:ie.get(n.staff_user_id)||null}));z(ne)}catch(s){console.error("Error fetching incident:",s),c({title:"Error",description:"Failed to load incident details",variant:"destructive"}),y("/admin/incidents")}finally{G(!1)}},K=async s=>{if(t){o(!0);try{const{error:a}=await d.from("incidents").update({status:s}).eq("id",t.id);if(a)throw a;I({...t,status:s}),c({title:"Status Updated",description:"Incident status has been updated successfully"})}catch(a){console.error("Error updating status:",a),c({title:"Error",description:"Failed to update status",variant:"destructive"})}finally{o(!1)}}},Q=async()=>{if(!(!v.trim()||!t)){o(!0);try{const{data:{user:s}}=await d.auth.getUser();if(!s)throw new Error("Not authenticated");const{error:a}=await d.from("incident_notes").insert({incident_id:t.id,staff_user_id:s.id,note:v.trim()});if(a)throw a;c({title:"Note Added",description:"Internal note has been saved"}),U(""),R()}catch(s){console.error("Error adding note:",s),c({title:"Error",description:"Failed to add note",variant:"destructive"})}finally{o(!1)}}},X=async()=>{if(!t||!i.amount||!i.reason){c({title:"Missing Information",description:"Please fill in all fields",variant:"destructive"});return}o(!0);try{const{data:{user:s}}=await d.auth.getUser();if(!s)throw new Error("Not authenticated");const a=parseFloat(i.amount),m=i.type==="debit"?-Math.abs(a):Math.abs(a),{error:x}=await d.from("account_credits").insert({user_id:t.user_id,amount:m,source:"staff_adjustment",description:i.reason,adjustment_type:i.type,adjusted_by_staff_id:s.id,related_incident_id:t.id});if(x)throw x;c({title:"Account Adjusted",description:`${i.type==="credit"?"Credit":"Debit"} of $${a} has been applied`}),A(!1),b({type:"debit",amount:"",reason:""})}catch(s){console.error("Error adjusting account:",s),c({title:"Error",description:"Failed to adjust account",variant:"destructive"})}finally{o(!1)}},Z=s=>({crash_accident:"Crash/Accident",damage:"Damage",theft_vandalism:"Theft/Vandalism",mechanical_breakdown:"Mechanical Breakdown",other:"Other"})[s]||s,ee=s=>({submitted:"bg-blue-500/10 text-blue-700 dark:text-blue-400",under_review:"bg-yellow-500/10 text-yellow-700 dark:text-yellow-400",resolved:"bg-green-500/10 text-green-700 dark:text-green-400"})[s]||"bg-secondary",se=s=>({submitted:"Submitted",under_review:"Under Review",resolved:"Resolved"})[s]||s;return Y?e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-[hsl(174_45%_98%)] to-background flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Loading incident details..."})]})}):t?e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-[hsl(174_45%_98%)] to-background p-8",children:e.jsxs("div",{className:"container mx-auto max-w-6xl",children:[e.jsxs(u,{variant:"ghost",onClick:()=>y("/admin/incidents"),className:"mb-4",children:[e.jsx(Ne,{className:"w-4 h-4 mr-2"}),"Back to Incidents"]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(f,{children:[e.jsx(p,{children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-2xl",children:Z(t.incident_type)}),e.jsxs(k,{children:["Reported on ",E(new Date(t.created_at),"PPP")]})]}),e.jsx(oe,{className:ee(t.status),children:se(t.status)})]})}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(_,{children:"Change Status"}),e.jsxs($,{value:t.status,onValueChange:K,disabled:D,children:[e.jsx(B,{className:"mt-2",children:e.jsx(V,{})}),e.jsxs(q,{children:[e.jsx(N,{value:"submitted",children:"Submitted"}),e.jsx(N,{value:"under_review",children:"Under Review"}),e.jsx(N,{value:"resolved",children:"Resolved"})]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 pt-4",children:[e.jsx(ve,{className:"w-5 h-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Date & Time"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:E(new Date(t.incident_date),"PPP 'at' p")})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(be,{className:"w-5 h-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Location"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.location})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(O,{className:"w-5 h-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:"Description"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.description})]})]}),t.police_report_number&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(we,{className:"w-5 h-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Police Report Number"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.police_report_number})]})]}),t.third_party_details&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(_e,{className:"w-5 h-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:"Third-Party Details"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.third_party_details})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ye,{className:"w-5 h-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Injuries"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.injuries?"Yes":"No"})]})]}),t.witnesses&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ce,{className:"w-5 h-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:"Witnesses"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.witnesses})]})]})]})]}),C.length>0&&e.jsxs(f,{children:[e.jsxs(p,{children:[e.jsx(j,{children:"Photos & Videos"}),e.jsxs(k,{children:[C.length," attachment(s)"]})]}),e.jsx(g,{children:e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:C.map(s=>e.jsx("div",{className:"relative group",children:s.file_type.startsWith("image/")?e.jsx("a",{href:s.file_url,target:"_blank",rel:"noopener noreferrer",children:e.jsx("img",{src:s.file_url,alt:"Incident attachment",className:"w-full h-40 object-cover rounded-lg border border-border hover:border-primary transition-colors"})}):e.jsx("a",{href:s.file_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center w-full h-40 bg-secondary/30 rounded-lg border border-border hover:border-primary transition-colors",children:e.jsx(O,{className:"w-12 h-12 text-muted-foreground"})})},s.id))})})]}),e.jsxs(f,{children:[e.jsxs(p,{children:[e.jsx(j,{children:"Internal Notes"}),e.jsx(k,{children:"Staff-only notes (not visible to rider)"})]}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{placeholder:"Add internal note...",value:v,onCh
1ange:s=>U(s.target.value),rows:3}),e.jsx(u,{onClick:Q,disabled:!v.trim()||D,children:"Add Note"})]}),T.length>0&&e.jsx("div",{className:"space-y-3 pt-4 border-t",children:T.map(s=>{var a,m;return e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsx("span",{className:"font-medium text-sm",children:(a=s.profiles)!=null&&a.first_name||(m=s.profiles)!=null&&m.last_name?`${s.profiles.first_name||""} ${s.profiles.last_name||""}`.trim():"Staff"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:E(new Date(s.created_at),"PPP 'at' p")})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:s.note})]},s.id)})})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(f,{children:[e.jsx(p,{children:e.jsxs(j,{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-5 h-5"}),"Rider Information"]})}),e.jsxs(g,{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Name"}),e.jsx("p",{className:"font-medium",children:r!=null&&r.first_name||r!=null&&r.last_name?`${r.first_name||""} ${r.last_name||""}`.trim():"Unknown"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Email"}),e.jsx("p",{className:"text-sm",children:(r==null?void 0:r.email)||"No email"})]}),(r==null?void 0:r.mobile)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Mobile"}),e.jsx("p",{className:"text-sm",children:r.mobile})]}),e.jsx(u,{variant:"outline",size:"sm",className:"w-full mt-4",onClick:()=>y("/admin/users"),children:"View Full Profile"})]})]}),e.jsxs(f,{children:[e.jsx(p,{children:e.jsxs(j,{className:"flex items-center gap-2",children:[e.jsx(Ae,{className:"w-5 h-5"}),"Actions"]})}),e.jsx(g,{className:"space-y-2",children:e.jsxs(me,{open:J,onOpenChange:A,children:[e.jsx(ue,{asChild:!0,children:e.jsx(u,{variant:"outline",className:"w-full",children:"Adjust Account"})}),e.jsxs(he,{children:[e.jsxs(xe,{children:[e.jsx(fe,{children:"Adjust Rider Account"}),e.jsx(pe,{children:"Add a credit or debit to the rider's account"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{children:"Type"}),e.jsxs($,{value:i.type,onValueChange:s=>b({...i,type:s}),children:[e.jsx(B,{children:e.jsx(V,{})}),e.jsxs(q,{children:[e.jsx(N,{value:"credit",children:"Credit (add to account)"}),e.jsx(N,{value:"debit",children:"Debit (deduct from account)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{children:"Amount (AUD)"}),e.jsx(ge,{type:"number",step:"0.01",placeholder:"0.00",value:i.amount,onChange:s=>b({...i,amount:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{children:"Reason"}),e.jsx(L,{placeholder:"e.g., Damage repair - $250",value:i.reason,onChange:s=>b({...i,reason:s.target.value}),rows:3})]})]}),e.jsxs(je,{children:[e.jsx(u,{variant:"outline",onClick:()=>A(!1),children:"Cancel"}),e.jsx(u,{onClick:X,disabled:D,children:"Apply Adjustment"})]})]})]})})]})]})]})]})}):null}export{ss 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.