feat(portal-shell): extract domain API layer and migrate 31 widgets

Task 4-10 of portal-shell data abstraction plan (M1-M2).

Add 7 domain API modules under src/lib/api/ (parent/admin/teacher/
student/universal/sidebar/topbar), each exposing semantic hooks that
wrap useWidgetQuery/useWidgetMutation and return flattened domain
models. Widget code now imports from @/lib/api instead of inlining
gql literals.

- 31 widgets migrated (gql literal count in widgets: 0)
- 7 test files (85 cases, all passing)
- topbar.useNotifications renamed to useNotificationBell to avoid
  barrel export collision with universal.useNotifications
- typecheck + lint (0 errors) + test (85/85) verified
This commit is contained in:
SpecialX
2026-07-17 13:07:24 +08:00
parent f623dcf4a7
commit 2910a90271
73 changed files with 8206 additions and 87 deletions

View File

@@ -3,42 +3,22 @@
/**
* user-menutopbar / top
*
* 通过 useWidgetQuery 查询 apollo-router → iam 子图的 me 数据。
* 通过 useCurrentUser 查询 apollo-router → iam 子图的 me 数据。
* 展示用户头像 + 下拉菜单(昵称 / 邮箱 / 角色)。
*
* 关联portal-shell spec §5.6 统一 Hook、M8 验收
*/
import { gql } from "@apollo/client";
import { useState } from "react";
import { useWidgetQuery } from "@/lib/useWidgetQuery";
import { useCurrentUser } from "@/lib/api/topbar";
import { useAuth } from "@/providers/AuthProvider";
import type { PluginProps } from "@/lib/types";
const GET_CURRENT_USER = gql`
query GetCurrentUser {
me {
id
name
email
role
}
}
`;
interface MeQueryData {
me: { id: string; name: string; email: string; role: string } | null;
}
export default function UserMenu(_props: PluginProps): React.ReactElement {
const { user } = useAuth();
const [open, setOpen] = useState(false);
const { data } = useWidgetQuery<MeQueryData, Record<string, never>>(
GET_CURRENT_USER,
{},
);
const { data: me } = useCurrentUser();
const me = data?.me;
const displayName = me?.name ?? user.name;
const displayEmail = me?.email ?? user.email;
const displayRole = me?.role ?? user.role;