PageSourceSearch

https://app.stoqui.com.br/assets/ImportProductsPage-BI25G7cd.js

js stoqui.com.br collected 2026-09-24 11:58:06 UTC 4,563 bytes, 2 lines download raw bytes

1import{j as e,a7 as n,H as j,T as c,N as D,Q as w,R as v,ac as I,ao as x,as as k}from"./mui-CRsYZxVY.js";import{r as u}from"./vendor-Dwao9eNC.js";import{d as q,a as F,f as $}from"./formatRelativeDateAndTime-DMOe89_J.js";import{u as _,w as R,c as A,T as K,b3 as N,K as O,b as Q,cF as z,cR as M}from"./index-TALscxEc.js";import{u as W,a as H}from"./query-8ViTdhdk.js";import{F as U}from"./FileSelector-D88j3gbb.js";import{L as Y}from"./lab-DSem1Osk.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};o.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var o=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},r=new o.Error().stack;r&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[r]="a719485b-2fd9-4549-8225-c58399cbb37d",o._sentryDebugIdIdentifier="sentry-dbid-a719485b-2fd9-4549-8225-c58399cbb37d")})()}catch{}const G=()=>{const{user:o}=_(),r=o==null?void 0:o.id;return W({queryKey:["imports"],queryFn:async()=>{if(!r)throw new Error("Usuário não autenticado");const{data:a,error:i}=await R.from("importacao").select("id, user_id, quantidade_produtos, criado_em").eq("user_id",r).order("criado_em",{ascending:!1});if(i)throw new Error(i.message);return a},enabled:!!r})},J=({id:o,date:r,productCount:a})=>{const i=Q();return e.jsx(v,{disablePadding:!0,onClick:()=>i(`/products/import/${o}`),sx:{border:"1px solid",borderColor:"divider"},children:e.jsxs(k,{children:[e.jsx(I,{primary:`Importação de ${a} ${a===1?"produto":"produtos"}`,secondary:$(z(r))}),e.jsx(M,{color:"primary"})]})})},ie=()=>{const{session:o}=_(),r=o==null?void 0:o.access_token,[a,i]=u.useState(null),[E,h]=u.useState(0),[y,g]=u.useState(!1),[p,d]=u.useState(null),T=H(),{data:m,isLoading:S,error:B}=G(),{data:f}=A(),C=t=>{i(t),t||h(s=>s+1)},L=async()=>{if(!a)return;d(null),g(!0);const t=new FormData;t.append("file",a);try{const s=await fetch("https://catalogo.stoqui.com.br/api/products/import",{method:"POST",body:t,headers:{Authorization:`Bearer ${r}`}}),l=await s.json();if(s.ok){const b=l.colunas_ignoradas??[],P=b.length>0?`
2Colunas ignoradas: ${b.join(", ")}.`:"";d({show:!0,message:`${l.count} ${l.count===1?"produto importado":"produtos importados"} com sucesso.${P}`,severity:"success"}),T.invalidateQueries({queryKey:["imports"]})}else throw new Error(l.error||"Falha ao importar produtos.")}catch(s){d({show:!0,message:s instanceof Error?s.message:"Erro desconhecido ao importar produtos.",severity:"error"})}finally{g(!1),i(null),h(s=>s+1)}};return e.jsxs(n,{sx:{display:"flex",flexDirection:"column"},children:[e.jsx(K,{title:"Importar produtos",navigateBack:!0}),e.jsxs(n,{sx:{flex:1,overflowY:"auto",padding:"16px",paddingBottom:"72px"},children:[e.jsxs(j,{elevation:0,sx:{p:2,mb:2,bgcolor:"white"},children:[e.jsx(c,{variant:"h6",gutterBottom:!0,color:"primary",fontWeight:"bold",children:"Nova importação"}),p&&e.jsx(n,{sx:{my:2},children:e.jsx(N,{severity:p.severity,onClose:()=>d(null),children:e.jsx(c,{variant:"body2",sx:{whiteSpace:"pre-line",wordBreak:"break-word"},children:p.message})})}),e.jsxs(n,{sx:{my:2},children:[e.jsx(U,{onFileChange:C,acceptedFileTypes:".csv, .xlsx, .xls"},E),e.jsx(Y,{loading:y,loadingPosition:"start",startIcon:e.jsx(q,{}),variant:"contained",fullWidth:!0,onClick:L,disabled:!a,sx:{mt:2},children:y?"Importando...":"Importar produtos"})]}),e.jsx(n,{sx:{display:"flex",justifyContent:"space-between",mt:2},children:e.jsx(D,{startIcon:e.jsx(F,{}),size:"small",sx:{flex:1,mr:1},component:"a",href:f==null?void 0:f.PRODUCT_IMPORT_SPREADSHEET_MODEL,children:"Baixar modelo"})})]}),e.jsxs(j,{elevation:0,sx:{p:2,bgcolor:"white"},children:[e.jsx(c,{variant:"h6",gutterBottom:!0,color:"primary",fontWeight:"bold",marginBottom:2,children:"Importações recentes"}),S?e.jsx(w,{disablePadding:!0,children:[1,2,3].map((t,s)=>e.jsxs(v,{sx:{border:"1px solid",borderColor:"divider"},children:[e.jsx(I,{primary:e.jsx(x,{width:"60%"}),secondary:e.jsx(x,{width:"40%"})}),e.jsx(x,{variant:"circular",width:24,height:24})]},s))}):B?e.jsx(c,{color:"error",children:"Erro ao carregar importações"}):m&&m.length>0?e.jsx(w,{disablePadding:!0,children:m.map(t=>
2e.jsx(J,{id:t.id,date:t.criado_em,productCount:t.quantidade_produtos},t.id))}):e.jsx(O,{primaryText:"Nenhuma importação recente",secondaryText:"As importações aparecerão aqui após serem realizadas"})]})]})]})};export{ie 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.