PageSourceSearch

https://weload.ai/assets/Compliance-D7p5HOXQ.js

js weload.ai collected 2026-10-05 13:52:30 UTC 12,611 bytes, 1 lines download raw bytes

1import{aw as V,i as Y,r as l,e as d,j as e,aJ as D,X as I,Q as O,l as T,a as A,J as M}from"./index-BWQbUAvI.js";import{E as q}from"./ErrorState-CNSrr0Td.js";import{P as J}from"./plus-D9LEKeCV.js";import{S as X}from"./save-BcwvHINc.js";const z={active:"bg-green-100 text-green-700",pending_review:"bg-amber-100 text-amber-700",expiring:"bg-amber-100 text-amber-700",expired:"bg-red-100 text-red-700",rejected:"bg-red-100 text-red-700"},K=["general_liability","cargo","auto_liability","workers_comp","bond","other"],h={certType:"general_liability",provider:"",policyNumber:"",coverageAmount:"",effectiveDate:"",expirationDate:""};function Z(){const{showToast:f}=V(),{user:p}=Y(),r=(p==null?void 0:p.role)==="master_admin",[b,E]=l.useState([]),[g,k]=l.useState([]),[i,_]=l.useState(null),[P,j]=l.useState(!0),[$,y]=l.useState(!1),[N,u]=l.useState(!1),[a,n]=l.useState(h),[v,w]=l.useState(!1),[C,x]=l.useState(""),[S,m]=l.useState(null),o=l.useCallback(async()=>{j(!0),y(!1);try{const t=[d.get("/compliance/certificates")];r?t.push(d.get("/compliance/summary")):t.push(d.get("/compliance/my-company"));const[s,c]=await Promise.all(t);E(s.data),r?k(c.data):_(c.data)}catch(t){console.error(t),y(!0)}finally{j(!1)}},[r]);l.useEffect(()=>{o()},[o]);async function R(t){m(t);try{await d.patch(`/compliance/certificates/${t}/verify`),await o()}catch(s){console.error(s),f("Failed to verify certificate. Please try again.","error")}m(null)}async function F(t){const s=prompt("Reason for rejection (optional):")??void 0;m(t);try{await d.patch(`/compliance/certificates/${t}/reject`,{reason:s}),await o()}catch(c){console.error(c),f("Failed to reject certificate. Please try again.","error")}m(null)}async function B(){var t,s;if(!a.certType){x("Certificate type is required");return}w(!0),x("");try{await d.post("/compliance/certificates",{certType:a.certType,provider:a.provider||null,policyNumber:a.policyNumber||null,coverageAmount:a.coverageAmount?Number(a.coverageAmount):null,effectiveDate:a.effectiveDate||null,expirationDate:a.expirationDate||null}),n(h),u(!1),await o()}catch(c){x(((s=(t=c==null?void 0:c.response)==null?void 0:t.data)==null?void 0:s.detail)||"Failed to add certificate")}w(!1)}const W=t=>t?new Date(t).toLocaleDateString():"—",L=t=>t!=null?`$${t.toLocaleString()}`:"—";return e.jsxs("div",{className:"space-y-6 pb-12",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-slate-900 flex items-center gap-2",children:[e.jsx(D,{className:"w-7 h-7 text-blue-600"})," Compliance Center"]}),e.jsx("p",{className:"text-slate-500 text-sm mt-1",children:r?"Per-company insurance & DOT compliance rollup.":"Your company insurance certificates and compliance status."})]}),!r&&!N&&e.jsxs("button",{onClick:()=>{n(h),x(""),u(!0)},className:"flex items-center gap-2 bg-blue-600 text-white px-4 py-2 rounded-xl text-sm font-medium hover:bg-blue-700",children:[e.jsx(J,{className:"w-4 h-4"})," Add Certificate"]})]}),!r&&N&&e.jsxs("div",{className:"bg-white rounded-2xl border border-blue-200 p-5 space-y-4",children:[e.jsx("h2",{className:"font-semibold text-slate-800",children:"New Certificate"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-500 mb-1",children:"Type *"}),e.jsx("select",{value:a.certType,onChange:t=>n(s=>({...s,certType:t.target.value})),className:"w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",children:K.map(t=>e.jsx("option",{value:t,children:t.replace(/_/g," ")},t))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-500 mb-1",children:"Provider"}),e.jsx("input",{value:a.provider,onChange:t=>n(s=>({...s,provider:t.target.value})),className:"w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Acme Insurance"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-500 mb-1",children:"Policy #"}),e.jsx("input",{value:a.policyNumber,onChange:t=>n(s=>({...s,policyNumber:t.target.value})),className:"w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"POL-12345"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-500 mb-1",children:"Coverage Amou
1nt ($)"}),e.jsx("input",{type:"number",value:a.coverageAmount,onChange:t=>n(s=>({...s,coverageAmount:t.target.value})),className:"w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"1000000"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-500 mb-1",children:"Effective Date"}),e.jsx("input",{type:"date",value:a.effectiveDate,onChange:t=>n(s=>({...s,effectiveDate:t.target.value})),className:"w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-500 mb-1",children:"Expiration Date"}),e.jsx("input",{type:"date",value:a.expirationDate,onChange:t=>n(s=>({...s,expirationDate:t.target.value})),className:"w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]})]}),C&&e.jsx("p",{className:"text-red-600 text-sm",children:C}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:B,disabled:v,className:"flex items-center gap-2 bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-blue-700 disabled:opacity-50",children:[e.jsx(X,{className:"w-4 h-4"})," ",v?"Saving…":"Save Certificate"]}),e.jsxs("button",{onClick:()=>u(!1),className:"flex items-center gap-2 px-4 py-2 border border-slate-200 rounded-lg text-sm text-slate-600 hover:bg-slate-50",children:[e.jsx(I,{className:"w-4 h-4"})," Cancel"]})]})]}),P?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((t,s)=>e.jsx("div",{className:"h-14 bg-slate-100 rounded-lg animate-pulse"},s))}):$?e.jsx(q,{message:"Couldn't load compliance data.",onRetry:o}):e.jsxs(e.Fragment,{children:[!r&&i&&e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 p-4",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"DOT Verified"}),e.jsx("p",{className:`text-lg font-semibold mt-1 ${i.dotVerified?"text-green-600":"text-slate-400"}`,children:i.dotVerified?"Yes":"No"})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 p-4",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Certificates"}),e.jsx("p",{className:"text-lg font-semibold mt-1 text-slate-900",children:i.certificateCount})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 p-4",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Active"}),e.jsx("p",{className:"text-lg font-semibold mt-1 text-green-600",children:i.certCountsByStatus.active??0})]}),e.jsxs("div",{className:`bg-white rounded-2xl border p-4 ${i.expiringWithin30Days>0?"border-amber-300":"border-slate-200"}`,children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Expiring <30d"}),e.jsx("p",{className:`text-lg font-semibold mt-1 ${i.expiringWithin30Days>0?"text-amber-700":"text-slate-400"}`,children:i.expiringWithin30Days})]})]}),r&&e.jsx("div",{className:"bg-white rounded-xl border border-slate-200 overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:720},children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs text-slate-400 border-b border-slate-100",children:[e.jsx("th",{className:"px-4 py-3 font-medium",children:"Company"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"DOT Verified"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Certificates"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Active"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Pending"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Expiring <30d"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Expired"})]})}),e.jsx("tbody",{children:g.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-10 text-center text-slate-400",children:"No companies yet."})}):g.map(t=>e.jsxs("tr",{className:"border-b border-slate-50 last:border-0",children:[e.jsxs("td",{className:"px-4 py-3 text-slate-800 font-medium flex items-center gap-2",children:[e.jsx(O,{className:"w-4 h-4 text-slate-300"}),t.companyName]}),e.jsx("td",{className:"px-4 py-3",children:t.dotVerified?e.jsxs("span",{className:"inline-flex items-center gap-1 text-green-600",children:[e.jsx(T,{className:"w-4 h-4"})," Yes"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 text-slate-400",children:[e.jsx(A,{className:"w-4 h-4"})," No"]})}),e.jsx("td",{className:"px-4 py-3 text-slate-700",children:t.certificateCount}),e.jsx("td",{className:"px-4 py-3 text-green-700",children:t.certCountsByStatus.active??0}),e.jsx("td",{className:"px-4 py-3 text-amber-700",children:t.certCountsByStatus.pending_review??0}),e.jsx("td",{className:`px-4 py-3 font-medium ${t.expiringWithin30Days>0?"text-amber-700":"text-slate-400"}`,children:t.expiringWithin30Days}),e.jsx("td",{className:`px-4 py-3 font-medium ${(t.certCountsByStatus.expired??0)>0?"text-red-600":"text-slate-400"}`,children:t.certCountsByStatus.expired??0})]},t.companyId))})]})}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold text-slate-800 mb-3",children:r?"All Certificates":"Your Certificates"}),b.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 p-12 text-center text-slate-400",children:[e.jsx(D,{className:"w-10 h-10 mx-auto mb-3 opacity-30"}),e.jsx("p",{children:"No certificates on file yet."})]}):e.jsx("div",{className:"bg-white rounded-xl border border-slate-200 overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:760},children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs text-slate-400 border-b border-slate-100",children:[e.jsx("th",{className:"px-4 py-3 font-medium",children:"Type"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Provider"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Policy #"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Coverage"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Expires"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Status"}),r&&e.jsx("th",{className:"px-4 py-3 font-medium",children:"Actions"})]})}),e.jsx("tbody",{children:b.map(t=>e.jsxs("tr",{className:"border-b border-slate-50 last:border-0",children:[e.jsx("td",{className:"px-4 py-3 text-slate-800 capitalize",children:t.certType.replace(/_/g," ")}),e.jsx("td",{className:"px-4 py-3 text-slate-600",children:t.provider??"—"}),e.jsx("td",{className:"px-4 py-3 text-slate-600 font-mono text-xs",children:t.policyNumber??"—"}),e.jsx("td",{className:"px-4 py-3 text-slate-700",children:L(t.coverageAmou
1nt)}),e.jsx("td",{className:`px-4 py-3 ${t.effectiveStatus==="expired"?"text-red-600":t.effectiveStatus==="expiring"?"text-amber-700":"text-slate-600"}`,children:W(t.expirationDate)}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${z[t.effectiveStatus]??"bg-slate-100 text-slate-600"}`,children:t.effectiveStatus.replace(/_/g," ")}),t.rejectionReason&&e.jsxs("span",{className:"ml-2 inline-flex items-center gap-1 text-xs text-red-500",children:[e.jsx(M,{className:"w-3 h-3"}),t.rejectionReason]})]}),r&&e.jsx("td",{className:"px-4 py-3",children:t.status==="pending_review"?e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>R(t.id),disabled:S===t.id,className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-lg bg-green-600 text-white text-xs font-medium hover:bg-green-700 disabled:opacity-50",children:[e.jsx(T,{className:"w-3.5 h-3.5"})," Verify"]}),e.jsxs("button",{onClick:()=>F(t.id),disabled:S===t.id,className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-lg border border-red-200 text-red-600 text-xs font-medium hover:bg-red-50 disabled:opacity-50",children:[e.jsx(A,{className:"w-3.5 h-3.5"})," Reject"]})]}):e.jsx("span",{className:"text-slate-300 text-xs",children:"—"})})]},t.id))})]})})]})]})]})}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.