PageSourceSearch

https://privawell.net/assets/admin-import-DLhdTVRJ.js

js privawell.net collected 2026-10-07 01:37:48 UTC 5,696 bytes, 1 lines download raw bytes

1import{bZ as P,cb as z,bE as n,c4 as L,by as e,h,k as u,l as f,J as F,i as j,f as c,F as q,aW as A,bC as Q,bs as U}from"./index-BOgKjTHI.js";import{B as T}from"./badge-xYseOKTI.js";import{T as V,d as $,e as S,c as H,a as K,b as O}from"./table-B6Wb7fwb.js";import{AdminNav as J}from"./admin-review-queue-CQ5VZD0q.js";import{U as I}from"./upload-9yrLFtZf.js";import{C as W}from"./circle-check-big-ltvJeKDU.js";import"./skeleton-C2m6pwdb.js";import"./clipboard-check-CqC7xPV_.js";import"./star-CPINmHzQ.js";import"./chart-column-DwvD-ANz.js";import"./activity-NJt4tlT_.js";function le(){var y;const[,R]=P(),{toast:x}=z(),d=n.useRef(null),[i,g]=n.useState(null),[r,p]=n.useState(null),[b,w]=n.useState(!1),[l,o]=n.useState(null),N=L({queryKey:["/api/leads/auth/me"],queryFn:U({on401:"returnNull"}),retry:!1});if(N.isLoading)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx("div",{className:"w-6 h-6 border-2 border-t-transparent rounded-full animate-spin border-amber-600"})});if(!((y=N.data)!=null&&y.authenticated))return R("/admin/leads/login"),null;async function D(s){var C;const a=(C=s.target.files)==null?void 0:C[0];if(!a)return;g(a),o(null);const t=new FormData;t.append("file",a);try{const m=await fetch("/api/leads/import?preview=true",{method:"POST",body:t,credentials:"include"}),k=await m.json();if(!m.ok)throw new Error(k.message);p(k)}catch(m){x({title:"Preview failed",description:m.message,variant:"destructive"}),p(null)}}async function B(){if(!i)return;w(!0),o(null);const s=new FormData;s.append("file",i);try{const a=await fetch("/api/leads/import",{method:"POST",body:s,credentials:"include"}),t=await a.json();if(!a.ok)throw new Error(t.message);o(t),Q.invalidateQueries({queryKey:["/api/leads"]}),x({title:"Import complete",description:`${t.processed} processed, ${t.failed} failed`})}catch(a){x({title:"Import failed",description:a.message,variant:"destructive"})}finally{w(!1)}}function E(){window.open("/api/leads/import/template","_blank")}function v(){g(null),p(null),o(null),d.current&&(d.current.value="")}return e.jsxs("div",{className:"min-h-screen bg-gray-50 dark:bg-gray-900",children:[e.jsxs("header",{className:"border-b bg-white dark:bg-gray-800 px-6 py-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(I,{className:"w-6 h-6 text-amber-600"}),e.jsx("h1",{className:"text-xl font-semibold",children:"Import Leads"})]}),e.jsx(J,{current:"import"})]}),e.jsxs("div",{className:"max-w-4xl mx-auto p-6 space-y-6",children:[e.jsxs(h,{children:[e.jsx(u,{children:e.jsxs(f,{className:"text-base flex items-center gap-2",children:[e.jsx(F,{className:"w-4 h-4"})," CSV Upload"]})}),e.jsxs(j,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:E,children:[e.jsx(q,{className:"w-4 h-4 mr-2"})," Download Template"]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Use this template to format your CSV before uploading"})]}),e.jsxs("div",{className:"border-2 border-dashed border-muted rounded-lg p-8 text-center",children:[e.jsx("input",{ref:d,type:"file",accept:".csv",className:"hidden",onChange:D}),i?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"w-10 h-10 mx-auto text-amber-600 mb-3"}),e.jsx("p",{className:"font-medium",children:i.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[(i.size/1024).toFixed(1)," KB",r&&` · ${r.totalRows} rows`]}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[e.jsx(c,{variant:"outline",size:"sm",onClick:v,children:"Change File"}),r&&!l&&e.jsx(c,{size:"sm",onClick:B,disabled:b,children:b?"Importing...":`Import ${r.totalRows} Leads`})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"w-10 h-10 mx-auto text-muted-foreground mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Choose a CSV file to import leads"}),e.jsx(c,{onClick:()=>{var s;return(s=d.current)==null?void 0:s.click()},children:"Select CSV File"})]})]})]})]}),r&&!l&&e.jsxs(h,{children:[e.jsx(u,{children:e.jsxs(f,{className:"text-base",children:["Preview (first ",r.rows.length," rows)"]})}),e.jsx(j,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(V,{children:[e.jsx($,{children:e.jsx(S,{children:r.headers.map(s=>e.jsx(H,{className:"text-xs whitespace-nowrap",children:s},s))})}),e.jsx(K,{children:r.rows.map((s,a)=>e.jsx(S,{children:r.headers.map(t=>e.jsx(O,{className:"text-sm",children:s[t]||"-"},t))},a))})]})})})]}),l&&e.jsxs(h,{children:[e.jsx(u,{children:e.jsxs(f,{className:"text-base flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4 text-green-600"})," Import Results"]})}),e.jsxs(j,{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(T,{className:"bg-green-100 text-green-800",children:[l.processed," processed"]})}),l.failed>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(T,{variant:"destructive",children:[l.failed," failed"]})})]}),l.errors.length>0&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(A,{className:"w-4 h-4 text-red-600"}),e.jsx("span",{className:"text-sm font-medium text-red-800 dark:text-red-200",children:"Errors"})]}),e.jsx("ul",{className:"text-sm text-red-700 dark:text-red-300 space-y-1",children:l.errors.map((s,a)=>e.jsx("li",{children:s},a))})]}),e.jsx(c,{variant:"outline",size:"sm",onClick:v,children:"Import Another File"})]})]})]})]})}export{le 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.