PageSourceSearch

https://netfocus-reimagine-website.lovable.app/assets/PdfDownloadsAdmin-CW8j8ePS.js

js netfocus-reimagine-website.lovable.app collected 2026-10-03 03:35:15 UTC 4,996 bytes, 2 lines download raw bytes

1import{j as e,i as L,r as t,P as k,B as j,C as D,a as M,b as U,c as S,Y as u,I as y,s as O}from"./index-DwD5y2V5.js";import{P as B}from"./ProtectedRoute-CWczz8ol.js";import{S as H,a as V,b as $,c as q,d as C}from"./select-_1JRRUTQ.js";import{T as Y,a as z,b as _,c as r,d as G,e as n}from"./table-BCxsBhmk.js";import{R as J}from"./refresh-cw-B0-iNgw1.js";import{D as K}from"./download-DlfnxmRR.js";import{L as Q}from"./loader-circle-D7CA8yYw.js";import{f as W}from"./format-BwcsVm1d.js";import"./Combination-Dj9zWLPK.js";import"./en-US-DWrl2lTx.js";const X=()=>{const{toast:F}=L(),[i,R]=t.useState([]),[h,p]=t.useState(!0),[o,g]=t.useState("all"),[m,w]=t.useState(""),[x,v]=t.useState(""),b=async()=>{p(!0);try{const{data:s,error:a}=await O.from("pdf_downloads").select("*").order("created_at",{ascending:!1}).limit(1e3);if(a)throw a;R(s??[])}catch(s){console.error(s),F({title:"Failed to load downloads",description:(s==null?void 0:s.message)??"Unknown error",variant:"destructive"})}finally{p(!1)}};t.useEffect(()=>{b()},[]);const T=t.useMemo(()=>{const s=new Set;return i.forEach(a=>a.file_name&&s.add(a.file_name)),Array.from(s).sort()},[i]),d=t.useMemo(()=>i.filter(s=>{if(o!=="all"&&s.file_name!==o)return!1;const a=new Date(s.created_at).getTime();if(m){const c=new Date(m+"T00:00:00").getTime();if(a<c)return!1}if(x){const c=new Date(x+"T23:59:59").getTime();if(a>c)return!1}return!0}),[i,o,m,x]),P=()=>{const a=[["Date","File","Source","Page","Referrer","IP","User Agent"].join(",")];d.forEach(l=>{const A=[new Date(l.created_at).toISOString(),l.file_name,l.source_label??"",l.page_path??"",l.referrer??"",l.ip_address??"",l.user_agent??""].map(I=>`"${String(I).replace(/"/g,'""')}"`);a.push(A.join(","))});const c=new Blob([a.join(`
2`)],{type:"text/csv"}),N=URL.createObjectURL(c),f=document.createElement("a");f.href=N,f.download=`pdf-downloads-${new Date().toISOString().slice(0,10)}.csv`,f.click(),URL.revokeObjectURL(N)},E=()=>{g("all"),w(""),v("")};return e.jsxs("div",{className:"min-h-screen bg-gray-50 pt-44 pb-16",children:[e.jsx(k,{title:"PDF Downloads Admin",description:"Admin dashboard for viewing recent PDF download activity and lead source attribution.",canonicalPath:"/admin/pdf-downloads"}),e.jsxs("div",{className:"max-w-7xl mx-auto px-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"PDF Downloads"}),e.jsxs("p",{className:"text-gray-600 mt-1",children:[d.length," of ",i.length," downloads"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(j,{variant:"outline",onClick:b,disabled:h,children:[e.jsx(J,{className:`h-4 w-4 mr-2 ${h?"animate-spin":""}`}),"Refresh"]}),e.jsxs(j,{onClick:P,disabled:d.length===0,children:[e.jsx(K,{className:"h-4 w-4 mr-2"}),"Export CSV"]})]})]}),e.jsxs(D,{className:"mb-6",children:[e.jsx(M,{children:e.jsx(U,{className:"text-lg",children:"Filters"})}),e.jsx(S,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx(u,{htmlFor:"file",children:"File"}),e.jsxs(H,{value:o,onValueChange:g,children:[e.jsx(V,{id:"file",children:e.jsx($,{placeholder:"All files"})}),e.jsxs(q,{children:[e.jsx(C,{value:"all",children:"All files"}),T.map(s=>e.jsx(C,{value:s,children:s},s))]})]})]}),e.jsxs("div",{children:[e.jsx(u,{htmlFor:"start",children:"Start date"}),e.jsx(y,{id:"start",type:"date",value:m,onChange:s=>w(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{htmlFor:"end",children:"End date"}),e.jsx(y,{id:"end",type:"date",value:x,onChange:s=>v(s.target.value)})]}),e.jsx("div",{className:"flex items-end",children:e.jsx(j,{variant:"outline",onClick:E,className:"w-full",children:"Clear filters"})})]})})]}),e.jsx(D,{children:e.jsx(S,{className:"p-0",children:h?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(Q,{className:"h-6 w-6 animate-spin text-blue-600"})}):d.length===0?e.jsx("div",{className:"text-center py-16 text-gray-500",children:"No downloads found."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Y,{children:[e.jsx(z,{children:e.jsxs(_,{children:[e.jsx(r,{children:"Date"}),e.jsx(r,{children:"File"}),e.jsx(r,{children:"Source"}),e.jsx(r,{children:"Page"}),e.jsx(r,{children:"Referrer"}),e.jsx(r,{children:"IP"})]})}),e.jsx(G,{children:d.map(s=>e.jsxs(_,{children:[e.jsx(n,{className:"whitespace-nowrap text-sm",children:W(new Date(s.created_at),"MMM d, yyyy h:mm a")}),e.jsx(n,{className:"text-sm font-medium",children:s.file_name}),e.jsx(n,{className:"text-sm",children:s.source_label??"—"}),e.jsx(n,{className:"text-sm max-w-xs truncate",title:s.page_path??"",children:s.page_path??"—"}),e.jsx(n,{className:"text-sm max-w-xs truncate",title:s.referrer??"",children:s.referrer??"—"}),e.jsx(n,{className:"text-sm",children:s.ip_address??"—"})]},s.id))})]})})})})]})]})},ce=()=>e.jsx(B,{requiredRole:"admin",children:e.jsx(X,{})});
2export{ce 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.