"use client"; import { Plus, Trash2 } from "lucide-react"; import { useMemo, useState } from "react"; import { AppShell } from "@/components/AppShell"; import { Button } from "@/components/ui/Button"; import { EmptyState } from "@/components/ui/EmptyState"; import { Field } from "@/components/ui/Field"; import { PageHeader } from "@/components/ui/PageHeader"; import { Select } from "@/components/ui/Select"; import { TextArea } from "@/components/ui/TextArea"; import type { ProjectResponse, RuleView } from "@/lib/api/types"; import { RULE_LEVELS, RULE_LEVEL_LABELS, groupByLevel, type RuleLevel, } from "@/lib/rules/rules"; import { useRules } from "@/lib/rules/useRules"; import { cardClass } from "@/lib/ui/variants"; interface RulesPageProps { project: ProjectResponse; initialRules: RuleView[]; } // 规则页(UX §7):四级规则列表 + 新增(乐观 + 回滚)。 export function RulesPage({ project, initialRules }: RulesPageProps) { const { items, busy, add, remove } = useRules(initialRules); const [level, setLevel] = useState("project"); const [content, setContent] = useState(""); const groups = useMemo(() => groupByLevel(items), [items]); const onSubmit = async (e: React.FormEvent): Promise => { e.preventDefault(); const ok = await add(project.id, level, content); if (ok) setContent(""); }; return (

新增规则