PageSourceSearch

https://carregamento3bs.lovable.app/assets/ProdutosMoegaPage-DJHVunYz.js

js carregamento3bs.lovable.app collected 2026-10-03 05:36:26 UTC 3,717 bytes, 1 lines download raw bytes

1import{u as w,r as h,j as e}from"./react-vendor-BorBU4Bs.js";import{u as C,a as P,b as g}from"./query-vendor-dlntIC_S.js";import{b as S,a$ as T,B as t,A as E,P as q,D as _,i as k,j as D,k as Q,L as z,I as A,N as I,O as L,Q as l,U as f,V as M,W as d,T as B,s as c}from"./index-DkhxOMdR.js";import{P as F}from"./pencil-Cf5Ul2CU.js";import"./radix-vendor-CazrR58L.js";import"./charts-vendor-BxJanGhU.js";import"./supabase-vendor-BxTHC7hl.js";import"./xlsx-vendor-DOnNs5_d.js";import"./qr-vendor-Ca1-Dxvv.js";function J(){const v=w(),[N,r]=h.useState(!1),[o,m]=h.useState(null),[u,n]=h.useState(""),{toast:i}=S(),j=C(),{data:p=[],isLoading:b}=P({queryKey:["moega_produtos"],queryFn:async()=>{const{data:s,error:a}=await c.from("moega_produtos").select("*").order("nome");if(a)throw a;return s}}),x=g({mutationFn:async()=>{if(o){const{error:s}=await c.from("moega_produtos").update({nome:u}).eq("id",o);if(s)throw s}else{const{error:s}=await c.from("moega_produtos").insert({nome:u});if(s)throw s}},onSuccess:()=>{j.invalidateQueries({queryKey:["moega_produtos"]}),r(!1),m(null),n(""),i({title:o?"Atualizado!":"Cadastrado!"})},onError:s=>i({title:"Erro",description:s.message,variant:"destructive"})}),y=g({mutationFn:async s=>{const{error:a}=await c.from("moega_produtos").delete().eq("id",s);if(a)throw a},onSuccess:()=>{j.invalidateQueries({queryKey:["moega_produtos"]}),i({title:"Removido!"})},onError:s=>i({title:"Erro",description:s.message,variant:"destructive"})});return e.jsxs("div",{className:"animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 mb-6",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-primary/20 text-primary",children:e.jsx(T,{className:"h-6 w-6"})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Produtos da Moega"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Cadastre os produtos disponíveis para as moegas"})]}),e.jsxs(t,{variant:"ghost",size:"sm",className:"-ml-2 mb-4",onClick:()=>v("/configuracoes"),children:[e.jsx(E,{className:"h-4 w-4 mr-1"})," Voltar ao menu"]}),e.jsx("div",{className:"flex justify-end mb-6",children:e.jsxs(t,{onClick:()=>{m(null),n(""),r(!0)},children:[e.jsx(q,{className:"h-4 w-4 mr-2"})," Novo Produto"]})}),e.jsx(_,{open:N,onOpenChange:r,children:e.jsxs(k,{children:[e.jsx(D,{children:e.jsxs(Q,{children:[o?"Editar":"Novo"," Produto"]})}),e.jsxs("form",{onSubmit:s=>{s.preventDefault(),x.mutate()},className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{children:"Nome"}),e.jsx(A,{value:u,onChange:s=>n(s.target.value),required:!0,placeholder:"Ex: Milho"})]}),e.jsx(t,{type:"submit",className:"w-full",disabled:x.isPending,children:x.isPending?"Salvando...":"Salvar"})]})]})}),e.jsx("div",{className:"bg-card rounded-lg border",children:e.jsxs(I,{children:[e.jsx(L,{children:e.jsxs(l,{className:"table-header",children:[e.jsx(f,{children:"Nome"}),e.jsx(f,{className:"w-24",children:"Ações"})]})}),e.jsx(M,{children:b?e.jsx(l,{children:e.jsx(d,{colSpan:2,className:"text-center text-muted-foreground",children:"Carregando..."})}):p.length===0?e.jsx(l,{children:e.jsx(d,{colSpan:2,className:"text-center text-muted-foreground",children:"Nenhum produto encontrado"})}):p.map(s=>e.jsxs(l,{children:[e.jsx(d,{className:"font-medium",children:s.nome}),e.jsx(d,{children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(t,{variant:"ghost",size:"icon",onClick:()=>{m(s.id),n(s.nome),r(!0)},children:e.jsx(F,{className:"h-4 w-4"})}),e.jsx(t,{variant:"ghost",size:"icon",onClick:()=>y.mutate(s.id),children:e.jsx(B,{className:"h-4 w-4 text-destructive"})})]})})]},s.id))})]})})]})}export{J 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.