PageSourceSearch

https://app.stoqui.com.br/assets/CustomShippingConfigPage-BGwCOc5l.js

js stoqui.com.br collected 2026-10-01 15:18:45 UTC 8,041 bytes, 1 lines download raw bytes

1import{j as e,a7 as u,a6 as B,ag as W,ae as O,T as x,ab as g,N as D,ad as K,Q as G,R as H,I,ac as M,X as U,ai as V,Z as X,z as q,q as Y,O as Z}from"./mui-CRsYZxVY.js";import{b as y}from"./vendor-Dwao9eNC.js";import{d as J}from"./Edit-BiqqVQWD.js";import{y as _,bx as ee,fi as re,by as S,z as w,w as m,t as ae,l as oe,u as te,C as ie,T as ne,dO as se,D as j,Q as le,F as de}from"./index-TALscxEc.js";import{a as f,b as h}from"./query-8ViTdhdk.js";import{u as ce}from"./useCustomShipping-DufBA9hL.js";import{H as ue}from"./HelperText-CbfuMRy9.js";import{L as me}from"./lab-DSem1Osk.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";import"./HelpOutline-7HiWCqx6.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};a.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var a=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},o=new a.Error().stack;o&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[o]="3bd5a32f-5ec7-4432-9ab8-d1a72db46c07",a._sentryDebugIdIdentifier="sentry-dbid-3bd5a32f-5ec7-4432-9ab8-d1a72db46c07")})()}catch{}_().shape({habilitado:ee().required(),locations:re().of(_().shape({id:S().required(),name:w().required("Nome do local é obrigatório"),price:S().transform(a=>Number.isNaN(a)?null:a).typeError("Preço é obrigatório").required("Preço é obrigatório").min(0,"Preço não pode ser negativo")})).default([])});const pe=_().shape({name:w().required("Nome do local é obrigatório"),price:S().transform(a=>Number.isNaN(a)?null:a).typeError("Preço é obrigatório").required("Preço é obrigatório").min(0,"Preço não pode ser negativo"),prazo_entrega:w().transform(a=>{if(!a)return a;const o=a.trim();return/^\d+$/.test(o)?`${o} dias úteis`:o}).max(25,"Prazo de entrega deve ter no máximo 25 caracteres").optional()}),ge=()=>{const a=f();return h({mutationFn:async o=>{const{data:t,error:i}=await m.from("regiao_frete_personalizado").insert({configuracao_id:o.configId,nome:o.nome,valor:o.valor,prazo_entrega:o.prazo_entrega||null}).select().single();if(i)throw i;return t},onSuccess:()=>{a.invalidateQueries({queryKey:["customShipping"]})}})},fe=()=>{const a=f();return h({mutationFn:async o=>{const{data:t,error:i}=await m.from("regiao_frete_personalizado").update({nome:o.nome,valor:o.valor,prazo_entrega:o.prazo_entrega||null}).eq("id",o.id).select().single();if(i)throw i;return t},onSuccess:()=>{a.invalidateQueries({queryKey:["customShipping"]})}})},he=()=>{const a=f();return h({mutationFn:async o=>{const{error:t}=await m.from("regiao_frete_personalizado").update({deletado_em:new Date().toISOString()}).eq("id",o);if(t)throw t;return o},onSuccess:o=>{ae(oe.DELETE.SHIPPING_REGION,{regionId:o}),a.invalidateQueries({queryKey:["customShipping"]})}})},be=()=>{const a=f(),{user:o}=te(),t=o==null?void 0:o.id;return h({mutationFn:async i=>{if(!t)throw new Error("Not authenticated");const{data:d}=await m.from("configuracao_frete_personalizado").select("id").eq("user_id",t).single();if(d){const{data:n,error:s}=await m.from("configuracao_frete_personalizado").update({habilitado:i.habilitado}).eq("id",d.id).select().single();if(s)throw s;return n}else{const{data:n,error:s}=await m.from("configuracao_frete_personalizado").insert({user_id:t,habilitado:i.habilitado}).select().single();if(s)throw s;return n}},onMutate:async i=>{await a.cancelQueries({queryKey:["customShipping"]});const d=a.getQueryData(["customShipping"]);return d?a.setQueryData(["customShipping"],{...d,habilitado:i.habilitado}):a.setQueryData(["customShipping"],{id:-1,habilitado:i.habilitado,criado_em:new Date().toISOString(),regions:[]}),{previousConfig:d}},onError:(i,d,n)=>{n!=null&&n.previousConfig&&a.setQueryData(["customShipping"],n.previousConfig)},onSettled:()=>{a.invalidateQueries({queryKey:["customShipping"]})}})},Ie=()=>{const[a,o]=y.useState(!1),[t,i]=y.useState(null),[d,n]=y.useState(null),{data:s,isLoading:T}=ce(),z=be(),P=ge(),R=fe(),v=he(),{control:b,handleSubmit:L,reset:C,formState:{isSubmitting:A}}=ie({resolver:de(pe),defaultValues:{name:"",price:0,prazo_entrega:""}}),E=r=>
1r===0?"Grátis":r.toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),N=async r=>{try{n(null),await z.mutateAsync({habilitado:r})}catch{n("Erro ao atualizar configuração")}},Q=()=>{i(null),C({name:"",price:0,prazo_entrega:""}),o(!0)},k=r=>{i(r),r&&(C({name:r.nome,price:r.valor,prazo_entrega:r.prazo_entrega||""}),o(!0))},$=async r=>{try{n(null),await v.mutateAsync(r)}catch{n("Erro ao excluir região")}},F=async r=>{try{n(null),t?await R.mutateAsync({id:t.id,nome:r.name,valor:r.price,prazo_entrega:r.prazo_entrega}):s&&await P.mutateAsync({configId:s.id,nome:r.name,valor:r.price,prazo_entrega:r.prazo_entrega}),o(!1)}catch{n("Erro ao salvar região")}};if(T)return e.jsx(u,{sx:{display:"flex",alignItems:"center",justifyContent:"center",height:"70vh"},children:e.jsx(B,{})});const p=(s==null?void 0:s.habilitado)??!1;return e.jsxs(u,{children:[e.jsx(ne,{title:"Frete personalizado",navigateBack:!0}),e.jsxs(u,{sx:{display:"flex",flexDirection:"column",height:"calc(100% - 56px)"},children:[e.jsx(u,{sx:{py:2,borderBottom:1,borderColor:"divider"},children:e.jsxs(u,{children:[e.jsx(W,{control:e.jsx(O,{checked:p,onChange:r=>N(r.target.checked),color:"primary",disabled:z.isPending}),labelPlacement:"start",label:e.jsx(x,{variant:"subtitle1",fontWeight:500,children:"Habilitar frete personalizado"})}),e.jsx(x,{variant:"body2",color:"text.secondary",sx:{mt:.5,ml:2},children:"Configure preços diferentes para cada região de entrega"})]})}),e.jsx(g,{spacing:3,sx:{p:2,flexGrow:1},children:e.jsxs(u,{sx:{opacity:p?1:.5},children:[e.jsx(D,{variant:"contained",fullWidth:!0,onClick:Q,disabled:!p,children:"Adicionar local de entrega"}),d&&e.jsx(K,{severity:"error",sx:{mt:2},children:d}),e.jsx(G,{sx:{width:"100%",p:0,mt:2},children:s==null?void 0:s.regions.map(r=>e.jsx(H,{sx:{mb:1,borderRadius:1,border:1,borderColor:"divider"},secondaryAction:e.jsxs(g,{direction:"row",spacing:1,children:[e.jsx(I,{edge:"end",onClick:()=>k(r),disabled:!p,size:"small",children:e.jsx(J,{fontSize:"small"})}),e.jsx(I,{edge:"end",onClick:()=>$(r.id),disabled:!p||v.isPending,size:"small",children:e.jsx(se,{fontSize:"small"})})]}),children:e.jsx(M,{primary:r.nome,secondary:r.prazo_entrega?`${E(r.valor)} • ${r.prazo_entrega}`:E(r.valor)})},r.id))})]})})]}),e.jsxs(U,{open:a,onClose:()=>o(!1),fullWidth:!0,maxWidth:"sm",children:[e.jsx(V,{children:t?"Editar local":"Adicionar local"}),e.jsxs(u,{component:"form",onSubmit:L(F),children:[e.jsx(X,{children:e.jsxs(g,{spacing:3,children:[e.jsx(j,{name:"name",control:b,render:({field:r,fieldState:l})=>{var c;return e.jsx(q,{...r,label:"Nome do local *",fullWidth:!0,error:!!l.error,helperText:((c=l.error)==null?void 0:c.message)||"Digite o nome do bairro, região ou cidade"})}}),e.jsx(j,{name:"price",control:b,render:({field:r,fieldState:l})=>{var c;return e.jsx(le,{...r,label:"Valor da entrega",fullWidth:!0,error:!!l.error,placeholder:"0,00",helperText:((c=l.error)==null?void 0:c.message)||"Digite o valor da taxa de entrega para este local",InputProps:{startAdornment:e.jsx(Y,{position:"start",children:"R$"})}})}}),e.jsxs(u,{children:[e.jsxs(g,{direction:"row",alignItems:"center",spacing:.5,sx:{mb:1},children:[e.jsx(x,{variant:"subtitle2",color:"text.secondary",children:"Prazo de entrega (opcional)"}),e.jsx(ue,{text:'Ex: "2 a 3 dias úteis", "Até 5 dias", "24 horas". Deixe em branco se não quiser especificar um prazo.'})]}),e.jsx(j,{name:"prazo_entrega",control:b,render:({field:r,fieldState:l})=>{var c;return e.jsx(q,{...r,fullWidth:!0,placeholder:'Ex: "2 a 3 dias úteis"',error:!!l.error,helperText:(c=l.error)==null?void 0:c.message,inputProps:{maxLength:25}})}})]})]})}),e.jsxs(Z,{children:[e.jsx(D,{onClick:()=>o(!1),children:"Cancelar"}),e.jsx(me,{type:"submit",variant:"contained",loading:A,children:t?"Salvar":"Adicionar"})]})]})]})]})};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.