PageSourceSearch

https://app.stoqui.com.br/assets/EditVariationPage-DpdmqgWN.js

js stoqui.com.br collected 2026-10-01 15:19:08 UTC 16,006 bytes, 12 lines download raw bytes

1function __vite__mapDeps(indexes) {
2  if (!__vite__mapDeps.viteFileDeps) {
3    __vite__mapDeps.viteFileDeps = ["assets/index-D9stzMVV.js","assets/index-TALscxEc.js","assets/mui-CRsYZxVY.js","assets/vendor-Dwao9eNC.js","assets/query-8ViTdhdk.js","assets/datePickers-BIJXYOKG.js","assets/icons-D8aatgQ4.js","assets/lab-DSem1Osk.js","assets/index-TuPg2doO.css"]
4  }
5  return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
6}
7import{j as e,ab as w,q as k,a7 as c,C as X,G as Y,X as J,ai as Z,I as V,Z as ee,T as S,a2 as re,ag as A,an as te,O as oe,N as F,z as q,ae as E,y as B,ad as ae}from"./mui-CRsYZxVY.js";import{r as C,b as ie}from"./vendor-Dwao9eNC.js";import{m as ne,w as N,e as M,dG as se,r as O,fX as R,D as P,Q as W,dL as le,X as Q,x as ce,C as de,c1 as ue,b2 as me,fY as pe,O as z,J as ge,b as xe,T as D,K as be}from"./index-TALscxEc.js";import{u as he}from"./useProductVariations-zMUBu_ll.js";import{u as fe}from"./useProduct-BltDnkHr.js";import{u as je}from"./useEditVariation-CPM2Wx9Q.js";import{a as ve,b as ye}from"./query-8ViTdhdk.js";import{C as $,l as _e,ao as Ie}from"./icons-D8aatgQ4.js";import{H as Ce}from"./HelperText-CbfuMRy9.js";import{i as Pe}from"./barcodeGenerator-Bzfrlpsg.js";import{L as Se}from"./lab-DSem1Osk.js";import"./datePickers-BIJXYOKG.js";import"./HelpOutline-7HiWCqx6.js";import"./JsBarcode-CTZHrd1V.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};r.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new r.Error().stack;s&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[s]="869c4db6-cd07-410f-897a-6b695478f4ef",r._sentryDebugIdIdentifier="sentry-dbid-869c4db6-cd07-410f-897a-6b695478f4ef")})()}catch{}const we=()=>{const r=ve(),{triggerRevalidation:s}=ne();return ye({mutationFn:async d=>{const{productId:u,imageUrl:b,attributeFilters:m}=d;if(m.length===0)return{updatedCount:0,productId:u};const{data:v,error:_}=await N.from("produto_variacao").select(`
8          id,
9          produto_variacao_valor!inner (
10            atributo_valor_id
11          )
12        `).eq("produto_id",u).is("deletado_em",null);if(_)throw _;const p=(v==null?void 0:v.filter(l=>{const j=l.produto_variacao_valor.map(y=>y.atributo_valor_id);return m.some(y=>j.includes(y.attributeValueId))}).map(l=>l.id))||[];if(p.length===0)return{updatedCount:0,productId:u};const{error:h}=await N.from("produto_variacao").update({image_url:b}).in("id",p);if(h)throw h;return{updatedCount:p.length,productId:u}},onSuccess:d=>{d!=null&&d.productId&&(r.invalidateQueries({queryKey:["product-variations",String(d.productId)]}),r.invalidateQueries({queryKey:["product",String(d.productId)]})),r.invalidateQueries({queryKey:["products"]}),s()}})},ke=({control:r,isSubmitting:s})=>{const{data:d,isLoading:u}=M(),b=se(d),{triggerPaywall:m}=O(),[v,_]=C.useState(!1),p=R({control:r,name:"price"}),h=R({control:r,name:"promoPrice"}),l=(t,o)=>!t||!o||t<=0?0:(t-o)/t*100,j=Number(h)>0&&Number(h)<Number(p),y=l(Number(p),Number(h)),I=(t,o)=>{const n=t.target.value;!b&&n&&(o(""),m("variation_promo_price",{pageAction:()=>_(!0),source:"variation_form"}))};return e.jsxs(w,{spacing:2,children:[e.jsx(P,{name:"price",control:r,render:({field:t,fieldState:{error:o}})=>e.jsx(W,{...t,fullWidth:!0,label:j?"Preço original*":"Preço de venda*",variant:"outlined",error:!!o,helperText:o==null?void 0:o.message,disabled:s,InputProps:{startAdornment:e.jsx(k,{position:"start",children:"R$"}),sx:j?{"& input":{textDecoration:"line-through",color:"text.secondary"}}:{}}})}),e.jsx(P,{name:"promoPrice",control:r,rules:{validate:t=>{if(!t)return!0;const o=Number(p);return Number(t)>=o&&o>0?"O preço promocional deve ser menor que o preço original":!0}},render:({field:t,fieldState:{error:o}})=>e.jsx(W,{...t,fullWidth:!0,label:e.jsxs(w,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx("span",{children:"Preço promocional"}),e.jsx(le,{variant:b?"label":"text",fontSize:"0.75rem"})]}),variant:"outlined",error:!!o,helperText:(o==null?void 0:o.message)||"Deixe em branco se não houver promoção",disabled:s||u,onBlur:n=>{t.onBlur(),I(n,t.onChange)},InputProps:{startAdornment:e.jsx(k,{position:"start",children:"R$"}),endAdornment:j&&e.jsx(k,{position:"end",children:e.jsxs(c,{sx:{bgcolor:"success.main",color:"success.contrastText",px:1,borderRadius:1,fontSize:"0.75rem",fontWeight:500},children:[y.toFixed(0),"% OFF"]})})}})}),e.jsx(Q,{open:v,onClose:()=>_(!1),planSuggestion:"lite",description:"Criar preços promocionais está disponível a partir do plano LITE."})]})},qe=({open:r,onClose:s,onSelect:d,images:u,selectedImageUrl:b,attributeOptions:m=[]})=>{const v=X(),_=Y(v.breakpoints.up("md")),[p,h]=C.useState([]),[l,j]=C.useState(b||null),y=n=>{m.length>0?j(n):(d(n),s())},I=n=>{h(g=>g.some(f=>f.attributeId===n.attributeId&&f.attributeValueId===n.attributeValueId)?g.f
12ilter(f=>!(f.attributeId===n.attributeId&&f.attributeValueId===n.attributeValueId)):[...g,n])},t=()=>{l&&(d(l,p),o())},o=()=>{j(null),h([]),s()};return ie.useEffect(()=>{r&&(j(b||null),h([]))},[r,b]),e.jsxs(J,{open:r,onClose:o,maxWidth:"md",fullWidth:!0,children:[e.jsxs(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:["Selecionar imagem",e.jsx(V,{onClick:o,children:e.jsx($,{})})]}),e.jsxs(ee,{sx:{overflow:"hidden",display:"flex",flexDirection:"column"},children:[u.length===0?e.jsx(c,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"200px",flexDirection:"column"},children:e.jsx(S,{color:"text.secondary",variant:_?"body1":"body2",children:"Nenhuma imagem disponível."})}):e.jsx(c,{sx:{display:"flex",flexWrap:"wrap",gap:1,width:"100%",flex:"1 1 auto",minHeight:0,overflowY:"auto",p:0,alignContent:"flex-start"},children:u.map((n,g)=>e.jsxs(c,{onClick:()=>y(n),sx:{position:"relative",width:{xs:"70px",md:"80px"},height:{xs:"70px",md:"80px"},flexShrink:0,border:2,borderColor:l===n?"primary.main":"grey.300",borderRadius:1,bgcolor:"white",overflow:"hidden",cursor:"pointer",transition:"all 0.2s ease","&:hover":{borderColor:"primary.main"}},children:[e.jsx(c,{component:"img",src:n,alt:`Produto ${g+1}`,sx:{width:"100%",height:"auto",position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",objectFit:"contain"}}),l===n&&e.jsx(c,{sx:{position:"absolute",top:4,right:4},children:e.jsx(_e,{sx:{color:"primary.main",bgcolor:"white",borderRadius:"50%",fontSize:{xs:20,md:24}}})})]},g))}),l&&m.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(re,{sx:{mt:1.5,mb:1.5}}),e.jsxs(c,{sx:{px:.5},children:[e.jsx(S,{variant:"body1",sx:{mb:1,fontWeight:500},children:"Aplicar também em:"}),m.map(n=>e.jsx(A,{control:e.jsx(te,{size:"small",checked:p.some(g=>g.attributeId===n.attributeId&&g.attributeValueId===n.attributeValueId),onChange:()=>I(n)}),label:n.label,sx:{display:"flex",mb:.5,alignItems:"center","& .MuiFormControlLabel-label":{fontSize:{xs:"0.875rem",md:"1rem"}}}},`${n.attributeId}-${n.attributeValueId}`))]})]})]}),e.jsxs(oe,{sx:{p:2},children:[e.jsx(F,{onClick:o,color:"inherit",children:"Cancelar"}),l&&m.length>0?e.jsx(F,{onClick:t,variant:"contained",disabled:!l,children:"Confirmar"}):null]})]})},De=r=>{const{price:s,promoPrice:d,...u}=r,b=Number(s),m=Number(d);return{...u,preco:m||b,preco_cheio:m?b:null}},Ve=r=>{const{preco:s,preco_cheio:d,...u}=r;return{...u,price:d||s,promoPrice:d?s:null}},Ae=({variation:r,product:s,attributeOptions:d,onSubmit:u,onBulkUpdateImages:b})=>{const{data:m}=M(),{triggerPaywall:v}=O(),[_,p]=C.useState(!1),[h,l]=C.useState(!1),[j,y]=C.useState(!1),[I,t]=C.useState(null),o=ce(m),n=a=>a.map(i=>i.atributo_valor.valor).join(" / "),g=Ve({preco:r.preco,preco_cheio:r.preco_cheio||null,codigo_produto:r.codigo_produto,oculto:r.oculto,controlar_estoque:r.controlar_estoque,codigo_de_barras:r.codigo_de_barras,moq:r.moq}),T={id:r.id,price:g.price,promoPrice:g.promoPrice||null,codigo_produto:g.codigo_produto||"",oculto:g.oculto,nome:n(r.valores),controlar_estoque:g.controlar_estoque,codigo_de_barras:g.codigo_de_barras||"",image_url:o&&r.image_url||null,moq:g.moq||null},f=de({defaultValues:T}),H=f.handleSubmit(async a=>{y(!0);try{const i=De({price:a.price,promoPrice:a.promoPrice}),x={...a,preco:i.preco,preco_cheio:i.preco_cheio,codigo_produto:a.codigo_produto&&a.codigo_produto.trim()!==""?a.codigo_produto:null,codigo_de_barras:a.codigo_de_barras&&a.codigo_de_barras.trim()!==""?a.codigo_de_barras:null,image_url:o&&a.image_url||null,moq:o&&a.moq||null};await u(x),b&&o&&I&&I.attributeFilters.length>0&&(await b(I.imageUrl,I.attributeFilters),t(null))}finally{y(!1)}});return e.jsxs(e.Fragment,{children:[e.jsx("form",{onSubmit:H,children:e.jsxs(w,{spacing:3,children:[e.jsx(S,{variant:"h6",fontWeight:"500",children:n(r.valores)}),e.jsx(ke,{control:f.control,isSubmitting:j}),e.jsx(P,{name:"codigo_produto",control:f.control,render:({field:a,fieldState:{error:i}})=>e.jsx(q,{...a,fullWidth:!0,label:"Código do item",variant:"outlined",error:!!i,helperText:i==null?void 0:i.message})}),e.jsx(c,{sx:{flexShrink:0},children:e.jsx(P,{name:"codigo_de_barras",control:f.control,render:({field:a,fieldState:{error:i}})=>e.jsx(q,{...a,fullWidth:!0,label:"Código de barras (EAN, UPC...)",variant:"outlined",error:!!i,helperText:(i==null?void 0:i.message)||(Pe(a.value,r.id)?"Código gerado automaticamente pelo Stoqui":"Deixe em branco para gerar automaticamente"),InputLabelProps:{shrink:!0},onFocus:x=>{x.target.select()},onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),x.target.blur())},InputProps:{endAdornment:ue.isNativePlatform()&&e.jsx(k,{position:"end",children:e.jsx(V,{"aria-label":"scan barcode",onClick:async()=>{try{const{CapacitorBarcodeScanner:x,CapacitorBarcodeScannerTypeHintALLOption:K,CapacitorBarcodeScannerAndroidScanningLibrary:U}=await me(()=>import("./index-D9stzMVV.js").then(G=>G.i),__vite__mapDeps([0,1,2,3,4,5,6,7,8]));document.body.classList.add("scanner-active");const L=await x.scanBarcode({hint:K.ALL,android:{scanningLibrary:U.MLKIT}});document.body.classList.remove("scanner-active"),L.ScanResult&&a.onChange(L.ScanResult)}catch(x){document.body.classList.remove("scanner-active"),x&&x.message&&x.message.toLowerCase().includes("cancelled")||console.error("Barcode scan error",x)}},edge:"end",children:e.jsx(pe,{})})})}})})}),e.jsx(P,{name:"moq",control:f.control,render:({field:a})=>e.jsx(q,{...a,value:a.value??"",onChange:i=>a.onChange(i.target.value===""?null:Number(i.target.value)),fullWidth:!0,label:e.jsxs(c,{component:"span",sx:{dis
12play:"flex",alignItems:"center",gap:.5},children:["Pedido mínimo (MOQ)",e.jsx(z,{variant:o?"label":"text",fontSize:"0.75rem"}),e.jsx(Ce,{text:"MOQ (Minimum Order Quantity) é a quantidade mínima que pode ser comprada desta variação. Esta regra aplica-se apenas a vendas online. Se definido, os clientes devem adicionar ao carrinho pelo menos esta quantidade para poder comprar a variação.",dialogTitle:"Pedido mínimo (MOQ)",iconSize:"small"})]}),type:"number",variant:"outlined",InputLabelProps:{shrink:!0},disabled:!o,onWheel:i=>i.target.blur(),sx:{"& input[type=number]":{"-moz-appearance":"textfield"},"& input[type=number]::-webkit-outer-spin-button":{"-webkit-appearance":"none",margin:0},"& input[type=number]::-webkit-inner-spin-button":{"-webkit-appearance":"none",margin:0}}})}),e.jsx(P,{name:"oculto",control:f.control,render:({field:a})=>e.jsxs(c,{children:[e.jsx(A,{control:e.jsx(E,{checked:a.value,onChange:i=>a.onChange(i.target.checked)}),label:"Ocultar variação"}),e.jsx(B,{children:"Variação não aparecerá na loja"})]})}),(s==null?void 0:s.controlar_estoque)&&e.jsx(P,{name:"controlar_estoque",control:f.control,render:({field:a})=>e.jsxs(c,{children:[e.jsx(A,{control:e.jsx(E,{checked:a.value,onChange:i=>a.onChange(i.target.checked)}),label:"Controlar estoque"}),e.jsx(B,{children:"Ative para gerenciar o estoque desta variação"})]})}),e.jsxs(c,{children:[e.jsxs(w,{direction:"row",spacing:1,alignItems:"center",sx:{mb:1},children:[e.jsx(S,{variant:"subtitle2",children:"Imagem da variação"}),e.jsx(z,{variant:o?"label":"text",fontSize:"0.75rem"})]}),e.jsx(P,{name:"image_url",control:f.control,render:({field:a})=>e.jsx(c,{onClick:()=>{if(!o&&!a.value){v("variation_image",{pageAction:()=>l(!0),source:"variation_form"});return}p(!0)},sx:{width:"100%",height:120,cursor:"pointer",border:1,borderColor:"grey.300",borderRadius:1,bgcolor:"white",position:"relative",p:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main"}},children:a.value&&o?e.jsxs(c,{sx:{position:"relative",width:"100%",height:"100%"},children:[e.jsx(c,{component:"img",src:a.value,alt:"Imagem da variação",sx:{width:"100%",height:"100%",objectFit:"contain",borderRadius:1}}),e.jsx(c,{sx:{position:"absolute",top:0,right:0,display:"flex",gap:.5,p:.5,bgcolor:"rgba(255, 255, 255, 0.9)",borderRadius:1},children:e.jsx(V,{size:"small",onClick:i=>{i.stopPropagation(),a.onChange(null)},sx:{color:"error.main"},children:e.jsx($,{})})})]}):e.jsxs(c,{display:"flex",alignItems:"center",justifyContent:"center",sx:{width:"100%",height:"100%",bgcolor:"grey.50",border:1,borderStyle:"dashed",borderColor:"grey.300",borderRadius:1,flexDirection:"column",gap:1},children:[e.jsx(Ie,{sx:{fontSize:32,color:"grey.400"}}),e.jsx(S,{variant:"body2",color:"text.secondary",textAlign:"center",children:"Selecionar do produto"}),e.jsx(S,{variant:"caption",color:"text.secondary",textAlign:"center",children:"Clique para escolher uma das imagens do produto"})]})})})]}),e.jsx(w,{direction:"row",spacing:2,sx:{pt:2},children:e.jsx(Se,{type:"submit",variant:"contained",loading:j,fullWidth:!0,children:"Salvar"})})]})}),o&&e.jsx(qe,{open:_,onClose:()=>p(!1),onSelect:(a,i)=>{f.setValue("image_url",a),i&&i.length>0&&t({imageUrl:a,attributeFilters:i.map(x=>({attributeId:x.attributeId,attributeValueId:x.attributeValueId}))}),p(!1)},images:(s==null?void 0:s.image_url)||[],selectedImageUrl:f.watch("image_url"),attributeOptions:d}),e.jsx(Q,{open:h,onClose:()=>l(!1),description:"Adicionar imagens específicas para variações de produtos é um recurso exclusivo do plano PRO. Assine agora para aproveitar este e outros benefícios."})]})},Ke=()=>{const{productId:r,variationId:s}=ge(),d=xe(),{data:u,isLoading:b}=he(r),{data:m}=fe(r??""),v=je(),_=we(),[p,h]=C.useState(null),l=u==null?void 0:u.find(t=>t.id===parseInt(s||"0")),j=C.useMemo(()=>l?l.valores.map(t=>({attributeId:t.atributo.id,attributeValueId:t.atributo_valor.id,attributeName:t.atributo.nome,attributeValue:t.atributo_valor.valor,label:`Todos com ${t.atributo.nome}: ${t.atributo_valor.valor}`})):[],[l]),y=async t=>{if(!(!s||!r)){h(null);try{await v.mutateAsync({id:parseInt(s),preco:t.preco,preco_cheio:t.preco_cheio,codigo_produto:t.codigo_produto,oculto:t.oculto,controlar_estoque:t.controlar_estoque,codigo_de_barras:t.codigo_de_barras,image_url:t.image_url,moq:t.moq}),d(-1)}catch(o){o&&o.message?h(o.message):h("Ocorreu um erro ao salvar a variação."),console.error("Error saving variation:",o)}}},I=async(t,o)=>{r&&await _.mutateAsync({productId:parseInt(r),imageUrl:t,attributeFilters:o})};return b?e.jsxs(c,{sx:{display:"flex",flexDirection:"column"},children:[e.jsx(D,{title:"Carregando...",navigateBack:!0}),e.jsx(c,{sx:{flex:1,p:2},children:e.jsx(S,{children:"Carregando variação..."})})]}):l?e.jsxs(c,{sx:{display:"flex",flexDirection:"column"},children:[e.jsx(D,{title:"Editar variação",navigateBack:!0}),e.jsxs(c,{sx:{flex:1,p:2},children:[p&&e.jsx(ae,{severity:"error",sx:{mb:2},children:p}),l&&m&&e.jsx(Ae,{variation:l,product:m,attributeOptions:j,onSubmit:y,onBulkUpdateImages:I})]})]}):e.jsxs(c,{sx:{display:"flex",flexDirection:"column"},children:[e.jsx(D,{title:"Variação não encontrada",navigateBack:!0}),e.jsx(c,{sx:{flex:1,p:2},children:e.jsx(be,{primaryText:"Variação não encontrada",secondaryText:"Esta variação pode ter sido removida ou não existe."})})]})};export{Ke 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.