PageSourceSearch

https://tosantofficial.lovable.app/assets/admin.menu-BKH9BzkB.js

js tosantofficial.lovable.app collected 2026-10-03 03:50:56 UTC 4,462 bytes, 1 lines download raw bytes

1import{c as b,w as N,m as w,s as c,r as k,j as e,t as l}from"./index-Bu_qGu7n.js";import{B as m}from"./button-CRt62nev.js";import{L as f,I as u}from"./label-2UGQn-GE.js";import{S as q,a as C,b as S,c as L,d as M}from"./select-DCoiv0ai.js";import{S as z}from"./switch-BGz0ux5w.js";import{P as B}from"./plus-CMVHNqqR.js";import{T as A}from"./trash-2-CRBqhxpw.js";import"./Combination-DS8eIzf_.js";import"./index-B9qJ-czE.js";const T=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],V=b("arrow-down",T);const F=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],I=b("arrow-up",F),g={header:"Header",footer_menu:"Footer — Menu",footer_legal:"Footer — Legal"};function $(){const p=N(),{data:x}=w({queryKey:["all_menu_items"],queryFn:async()=>{const{data:s,error:a}=await c.from("menu_items").select("*").order("location").order("sort_order");if(a)throw a;return s??[]}}),[t,n]=k.useState({label:"",url:"",location:"header"}),h=()=>{p.invalidateQueries({queryKey:["all_menu_items"]}),p.invalidateQueries({queryKey:["menu_items"]})},y=async s=>{if(s.preventDefault(),!t.label||!t.url)return;const a=(x??[]).filter(o=>o.location===t.location).reduce((o,i)=>Math.max(o,i.sort_order),0),{error:r}=await c.from("menu_items").insert({...t,sort_order:a+1});if(r)return l.error(r.message);l.success("Menu ditambahkan"),n({label:"",url:"",location:t.location}),h()},d=async(s,a)=>{const{error:r}=await c.from("menu_items").update(a).eq("id",s);if(r)return l.error(r.message);h()},_=async s=>{if(!confirm("Hapus item ini?"))return;const{error:a}=await c.from("menu_items").delete().eq("id",s);if(a)return l.error(a.message);l.success("Dihapus"),h()},j=async(s,a)=>{const r=x?.find(o=>o.id===s);r&&await d(s,{sort_order:r.sort_order+a})},v=["header","footer_menu","footer_legal"];return e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-2xl font-bold",children:"Menu Navigasi"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Atur link di header dan footer."}),e.jsxs("form",{onSubmit:y,className:"mt-6 rounded-xl border border-border bg-card p-5",children:[e.jsx("h2",{className:"font-display font-semibold",children:"Tambah Menu"}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{children:"Label"}),e.jsx(u,{value:t.label,onChange:s=>n({...t,label:s.target.value}),placeholder:"Beranda",required:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{children:"URL"}),e.jsx(u,{value:t.url,onChange:s=>n({...t,url:s.target.value}),placeholder:"/produk",required:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{children:"Lokasi"}),e.jsxs(q,{value:t.location,onValueChange:s=>n({...t,location:s}),children:[e.jsx(C,{children:e.jsx(S,{})}),e.jsx(L,{children:v.map(s=>e.jsx(M,{value:s,children:g[s]},s))})]})]}),e.jsx("div",{className:"flex items-end",children:e.jsxs(m,{type:"submit",className:"w-full",children:[e.jsx(B,{size:16})," Tambah"]})})]})]}),e.jsx("div",{className:"mt-6 space-y-6",children:v.map(s=>{const a=(x??[]).filter(r=>r.location===s).sort((r,o)=>r.sort_order-o.sort_order);return e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5",children:[e.jsx("h2",{className:"font-display font-semibold",children:g[s]}),a.length===0?e.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:"Belum ada item."}):e.jsx("ul",{className:"mt-4 divide-y divide-border",children:a.map((r,o)=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 py-3",children:[e.jsx(u,{className:"w-40",defaultValue:r.label,onBlur:i=>i.target.value!==r.label&&d(r.id,{label:i.target.value})}),e.jsx(u,{className:"flex-1 min-w-40",defaultValue:r.url,onBlur:i=>i.target.value!==r.url&&d(r.id,{url:i.target.value})}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>j(r.id,-1),disabled:o===0,children:e.jsx(I,{size:14})}),e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>j(r.id,1),disabled:o===a.length-1,children:e.jsx(V,{size:14})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{checked:r.is_active,onCheckedChange:i=>d(r.id,{is_active:i})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r.is_active?"Aktif":"Off"})]}),e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>_(r.id),children:e.jsx(A,{size:14})})]},r.id))})]},s)})})]})}export{$ as component};

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.