PageSourceSearch

https://app.stoqui.com.br/assets/CreateAttributePage-BlhpAD_F.js

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

1import{j as e,a7 as h,ab as P,T as C,z as D,q as B,I as K}from"./mui-CRsYZxVY.js";import{r as F}from"./vendor-Dwao9eNC.js";import{u as V,w as I,b as W,c8 as R,C as J,e8 as Q,T as Y,D as M}from"./index-TALscxEc.js";import{a as $,b as H}from"./query-8ViTdhdk.js";import{c as U}from"./colorService-BFHRdnHk.js";import{C as X}from"./icons-D8aatgQ4.js";import{L as G}from"./lab-DSem1Osk.js";import"./datePickers-BIJXYOKG.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new t.Error().stack;s&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[s]="716c1335-74e1-43d0-805e-ff21317047f0",t._sentryDebugIdIdentifier="sentry-dbid-716c1335-74e1-43d0-805e-ff21317047f0")})()}catch{}const Z=()=>{const t=$(),{user:s}=V(),i=s==null?void 0:s.id;return H({mutationFn:async({nome:f,valores:m,swatches:c})=>{if(!i)throw new Error("User must be logged in to create an attribute.");const{data:x,error:p}=await I.from("atributos").insert({nome:f,user_id:i}).select().single();if(p)throw p;if(m.length>0){const b=m.length,{error:y}=await I.from("atributo_valor").insert(m.map((j,g)=>({valor:j,atributo_id:x.id,user_id:i,destaque:b-g,swatch:c&&c[g]?c[g]:null})));if(y)throw y}return x},onSuccess:()=>{t.invalidateQueries({queryKey:["attributes"]})}})},N=150,ee=t=>["cor","color","colour"].some(i=>t.toLowerCase().includes(i.toLowerCase())),ce=()=>{const t=W(),s=R(),[i,f]=F.useState(!1),m=s.state,{sourceProduct:c,autoSelectForProduct:x,isCreationMode:p}=m||{},{control:b,handleSubmit:y,watch:j,formState:{isDirty:g,isValid:k}}=J({defaultValues:{name:"",values:[{value:""}]},mode:"onChange"}),{fields:u,append:S,remove:q}=Q({control:b,name:"values"}),n=j("values"),E=Z();F.useEffect(()=>{if(n&&n.length>0){const o=n[n.length-1];o&&o.value&&o.value.trim()!==""&&n.length<N&&S({value:""})}},[n,S]);const z=async o=>{const r=o.values.filter(a=>a.value.trim()!=="");if(!(r.length===0||!o.name.trim()))try{const a=ee(o.name),A=r.map(l=>l.value.trim());let v=[];if(a&&r.length>0){f(!0);const l=r.map(w=>w.value.trim());v=await U.classifyMultipleColors(l),f(!1)}const d=await E.mutateAsync({nome:o.name,valores:A,swatches:a?v:void 0});if(x&&d&&(p||c)){const{data:l,error:w}=await I.from("atributos").select(`
2            id,
3            valores:atributo_valor(id)
4          `).eq("id",d.id).single();if(w)console.error("Error fetching attribute:",w);else if(l&&l.valores){const L=l.valores.map(O=>O.id),T=p?"createProductAttributeSelections":`editProductAttributeSelections_${c}`,_=JSON.parse(localStorage.getItem(T)||"{}");_[d.id]=L,localStorage.setItem(T,JSON.stringify(_))}}t(-1)}catch(a){f(!1),console.error("Error creating attribute:",a)}};return e.jsxs(h,{sx:{display:"flex",flexDirection:"column"},children:[e.jsx(Y,{title:"Adicionar atributo",navigateBack:!0}),e.jsx(h,{sx:{flex:1,p:2,display:"flex",flexDirection:"column",overflowY:"auto"},children:e.jsx("form",{onSubmit:y(z),children:e.jsxs(P,{spacing:2,sx:{flex:1},children:[e.jsxs(h,{children:[e.jsx(C,{variant:"subtitle1",fontWeight:"500",color:"text.primary",sx:{mb:.5},children:"Nome do atributo"}),e.jsx(C,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:'Exemplo: "Cor", "Tamanho"'}),e.jsx(M,{name:"name",control:b,rules:{required:!0},render:({field:o})=>e.jsx(D,{...o,fullWidth:!0,inputMode:"text",autoComplete:"off",inputProps:{enterKeyHint:"next"}})})]}),e.jsxs(h,{children:[e.jsx(C,{variant:"subtitle1",fontWeight:"500",color:"text.primary",sx:{mb:.5},children:"Opções"}),e.jsx(C,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:'Exemplo: "Branco", "Azul"'}),e.jsx(P,{spacing:1,children:u.map((o,r)=>e.jsx(M,{name:`values.${r}.value`,control:b,render:({field:{value:a,onChange:A,onBlur:v}})=>e.jsx(D,{value:a,onChange:d=>{A(d),r===u.length-1&&d.target.value.trim()!==""&&u.length<N&&S({value:""})},onBlur:v,size:"small",placeholder:r===u.length-1?"Adicionar opção":"",variant:"outlined",inputMode:"text",autoComplete:"off",InputProps:{endAdornment:(a.trim()!==""||r!==u.length-1)&&e.jsx(B,{position:"end",children:e.jsx(K,{edge:"end",size:"small",onClick:()=>{r===u.length-1&&a.trim()===""||q(r)},sx:{color:"text.secondary"},children:e.jsx(X,{fontSize:"small"})})})},sx:{bgcolor:"white","& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"}}}})},o.id))})]}),e.jsx(h,{sx:{mt:"auto",pt:2},children:e.jsx(G,{variant:"contained",fullWidth:!0,type:"submit",loading:E.isPending||i,disabled:!g||!k||!n.some(o=>o.value.trim()!==""),size:"large",children:"Salvar"})})]})})})]})};export{ce 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.