fix(scope): all pages react to company scope change via useScopeEffect

- Created useScopeEffect hook that auto-triggers reload on scope change
- Replaced useEffect([], []) with useScopeEffect in 20+ pages
- Risks/Reports/Dashboard also use useScopeEffect
- Removed redundant per-page useCompanyScope where only effect was needed
This commit is contained in:
selfrelease
2026-07-20 08:09:33 +08:00
parent 4265f4bc4c
commit c3232f73c8
23 changed files with 105 additions and 63 deletions
+4 -3
View File
@@ -1,7 +1,8 @@
"use client";
import { useEffect, useState } from "react";
import { useState } from "react";
import { listMajorEvents, listInquiries } from "@/lib/api-v2";
import { useScopeEffect } from "@/lib/company-scope";
import { PageContainer, Badge } from "@/components/shared/PageContainer";
import { LoadingSpinner } from "@/components/shared/LoadingSpinner";
import { EmptyState } from "@/components/shared/EmptyState";
@@ -26,7 +27,7 @@ export default function EventsPage() {
const [isLoading, setIsLoading] = useState(true);
const [tab, setTab] = useState<"events" | "inquiries">("events");
useEffect(() => {
useScopeEffect(() => {
Promise.all([listMajorEvents(), listInquiries()])
.then(([e, i]) => {
setEvents((e.data as MajorEvent[]) ?? []);
@@ -37,7 +38,7 @@ export default function EventsPage() {
setInquiries([]);
})
.finally(() => setIsLoading(false));
}, []);
});
return (
<PageContainer title="重大事项 & 追问清单" description="AI 从月报/弱信号中自动识别重大事项 + 生成追问清单">