PageSourceSearch

https://trackstein.com/assets/PPEDamageReports--33EmuQQ.js

js trackstein.com collected 2026-10-09 22:05:00 UTC 12,260 bytes, 1 lines download raw bytes

1import{c8 as oe,aN as Q,c9 as I,aK as y,r as _,M as e,aT as v,cT as ie,bZ as K,b_ as le,a_ as ce,a$ as de,f5 as me,dA as pe}from"./vendor-BNUVQ5NN.js";import{u as ge,z as he,s as m,C as M,f as $,g as B,k as A,a3 as U,B as f,h as V,D as z,c as H,d as G,e as J,i as W,I as xe}from"./index-BryxCFMR.js";import{T as Y}from"./textarea-BfP9Tot-.js";import{u as ue}from"./useCompanyAwareQuery-D-6Il3tE.js";import{P as je}from"./PPEPhotoCapture-DQqXS0iE.js";import{L as g}from"./label-C9Mg_OMf.js";import{S as Z,a as X,b as ee,c as se,d as ae}from"./select-fU-0lmrN.js";import{P as ye}from"./PPECatalogCombobox-DR5zHgrQ.js";import{C as _e}from"./checkbox-B6jw-_Ii.js";import"./export-excel-BaWk6VOU.js";import"./supabase-DE1vgkE3.js";import"./sentry-B8b0D934.js";import"./command-D5rn7qv4.js";const fe=()=>{const i=oe(),{company_id:h}=ge(),{enhanceQuery:c}=ue(),{user:x}=he(),p=(a,r,o)=>{!x||!h||m.from("audit_logs").insert([{actor_user_id:x.id,action:a,entity_type:"ppe_item",entity_id:r||void 0,company_id:h,metadata:o?JSON.parse(JSON.stringify(o)):null}]).then(({error:t})=>{})},{data:S,isLoading:N}=Q({queryKey:["ppe-damage-reports"],queryFn:async()=>{const{data:a,error:r}=await c(m.from("ppe_damage_summary")).select("*").order("reported_at",{ascending:!1});if(r)throw r;return a||[]}}),{data:E}=Q({queryKey:["ppe-damage-summary"],queryFn:async()=>{const{data:a,error:r}=await c(m.from("ppe_damage_summary")).select("*");if(r)throw r;return a}}),F=I({mutationFn:async a=>{const{data:{user:r}}=await m.auth.getUser();if(!r)throw new Error("Not authenticated");const{error:o}=await c(m.from("ppe_damage_reports")).insert({...a,reported_by:r.id,company_id:h||""});if(o)throw o},onSuccess:(a,r)=>{i.invalidateQueries({queryKey:["ppe-damage-reports"]}),i.invalidateQueries({queryKey:["ppe-damage-summary"]}),p("ppe.damaged",r.catalog_id,{damage_type:r.damage_type,severity:r.severity,replacement_needed:r.replacement_needed}),y.success("Damage report created successfully")},onError:a=>{y.error(a.message||"Failed to create damage report")}}),u=I({mutationFn:async({id:a,updates:r})=>{const{error:o}=await c(m.from("ppe_damage_reports")).update(r).eq("id",a);if(o)throw o},onSuccess:()=>{i.invalidateQueries({queryKey:["ppe-damage-reports"]}),i.invalidateQueries({queryKey:["ppe-damage-summary"]}),y.success("Damage report updated")},onError:a=>{y.error(a.message||"Failed to update damage report")}}),w=I({mutationFn:async({id:a,resolutionNotes:r,resolutionPhotos:o})=>{let t=[];if(o&&o.length>0)for(const l of o)if(l.startsWith("data:")){const[j,O]=l.split(","),C=j.match(/:(.*?);/),D=C?C[1]:"image/jpeg",s=atob(O),n=new ArrayBuffer(s.length),P=new Uint8Array(n);for(let q=0;q<s.length;q++)P[q]=s.charCodeAt(q);const L=D.split("/")[1]||"jpg",b=`${crypto.randomUUID()}.${L}`,R=`${h||"unknown"}/ppe-damage-resolution/${a}/${b}`,T=new File([n],b,{type:D}),{error:ne}=await m.storage.from("incident-photos").upload(R,T,{cacheControl:"3600",upsert:!1});if(ne)continue;t.push(`incident-photos:${R}`)}else t.push(l);const d={resolved_at:new Date().toISOString(),resolution_notes:r};if(t.length>0){const{data:l}=await c(m.from("ppe_damage_reports")).select("photo_urls").eq("id",a).single(),j=(l==null?void 0:l.photo_urls)||[];d.photo_urls=[...j,...t]}const{error:k}=await c(m.from("ppe_damage_reports")).update(d).eq("id",a);if(k)throw k},onSuccess:()=>{i.invalidateQueries({queryKey:["ppe-damage-reports"]}),i.invalidateQueries({queryKey:["ppe-damage-summary"]}),y.success("Damage report marked as resolved")},onError:a=>{y.error(a.message||"Failed to resolve damage report")}});return{damageReports:S,damageSummary:E,isLoading:N,createDamageReport:F,updateDamageReport:u,markAsResolved:w}},te={torn:"Torn",broken:"Broken",stained:"Stained",missing_parts:"Missing Parts",expired:"Expired",worn_out:"Worn Out",other:"Other"},re={minor:{label:"Minor",color:"bg-yellow-100 text-yellow-800 border-yellow-200",icon:v},moderate:{label:"Moderate",color:"bg-orange-100 text-orange-800 border-orange-200",icon:v},severe:{label:"Severe",color:"bg-red-100 text-red-800 border-red-200",icon:v},total_loss:{label:"Total Loss",color:"bg-red-200 text-red-900 border-red-300",icon:v}};function ve(){var D;const{damageReports:i,isLoading:h,markAsResolved:c,createDamageReport:x}=fe(),[p,S]=_.useState(null),[N,E]=_.useState(""),[F,u]=_.useState(!1),[w,a]=_.useState([]),[r,o]=_.useState(!1),[t,d]=_.useState({catalog_id:"",damage_type:"other",severity:"minor",description:"",replacement_needed:!1,cost_of_damage:""}),k=async()=>{!t.catalog_id||!t.description.trim()||(await x.mutateAsync({catalog_id:t.catalog_id,damage_type:t.damage_type,severity:t.severity,description:t.description,replacement_needed:t.replacement_needed,cost_of_damage:t.cost_of_damage?parseFloat(t.cost_of_damage):void 0}),o(!1),d({catalog_id:"",damage_type:"other",severity:"minor",description:"",replacement_needed:!1,cost_of_damage:""}))};if(h)return e.jsx("div",{className:"text-center py-8",children:"Loading damage reports..."});const l=(i==null?void 0:i.filter(s=>!s.resolved_at))||[],j=(i==null?void 0:i.filter(s=>s.resolved_at))||[],O=async()=>{p&&(await c.mutateAsync({id:p.id,resolutionNotes:N,resolutionPhotos:w.length>0?w:void 0}),u(!1),E(""),S(null),a([]))},C=({report:s,isResolved:n})=>{var b,R,T;
1const P=re[s.severity],L=P.icon;return e.jsx("div",{className:"border rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-2",children:[e.jsx("h4",{className:"font-semibold",children:((b=s.ppe_catalog)==null?void 0:b.name)||"Unknown Item"}),e.jsx(A,{variant:"outline",className:"text-xs",children:(R=s.ppe_catalog)==null?void 0:R.category}),e.jsxs(A,{className:`text-xs ${P.color}`,children:[e.jsx(L,{className:"h-3 w-3 mr-1"}),P.label]}),s.replacement_needed&&e.jsxs(A,{variant:"secondary",className:"text-xs",children:[e.jsx(ce,{className:"h-3 w-3 mr-1"}),"Replacement Needed"]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Type:"})," ",te[s.damage_type]||s.damage_type]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Description:"})," ",s.description]}),s.cost_of_damage&&e.jsxs("p",{className:"flex items-center gap-1",children:[e.jsx(de,{className:"h-3 w-3"}),e.jsx("strong",{children:"Cost:"})," $",s.cost_of_damage.toLocaleString()]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Reported by:"})," ",s.reported_by_name||"Unknown"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Date:"})," ",new Date(s.reported_at).toLocaleDateString()]}),((T=s.photo_urls)==null?void 0:T.length)>0&&e.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[e.jsx(me,{className:"h-3 w-3"}),e.jsxs("span",{className:"text-xs",children:[s.photo_urls.length," photo(s) attached"]})]}),n&&s.resolved_at&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Resolved:"})," ",new Date(s.resolved_at).toLocaleDateString()]}),s.resolution_notes&&e.jsxs("p",{children:[e.jsx("strong",{children:"Resolution:"})," ",s.resolution_notes]})]})]})]}),!n&&e.jsxs(f,{size:"sm",onClick:()=>{S(s),u(!0)},children:[e.jsx(K,{className:"h-4 w-4 mr-2"}),"Resolve"]})]})})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(M,{children:[e.jsxs($,{children:[e.jsxs(B,{className:"flex items-center gap-2",children:[e.jsx(v,{className:"h-5 w-5 text-orange-600"}),"Active Damage Reports",l.length>0&&e.jsx(A,{variant:"destructive",children:l.length})]}),e.jsx(U,{children:"PPE items requiring attention or replacement"}),e.jsxs(f,{onClick:()=>o(!0),size:"sm",children:[e.jsx(ie,{className:"h-4 w-4 mr-2"}),"Report Damage"]})]}),e.jsx(V,{children:l.length>0?e.jsx("div",{className:"space-y-3",children:l.map(s=>e.jsx(C,{report:s,isResolved:!1},s.id))}):e.jsxs("div",{className:"text-center py-8",children:[e.jsx(K,{className:"h-12 w-12 mx-auto text-green-600 mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"No active damage reports"})]})})]}),j.length>0&&e.jsxs(M,{children:[e.jsxs($,{children:[e.jsxs(B,{className:"flex items-center gap-2",children:[e.jsx(le,{className:"h-5 w-5 text-muted-foreground"}),"Resolved Damage Reports"]}),e.jsx(U,{children:"Historical damage reports that have been addressed"})]}),e.jsx(V,{children:e.jsx("div",{className:"space-y-3",children:j.map(s=>e.jsx(C,{report:s,isResolved:!0},s.id))})})]}),e.jsx(z,{open:r,onOpenChange:o,children:e.jsxs(H,{className:"sm:max-w-[500px]",children:[e.jsxs(G,{children:[e.jsx(J,{children:"Report PPE Damage"}),e.jsx(W,{children:"Create a new damage report for a PPE item"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"PPE Item *"}),e.jsx(ye,{value:t.catalog_id,onValueChange:s=>d(n=>({...n,catalog_id:s})),placeholder:"Select PPE item"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Damage Type *"}),e.jsxs(Z,{value:t.damage_type,onValueChange:s=>d(n=>({...n,damage_type:s})),children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsx(se,{children:Object.entries(te).map(([s,n])=>e.jsx(ae,{value:s,children:n},s))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Severity *"}),e.jsxs(Z,{value:t.severity,onValueChange:s=>d(n=>({...n,severity:s})),children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsx(se,{children:Object.entries(re).map(([s,n])=>e.jsx(ae,{value:s,children:n.label},s))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Description *"}),e.jsx(Y,{value:t.description,onChange:s=>d(n=>({...n,description:s.target.value})),placeholder:"Describe the damage...",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Estimated Cost of Damage"}),e.jsx(xe,{type:"number",value:t.cost_of_damage,onChange:s=>d(n=>({...n,cost_of_damage:s.target.value})),placeholder:"0.00",min:"0",step:"0.01"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(_e,{id:"replacement-needed",checked:t.replacement_needed,onCheckedChange:s=>d(n=>({...n,replacement_needed:s===!0}))}),e.jsx(g,{htmlFor:"replacement-needed",className:"text-sm cursor-pointer",children:"Replacement needed"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",onClick:()=>o(!1),className:"flex-1",children:"Cancel"}),e.jsx(f,{onClick:k,disabled:!t.catalog_id||!t.description.trim()||x.isPending,className:"flex-1",children:x.isPending?"Creating...":"Submit Report"})]})]})]})}
1),e.jsx(z,{open:F,onOpenChange:u,children:e.jsxs(H,{children:[e.jsxs(G,{children:[e.jsx(J,{children:"Resolve Damage Report"}),e.jsx(W,{children:"Mark this damage report as resolved and add resolution notes"})]}),e.jsxs("div",{className:"space-y-4",children:[p&&e.jsxs("div",{className:"bg-muted p-3 rounded-md text-sm",children:[e.jsx("p",{children:e.jsx("strong",{children:(D=p.ppe_catalog)==null?void 0:D.name})}),e.jsx("p",{className:"text-muted-foreground",children:p.description})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Resolution Notes"}),e.jsx(Y,{value:N,onChange:s=>E(s.target.value),placeholder:"Describe how the issue was resolved...",rows:4})]}),e.jsx(je,{photos:w,onPhotosChange:a,maxPhotos:3,label:"Resolution Photos (optional)"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",onClick:()=>u(!1),className:"flex-1",children:"Cancel"}),e.jsx(f,{onClick:O,disabled:!N.trim()||c.isPending,className:"flex-1",children:c.isPending?"Resolving...":"Mark as Resolved"})]})]})]})})]})}function Fe(){return e.jsxs(e.Fragment,{children:[e.jsxs(pe,{children:[e.jsx("title",{children:"PPE Damage Reports | TrackStein"}),e.jsx("meta",{name:"description",content:"Track and manage damaged PPE equipment"})]}),e.jsxs("div",{className:"p-3 sm:p-4 md:p-6 space-y-4 sm:space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"page-title flex items-center gap-2",children:[e.jsx(v,{className:"h-6 w-6 sm:h-8 sm:w-8"}),"PPE Damage Reports"]}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Track damaged PPE, manage replacements, and analyze damage trends"})]}),e.jsx(ve,{})]})]})}export{Fe 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.