feat(portal-shell): implement portal-shell with apollo-router integration
M8: portal-shell unified frontend shell (Modular Monolith + micro-kernel). - Apollo Client -> apollo-router (port 4010, RSC prefetch) - 5 layouts: classic/focus/split/triple/canvas - Registry + PluginLoader (dynamic import ssr:false) - 3-layer props merge, Zustand PluginStore - 4 widgets: grades/notification-bell/user-menu/class-selector - config-service: new pluginConfig GraphQL resolver - apollo-router: CORS + header propagation for portal-shell - docker-compose.yml: portal-shell service block
This commit is contained in:
76
apps/portal-shell/src/widgets/topbar/user-menu/index.tsx
Normal file
76
apps/portal-shell/src/widgets/topbar/user-menu/index.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* user-menu(topbar / top)
|
||||
*
|
||||
* 通过 useWidgetQuery 查询 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 { 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 me = data?.me;
|
||||
const displayName = me?.name ?? user.name;
|
||||
const displayEmail = me?.email ?? user.email;
|
||||
const displayRole = me?.role ?? user.role;
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<button
|
||||
type="button"
|
||||
aria-label="用户菜单"
|
||||
aria-expanded={open}
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className="flex items-center gap-sm rounded-button bg-surface px-sm py-xs text-ink"
|
||||
>
|
||||
<span
|
||||
aria-hidden
|
||||
className="flex h-heading-3 w-heading-3 items-center justify-center rounded-full bg-accent text-ink-onAccent"
|
||||
>
|
||||
{displayName.charAt(0).toUpperCase()}
|
||||
</span>
|
||||
<span className="text-small">{displayName}</span>
|
||||
</button>
|
||||
{open ? (
|
||||
<ul className="absolute right-0 z-50 mt-sm w-56 rounded-card border border-rule bg-surface p-sm shadow-md">
|
||||
<li className="border-b border-rule py-xs">
|
||||
<p className="text-small text-ink">{displayName}</p>
|
||||
<p className="text-tiny text-ink-muted">{displayEmail}</p>
|
||||
</li>
|
||||
<li className="py-xs text-small text-ink-muted">
|
||||
角色:{displayRole}
|
||||
</li>
|
||||
</ul>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user