"use client"; import { useMemo, useState } from "react"; import { AppShell } from "@/components/AppShell"; 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"; interface RulesPageProps { project: ProjectResponse; initialRules: RuleView[]; } // 规则页(UX §7):四级规则列表 + 新增(乐观 + 回滚)。 export function RulesPage({ project, initialRules }: RulesPageProps) { const { items, busy, add } = 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 (

新增规则