PageSourceSearch

https://app.litcommerce.com/assets/AllProductFileImport-DB8ncR4G.js

js litcommerce.com collected 2026-10-02 02:29:04 UTC 11,592 bytes, 1 lines download raw bytes

1import{j as e,B as p,A as L,T as F,L as k,m as R,aw as G,ax as N,aR as X,ay as A,r as x,R as U,P as $,fA as O,I as M,az as Y,t as E,aT as W,C as K,d as V,b as P,e as Z,kC as J,g as Q,ab as H}from"./index-DD7wEX2k.js";import{P as ee}from"./PageDefaultLayout-DV9yk-lQ.js";import{H as te}from"./HeaderPageTitle-y5EsJ77J.js";import{d as se}from"./ArrowBack-DPKRexet.js";import{i as T}from"./importFile-92nl5iOT.js";import{d as oe}from"./Delete-TaFDY8Lv.js";import{d as re}from"./InsertDriveFile-ZqnJOusz.js";import{C as ae,b as ne}from"./CopyComponent-Bam8Kwx6.js";import{g as ie,c as le,F as ce,L as de,f as _,n as pe}from"./CsvFile-BfHe8q1T.js";import{d as B}from"./Info-OZvC33_z.js";import{C as ue}from"./CustomLoadingButton-DzS_9QXf.js";import{C as me}from"./Card-CU05tOYa.js";import"./Page-mik8EZ_Q.js";import"./FileCopyOutlined-CsLkg8dP.js";import"./formik.esm-y-epKQ_W.js";import"./toString-BpP3vzIR.js";import"./Description-ju8aDwz-.js";import"./RadioGroup-DH1Vw7cH.js";import"./RadioGroupContext-CcoEOJr4.js";import"./Radio-CiD3rp-4.js";import"./Autocomplete-w5JONlgQ.js";import"./Help-DIwhWvl8.js";import"./Lazy-B4elB764.js";import"./CardHeader-DQ_PwC8a.js";import"./CardContent-glxr2M6x.js";import"./Switch-y6CmP1sJ.js";import"./index-BtNkM2il.js";import"./AllProductContext-C2skYRpJ.js";import"./AllProductCountContext-DiWtSr9V.js";import"./InfoOutlined-BJLHdNY6.js";import"./Grid-eV9hG1VW.js";import"./utils-Bgys39Sh.js";import"./Publish-JkXB9gP0.js";import"./ToggleOn-DyW7ZvlH.js";import"./AddCircleOutline-COf8fMgR.js";import"./Update-CQ15_MJp.js";import"./link-B9vAowY9.js";import"./ActionButtonMenu-BC9lDWO8.js";import"./ArrowDropDown-AeO9ZKDt.js";import"./ArrowDropUp-xVit32Pr.js";import"./ArrowForward-Bg5DeRrc.js";import"./TableContainer-BUx5ZMeU.js";function fe(){return e.jsx(p,{mb:2,children:e.jsxs(L,{severity:"info",children:[e.jsxs(F,{variant:"body2",component:"span",children:["Don't have a file or not sure how to format it?"," "]})," ",e.jsx(k,{href:"https://api.litcommerce.com/api/products/downloads/template",style:{fontWeight:500},children:"Download our template"})]})})}const he=R(t=>({menuItem:{fontSize:13,paddingTop:6,paddingBottom:6}}));function xe({importType:t="file",onImportTypeChange:n=()=>{},disabled:a=!1}){const r=he();return e.jsxs(p,{mb:3,children:[e.jsx(F,{variant:"subtitle2",children:"Import Type"}),e.jsx(G,{fullWidth:!0,variant:"outlined",size:"small",disabled:a,children:e.jsxs(N,{value:t,onChange:l=>n(l.target.value),MenuProps:{...X},children:[e.jsx(A,{value:"file",className:r.menuItem,children:"File Upload"}),e.jsx(A,{value:"sheet",className:r.menuItem,children:"Google Sheet"})]})})]})}const ye=100*1024*1024;function ge({selectedFile:t=null,onFileSelected:n=()=>{},onError:a=()=>{},disabled:r=!1,onFileDelete:l=()=>{}}){const u=x.useRef(),c=s=>{if(!s||s.length===0)return;if(s.length>1){a("You can only upload one file at a time.");return}const o=s[0],d=(o.name||"").split(".").pop().toLowerCase();if(!["csv","xlsx"].includes(d)){a("Invalid file format. Supported formats: CSV, XLSX");return}if(o.size>ye){a("File size exceeds the 100MB limit. Please upload a smaller file");return}a(""),n(o)},i=()=>{const s=t==null?void 0:t.size;if(!s&&s!==0)return"";if(s===0)return"0 B";const o=1024,m=["B","KB","MB","GB","TB"],d=Math.floor(Math.log(s)/Math.log(o));return parseFloat((s/Math.pow(o,d)).toFixed(2))+" "+m[d]};return e.jsxs(p,{mb:3,children:[!t&&e.jsxs(U.Fragment,{children:[e.jsx(F,{variant:"subtitle2",children:"Upload File"}),e.jsx("input",{ref:u,type:"file",id:"product-file",style:{display:"none"},accept:".xlsx,.csv",onChange:s=>c(s.target.files),disabled:r}),e.jsxs(p,{onClick:()=>!r&&u.current&&u.current.click(),onDragOver:s=>!r&&s.preventDefault(),onDrop:s=>{!r&&s.preventDefault(),!r&&c(s.dataTransfer.files)},style:{border:"2px dashed #d8d8d8",borderRadius:6,padding:48,textAlign:"center",cursor:r?"not-allowed":"pointer",opacity:r?.5:1,pointerEvents:r?"none":"auto"},children:[e.jsx(F,{variant:"body1",color:"primary",style:{marginBottom:8},children:"Click to Upload or Drag and Drop"}),e.jsx(F,{variant:"body2",color:"textSecondary",children:"XLSX, CSV (max. 100MB)"})]})]}),t&&e.jsx(p,{mt:2,children:e.jsx($,{variant:"outlined",style:{background:"#faf7f7",padding:12},children:e.jsxs(p,{display:"flex",alignItems:"center",children:[e.jsx(O,{style:{background:"#e6f4ea",color:"#1b5e20",marginRight:12},children:e.jsx(re,{})}),e.jsxs(p,{flex:1,children:[e.jsx(k,{component:"button",onClick:()=>{},style:{fontWeight:500,textTransform:"none"},children:t.name}),e.jsx(F,{variant:"body2",color:"textSecondary",children:i(t.size)})]}),e.jsx(M,{size:"small",onClick:l,children:e.jsx(oe,{})})]})})})]})}const je=R(()=>({boxIcon:ne}));function Se({sheetUrl:t="",onSheetUrlChange:n=()=>{},disabled:a=!1}){const r=je(),[l,u]=x.useState(!1);return e.jsxs(p,{mb:3,children:[e.jsxs(F,{variant:"subtitle2",children:["File Url",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsx(Y,{fullWidth:!0,required:!0,disabled:a,value:t,size:"small",onChange:c=>n(c.target.value),variant:"outlined",helperText:e.jsxs(p,{width:"fit-content",display:"flex",alignItems:"center",onMouseLeave:()=>u(!1),children:["If your file isn't publicly accessible, please grant access with this email:"," ",e.jsx(k,{style:{fontWeight:500},href:"mailto:[email protected]",onMouseEnter:()=>u(!0),children:"[email protected]"}
1),e.jsx(p,{className:r.boxIcon,children:l&&e.jsx(ae,{text:"[email protected]"})})]})})]})}function be({importType:t="file",selectedFile:n=null,sheetUrl:a="",onSubmit:r=()=>{},disabled:l=!1}){const c=l||!(t==="file"&&n||t==="sheet"&&(()=>{if(!a)return!1;try{const i=new URL(a);if(i.hostname.toLowerCase()!=="docs.google.com")return!1;const o="/spreadsheets/d/",m=i.pathname.indexOf(o);return m===-1?!1:!!i.pathname.slice(m+o.length).split("/")[0]}catch{return!1}})());return e.jsx(p,{display:"flex",justifyContent:"flex-end",children:e.jsx(E,{variant:"contained",color:"primary",onClick:r,size:"small",disabled:c,children:"Import Products"})})}function ve({setShowMapping:t=()=>{},setFirstLineHeaders:n,setMappings:a=()=>{},setAdditionalPayload:r=()=>{}}){const{enqueueSnackbar:l}=W(),[u,c]=x.useState(""),[i,s]=x.useState(""),[o,m]=x.useState("file"),[d,y]=x.useState(null),[g,C]=x.useState(!1),h=b=>{c(""),m(b),b==="file"?s(""):(y(null),n([]),a([]))},j=async()=>{var b,w;C(!0);try{if(o==="file"){const f=new FormData;f.append("product",d);const S=await T.post.uploadProductFile(f);if(S&&S.status<400){const{first_line:v,...z}=S.data;n(v),r(z),l("File uploaded successfully!",{variant:"success"}),t(!0)}}else if(o==="sheet"){const f={method:"url",info:{url:i,file_type:"sheet"}};r({url:i,file_type:"sheet"});const S=await T.post.testConnection(f);S&&S.status<400&&(n(S.data.data.first_line),l("Sheet connected successfully!",{variant:"success"}),t(!0))}}catch(f){console.log(f),l(((w=(b=f==null?void 0:f.response)==null?void 0:b.data)==null?void 0:w.errors)||"Import failed. Please try again or contact support if the issue persists.",{variant:"error"})}finally{C(!1)}};return e.jsxs(p,{style:{padding:24,position:"relative"},children:[e.jsx(fe,{}),e.jsx(xe,{importType:o,onImportTypeChange:h,disabled:g}),o==="file"&&e.jsx(ge,{selectedFile:d,onFileSelected:y,onError:c,disabled:g,onFileDelete:()=>{y(null),n([]),a([]),c("")}}),o==="sheet"&&e.jsx(Se,{sheetUrl:i,onSheetUrlChange:s,disabled:g}),u&&e.jsx(p,{mb:2,children:e.jsx(L,{severity:"error",children:u})}),e.jsx(be,{importType:o,selectedFile:d,sheetUrl:i,onSubmit:j,disabled:g}),g&&e.jsx(p,{style:{position:"absolute",top:0,left:0,right:0,bottom:0,display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(K,{color:"primary"})})]})}function Ce({mappings:t=[],setShowMapping:n=()=>{},setMappings:a=()=>{},additionalPayload:r={},firstLineHeaders:l=[]}){const u=V(),{enqueueSnackbar:c}=W(),[i,s]=x.useState(!1),{missingFields:o,hasMissingField:m,duplicateFields:d,hasDuplicates:y,exceededFieldLimits:g,hasExceededLimit:C,hasEmptyField:h}=ie(t),j=m||y||C||h,b=()=>{n(!1),a([])},w=async()=>{var f,S;s(!0);try{const v=t==null?void 0:t.filter(I=>I==null?void 0:I.import).map(I=>I==null?void 0:I.name),q={mapping:le(t),...r,first_line:l,import_fields:v},D=await T.post.importProductFromFile(q);D&&D.status<400&&(c("Import started successfully. You'll be notified once the process is complete.",{variant:"success"}),u.push("/products"))}catch(v){console.log(v),c(((S=(f=v==null?void 0:v.response)==null?void 0:f.data)==null?void 0:S.message)||"Import failed. Please try again or contact support if the issue persists.",{variant:"error"})}finally{s(!1)}};return e.jsxs(p,{display:"flex",m:1,gridGap:8,children:[e.jsx(E,{variant:"contained",size:"small",onClick:b,children:"Back"}),e.jsx(ue,{text:"Start Import",handleClick:w,disabled:j,loading:i,minWidth:95}),m&&e.jsx(P,{title:e.jsxs(e.Fragment,{children:["The following required fields are not mapped:"," ",e.jsx("span",{style:{fontWeight:500,color:"orange"},children:o.join(", ")})," ","Please complete the mapping to ensure product data syncs correctly."]}),children:e.jsx(M,{size:"small",children:e.jsx(B,{color:"error"})})}),y&&e.jsx(P,{title:e.jsxs(e.Fragment,{children:["The following fields have duplicates:"," ",e.jsx("span",{style:{fontWeight:500,color:"orange"},children:d.join(", ")}),". Please rename or remove any fields with duplicate names."]}),children:e.jsx(M,{size:"small",children:e.jsx(B,{color:"error"})})}),C&&e.jsx(P,{title:e.jsxs(e.Fragment,{children:["Maximum of"," ",e.jsx("span",{style:{fontWeight:500,color:"orange"},children:g.map(f=>`${f.maxFields} ${f.label||f.name}`).join(", ")})," ","allowed."]}),children:e.jsx(M,{size:"small",children:e.jsx(B,{color:"error"})})})]})}function Ie({mappings:t,setMappings:n,firstLineHeaders:a,setShowMapping:r,additionalPayload:l={}}){const u=Z(),[c,i]=x.useState(!1);return x.useEffect(()=>{const s=async()=>{i(!0);try{const o=await T.post.recommendedMapping({input_fields:a});if(o&&o.status<400){const m=o.data,d=_.map(h=>{const j=m[h.name],b=!j||Array.isArray(j)&&j.length===0;return{...h,field:Array.isArray(j)?j:j||"",import:!b||h.required,default:!0}}),y=_.map(h=>h.name),g=Object.keys(m).filter(h=>!y.includes(h)).map(h=>({name:pe(h),field:m[h],uuid:J(),import:!1})),C=[...d,...g];n(C)}}catch(o){console.log(o)}i(!1)};a.length!==0&&s()},[a]),e.jsxs(U.Fragment,{children:[e.jsx(ce,{mappings:t,setMappings:n,currentFirstLine:a,appName:u}),e.jsx(Ce,{mappings:t,setShowMapping:r,setMappings:n,additionalPayload:l,firstLineHeaders:a}),e.jsx(de,{loading:c})]})}function mt(){const t=Q(d=>{var y,g;return(g=(y=d==null?void 0:d.account)==null?void 0:y.user)==null?void 0:g.mainstore_type}),n=V();if(t!=="litcommerce")return e.jsx(H,{to:"/products"});
1const[a,r]=x.useState([]),[l,u]=x.useState([]),[c,i]=x.useState(!1),[s,o]=x.useState({}),m=()=>c?e.jsx(Ie,{mappings:a,setMappings:r,firstLineHeaders:l,setShowMapping:i,additionalPayload:s}):e.jsx(ve,{setShowMapping:i,setFirstLineHeaders:u,setMappings:r,setAdditionalPayload:o});return e.jsxs(ee,{header:"Import Products",children:[e.jsxs(p,{alignItems:"center",mb:2,children:[e.jsxs(p,{display:"flex",alignItems:"center",mb:1,onClick:()=>n.push("/products"),children:[e.jsx(se,{fontSize:"small",color:"primary",style:{cursor:"pointer"}}),e.jsx(k,{style:{fontSize:13,cursor:"pointer"},children:"Back to All Products"})]}),e.jsx(te,{color:"textPrimary",children:"Import Products"})]}),e.jsx(me,{style:{display:"flex",flexDirection:"column"},children:m()})]})}export{mt 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.