"use client"; import { useState } from "react"; type MenuItem = { id: string; label: string; path: string; visible: boolean; order: number }; const initialMenus: MenuItem[] = [ { id: "1", label: "홈", path: "/", visible: true, order: 1 }, { id: "2", label: "게시판", path: "/boards", visible: true, order: 2 }, { id: "3", label: "쿠폰", path: "/coupons", visible: false, order: 3 }, ]; export default function AdminMenusPage() { const [menus, setMenus] = useState(initialMenus); const [form, setForm] = useState<{ label: string; path: string; visible: boolean }>({ label: "", path: "", visible: true }); function addMenu() { if (!form.label.trim() || !form.path.trim()) return; const next: MenuItem = { id: crypto.randomUUID(), label: form.label, path: form.path, visible: form.visible, order: menus.length + 1 }; setMenus((m) => [...m, next]); setForm({ label: "", path: "", visible: true }); } function removeMenu(id: string) { setMenus((m) => m.filter((x) => x.id !== id)); } function toggleVisible(id: string) { setMenus((m) => m.map((x) => (x.id === id ? { ...x, visible: !x.visible } : x))); } return (

메뉴 관리

{/* 추가 폼 */}
메뉴 추가
setForm({ ...form, label: e.target.value })} /> setForm({ ...form, path: e.target.value })} />
{/* 목록 */}
#
이름
경로
표시
관리
    {menus.sort((a, b) => a.order - b.order).map((m, idx) => (
  • {idx + 1}
    {m.label}
    {m.path}
  • ))}
); }