PageSourceSearch

https://psychicguide.net/assets/AdminImportPage-BC9-4WdA.js

js psychicguide.net collected 2026-10-09 22:04:14 UTC 11,720 bytes, 6 lines download raw bytes

1import{c as H,y as G,r as i,s as u,j as e,$ as _,B as f,U as K,q as n,Y as O,e as W}from"./index-CdlRzbIO.js";import{C as m,b as E,c as P,d as Y,a as x}from"./card-CM0Okv3Z.js";import{S as g}from"./skeleton-CbzUyPBA.js";import{L as B}from"./label-e8Kal1IJ.js";import{S as Z,a as J,b as Q,c as X,d as ee}from"./select-Bn2PV-d6.js";import{R as se}from"./refresh-cw-DjQSYiT5.js";import{U as T}from"./upload-CgwQGz6J.js";import{F as ae}from"./file-up-CJJDmVN6.js";import{C as re}from"./circle-alert-BgKO0fRI.js";import{I as te}from"./info-BRiNgT-X.js";import{T as le}from"./triangle-alert-B9XdSvlM.js";import"./index-BdQq_4o_.js";import"./index-ClrCEPLH.js";import"./chevron-down-CJ0_mUBc.js";import"./chevron-up-QfggDjgX.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ce=H("FileSpreadsheet",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]]),N=({title:d,value:j,subtitle:h,icon:a,iconBg:o,iconColor:t,loading:y})=>y?e.jsx(m,{className:"border-0 shadow-sm bg-white",children:e.jsx(x,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(g,{className:"h-10 w-10 rounded-xl shrink-0"}),e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsx(g,{className:"h-3 w-20"}),e.jsx(g,{className:"h-6 w-24"})]})]})})}):e.jsx(m,{className:"border-0 shadow-sm bg-white hover:shadow-md transition-shadow",children:e.jsx(x,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`p-2.5 rounded-xl ${o} shrink-0`,children:e.jsx(a,{className:`h-5 w-5 ${t}`})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:d}),e.jsx("div",{className:"flex items-center gap-2 mt-0.5",children:e.jsx("span",{className:"text-xl font-bold text-gray-900",children:j})}),h&&e.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:h})]})]})})}),be=()=>{var R;const{toast:d}=G(),[j,h]=i.useState(!1),[a,o]=i.useState(null),[t,y]=i.useState(null),[S,V]=i.useState([]),[p,U]=i.useState(""),[v,z]=i.useState(!0),[C,A]=i.useState({totalReaders:0,totalServices:0,lastImport:null}),b=i.useRef(null);i.useEffect(()=>{I(),w()},[]);const w=async()=>{try{const[s,r]=await Promise.all([u.from("reader_profiles").select("*",{count:"exact",head:!0}),u.from("services").select("*",{count:"exact",head:!0})]);A({totalReaders:s.count||0,totalServices:r.count||0,lastImport:null})}catch(s){console.error("Error fetching stats:",s)}},I=async()=>{try{const{data:s,error:r}=await u.from("reader_profiles").select("user_id");if(r)throw r;const{data:l,error:k}=await u.from("profiles").select("user_id, display_name, full_name, email");if(k)throw k;const q=(s||[]).map(F=>{const c=l==null?void 0:l.find(D=>D.user_id===F.user_id);return{user_id:F.user_id,display_name:(c==null?void 0:c.display_name)||(c==null?void 0:c.full_name)||(c==null?void 0:c.email)||"Unknown Reader"}});V(q)}catch(s){console.error("Error fetching readers:",s),d({variant:"destructive",title:"Error",description:"Failed to load readers list"})}finally{z(!1)}},M=s=>{var l;const r=(l=s.target.files)==null?void 0:l[0];r&&(y(r),o(null))},L=async()=>{if(!t){d({variant:"destructive",title:"No file selected",description:"Please select a CSV file to import"});return}if(!p){d({variant:"destructive",title:"No reader selected",description:"Please select a reader to import products for"});return}h(!0),o(null);try{const s=await t.text(),{data:r,error:l}=await u.functions.invoke("import-etsy-products",{body:{csvContent:s,readerId:p,clearExisting:!0}});if(l)throw l;o(r),w(),d({title:"Import Complete",description:`Successfully imported ${r.imported} products`})}catch(s){console.error("Import error:",s),o({success:!1,error:s 
6instanceof Error?s.message:"An error occurred"}),d({variant:"destructive",title:"Import Failed",description:s instanceof Error?s.message:"An error occurred"})}finally{h(!1)}},$=(R=S.find(s=>s.user_id===p))==null?void 0:R.display_name;return v?e.jsxs("div",{className:"space-y-6 max-w-6xl mx-auto",children:[e.jsxs("div",{children:[e.jsx(g,{className:"h-8 w-48"}),e.jsx(g,{className:"h-4 w-64 mt-2"})]}),e.jsx("div",{className:"grid gap-3 grid-cols-2 lg:grid-cols-3",children:[1,2,3].map(s=>e.jsx(N,{title:"",value:"",icon:_,iconBg:"",iconColor:"",loading:!0},s))})]}):e.jsxs("div",{className:"space-y-6 max-w-6xl mx-auto",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Import Products"}),e.jsx("p",{className:"text-gray-500 mt-1",children:"Import Etsy products from CSV file"})]}),e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>{I(),w()},className:"gap-2",children:[e.jsx(se,{className:"h-4 w-4"}),"Refresh"]})]}),e.jsxs("div",{className:"grid gap-3 grid-cols-2 lg:grid-cols-3",children:[e.jsx(N,{title:"Total Readers",value:C.totalReaders,subtitle:"Available for import",icon:K,iconBg:"bg-blue-100",iconColor:"text-blue-600"}),e.jsx(N,{title:"Total Services",value:C.totalServices,subtitle:"In database",icon:_,iconBg:"bg-emerald-100",iconColor:"text-emerald-600"}),e.jsx(N,{title:"Supported Format",value:"CSV",subtitle:"Etsy export format",icon:ce,iconBg:"bg-violet-100",iconColor:"text-violet-600"})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsx("div",{className:"lg:col-span-2",children:e.jsxs(m,{className:"border-0 shadow-sm",children:[e.jsx(E,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-violet-100",children:e.jsx(T,{className:"h-4 w-4 text-violet-600"})}),e.jsxs("div",{children:[e.jsx(P,{className:"text-base font-semibold",children:"Etsy Product Import"}),e.jsx(Y,{children:"Upload CSV file and import products"})]})]})}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"reader-select",className:"text-sm font-medium text-gray-700",children:"Select Reader"}),e.jsxs(Z,{value:p,onValueChange:U,disabled:v,children:[e.jsx(J,{id:"reader-select",className:"bg-gray-50",children:e.jsx(Q,{placeholder:v?"Loading readers...":"Select a reader"})}),e.jsx(X,{children:S.map(s=>e.jsx(ee,{value:s.user_id,children:s.display_name},s.user_id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"csv-file",className:"text-sm font-medium text-gray-700",children:"Select CSV File"}),e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-6 text-center transition-colors ${t?"border-emerald-300 bg-emerald-50":"border-gray-200 bg-gray-50 hover:border-gray-300"}`,children:[e.jsx("input",{ref:b,id:"csv-file",type:"file",accept:".csv",onChange:M,className:"hidden"}),t?e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{className:"h-8 w-8 text-emerald-500 mx-auto"}),e.jsx("p",{className:"text-sm font-medium text-gray-900",children:t.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(t.size/1024).toFixed(1)," KB"]}),e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{var s;return(s=b.current)==null?void 0:s.click()},children:"Change File"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(ae,{className:"h-8 w-8 text-gray-400 mx-auto"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Click to select or drag and drop"}),e.jsx("p",{className:"text-xs text-gray-400",children:"CSV files only"}),e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{var s;return(s=b.current)==null?void 0:s.click()},children:"Browse Files"})]})]})]}),e.jsx(f,{onClick:L,disabled:j||!t||!p,className:"w-full",size:"lg",children:j?e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"w-4 h-4 mr-2 animate-spin"}),"Importing Products..."]}):e.jsxs(e.Fragment,{children:[e.jsx(T,{className:"w-4 h-4 mr-2"}),"Start Import"]})}),a&&e.jsxs("div",{className:`p-4 rounded-lg ${a.success?"bg-emerald-50 border border-emerald-200":"bg-red-50 border border-red-200"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[a.success?e.jsx(n,{className:"w-5 h-5 text-emerald-500"}):e.jsx(re,{className:"w-5 h-5 text-red-500"}),e.jsx("h4",{className:"font-semibold text-gray-900",children:a.success?"Import Successful":"Import Failed"})]}),e.jsx("p",{className:"text-sm text-gray-600",children:a.message||a.error}),a.imported!==void 0&&e.jsxs("p",{className:"text-sm mt-1 text-gray-700",children:["Products imported: ",e.jsx("strong",{children:a.imported})]}),a.errors>0&&e.jsxs("p",{className:"text-sm text-amber-600 mt-1",children:["Errors: ",a.errors]}),a.sampleTitles&&a.sampleTitles.length>0&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-200",children:[e.jsx("p",{className:"text-xs font-medium text-gray-700 mb-1",children:"Sample products:"}),e.jsx("ul",{className:"text-xs text-gray-500 space-y-0.5 max-h-24 overflow-y-auto",children:a.sampleTitles.map((s,r)=>e.jsxs("li",{children:["• ",s]},r))})]})]})]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs(m,{className:"border-0 shadow-sm",children:[e.jsx(E,{className:"pb-3",children:e.jsxs(P,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(te,{className:"h-4 w-4 text-gray-500"}),"Import Details"]}
vendor: 2,180 bytes, line 6
6)}),e.jsxs(x,{className:"pt-0 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-gray-50",children:[e.jsx("span",{className:"text-sm text-gray-600",children:"Selected Reader"}),e.jsx("span",{className:"text-sm font-medium text-gray-900",children:$||"None"})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-gray-50",children:[e.jsx("span",{className:"text-sm text-gray-600",children:"Format"}),e.jsx(W,{variant:"outline",children:"Etsy CSV"})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-gray-50",children:[e.jsx("span",{className:"text-sm text-gray-600",children:"Max Images"}),e.jsx("span",{className:"text-sm font-medium text-gray-900",children:"10 per product"})]})]})]}),e.jsx(m,{className:"border-0 shadow-sm bg-amber-50",children:e.jsx(x,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-amber-100",children:e.jsx(le,{className:"h-4 w-4 text-amber-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-amber-900",children:"Warning"}),e.jsx("p",{className:"text-xs text-amber-700 mt-1",children:"Existing services for the selected reader will be replaced during import."})]})]})})}),e.jsx(m,{className:"border-0 shadow-sm bg-gradient-to-br from-violet-50 to-blue-50",children:e.jsxs(x,{className:"p-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 mb-3",children:"Import Features"}),e.jsxs("ul",{className:"space-y-2 text-xs text-gray-600",children:[e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx(n,{className:"h-3 w-3 text-emerald-500"}),"Auto-assign categories from tags"]}),e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx(n,{className:"h-3 w-3 text-emerald-500"}),"Import product images"]}),e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx(n,{className:"h-3 w-3 text-emerald-500"}),"GBP to USD conversion"]}),e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx(n,{className:"h-3 w-3 text-emerald-500"}),"Preserve descriptions"]})]})]})})]})]})]})};export{be 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.