1- import { useRef , useState } from 'react' ;
2-
1+ import React , { FC , useRef , useState } from 'react' ;
32import { NavLink } from 'react-router-dom' ;
4-
53import {
64 Avatar ,
75 Box ,
86 Button ,
97 Divider ,
108 Hidden ,
11- lighten ,
129 List ,
1310 ListItem ,
1411 ListItemText ,
1512 Popover ,
1613 Typography
1714} from '@mui/material' ;
18-
19- import InboxTwoToneIcon from '@mui/icons-material/InboxTwoTone' ;
20- import { styled } from '@mui/material/styles' ;
15+ import { styled , lighten } from '@mui/material/styles' ;
2116import ExpandMoreTwoToneIcon from '@mui/icons-material/ExpandMoreTwoTone' ;
2217import AccountBoxTwoToneIcon from '@mui/icons-material/AccountBoxTwoTone' ;
23- import LockOpenTwoToneIcon from '@mui/icons-material/LockOpenTwoTone ' ;
18+ import InboxTwoToneIcon from '@mui/icons-material/InboxTwoTone ' ;
2419import AccountTreeTwoToneIcon from '@mui/icons-material/AccountTreeTwoTone' ;
20+ import LockOpenTwoToneIcon from '@mui/icons-material/LockOpenTwoTone' ;
21+ import { useQuery } from '@apollo/client' ;
22+ import { GET_USER_INFO } from 'src/graphql/request' ;
23+ import { useAuth } from 'src/contexts/AuthContext' ;
2524
2625const UserBoxButton = styled ( Button ) (
2726 ( { theme } ) => `
28- padding-left: ${ theme . spacing ( 1 ) } ;
29- padding-right: ${ theme . spacing ( 1 ) } ;
27+ padding-left: ${ theme . spacing ( 1 ) } ;
28+ padding-right: ${ theme . spacing ( 1 ) } ;
3029`
3130) ;
3231
3332const MenuUserBox = styled ( Box ) (
3433 ( { theme } ) => `
35- background: ${ theme . colors . alpha . black [ 5 ] } ;
36- padding: ${ theme . spacing ( 2 ) } ;
34+ background: ${ theme . colors . alpha . black [ 5 ] } ;
35+ padding: ${ theme . spacing ( 2 ) } ;
3736`
3837) ;
3938
4039const UserBoxText = styled ( Box ) (
4140 ( { theme } ) => `
42- text-align: left;
43- padding-left: ${ theme . spacing ( 1 ) } ;
41+ text-align: left;
42+ padding-left: ${ theme . spacing ( 1 ) } ;
4443`
4544) ;
4645
4746const UserBoxLabel = styled ( Typography ) (
4847 ( { theme } ) => `
49- font-weight: ${ theme . typography . fontWeightBold } ;
50- color: ${ theme . palette . secondary . main } ;
51- display: block;
48+ font-weight: ${ theme . typography . fontWeightBold } ;
49+ color: ${ theme . palette . secondary . main } ;
50+ display: block;
5251`
5352) ;
5453
5554const UserBoxDescription = styled ( Typography ) (
5655 ( { theme } ) => `
57- color: ${ lighten ( theme . palette . secondary . main , 0.5 ) }
56+ color: ${ lighten ( theme . palette . secondary . main , 0.5 ) } ;
5857`
5958) ;
6059
61- function HeaderUserbox ( ) {
62- const user = {
63- name : 'Catherine Pike' ,
64- avatar : '/static/images/avatars/1.jpg' ,
65- jobtitle : 'Project Manager'
66- } ;
67-
60+ export const HeaderUserbox = ( ) => {
61+ const { user, isLoading, logout } = useAuth ( ) ;
62+ console . log ( 'user' , user ) ;
6863 const ref = useRef < any > ( null ) ;
6964 const [ isOpen , setOpen ] = useState < boolean > ( false ) ;
7065
@@ -79,12 +74,13 @@ function HeaderUserbox() {
7974 return (
8075 < >
8176 < UserBoxButton color = "secondary" ref = { ref } onClick = { handleOpen } >
82- < Avatar variant = "rounded" alt = { user . name } src = { user . avatar } />
77+ < Avatar variant = "rounded" alt = { user . username } src = { user . avatarUrl } />
8378 < Hidden mdDown >
8479 < UserBoxText >
85- < UserBoxLabel variant = "body1" > { user . name } </ UserBoxLabel >
80+ < UserBoxLabel variant = "body1" > { user . username } </ UserBoxLabel >
81+ { /* 这里可根据需要展示 email 或其他信息 */ }
8682 < UserBoxDescription variant = "body2" >
87- { user . jobtitle }
83+ { user . email }
8884 </ UserBoxDescription >
8985 </ UserBoxText >
9086 </ Hidden >
@@ -106,11 +102,11 @@ function HeaderUserbox() {
106102 } }
107103 >
108104 < MenuUserBox sx = { { minWidth : 210 } } display = "flex" >
109- < Avatar variant = "rounded" alt = { user . name } src = { user . avatar } />
105+ < Avatar variant = "rounded" alt = { user . username } src = { user . avatarUrl } />
110106 < UserBoxText >
111- < UserBoxLabel variant = "body1" > { user . name } </ UserBoxLabel >
107+ < UserBoxLabel variant = "body1" > { user . username } </ UserBoxLabel >
112108 < UserBoxDescription variant = "body2" >
113- { user . jobtitle }
109+ { user . email }
114110 </ UserBoxDescription >
115111 </ UserBoxText >
116112 </ MenuUserBox >
@@ -135,14 +131,12 @@ function HeaderUserbox() {
135131 </ List >
136132 < Divider />
137133 < Box sx = { { m : 1 } } >
138- < Button color = "primary" fullWidth >
134+ < Button color = "primary" fullWidth onClick = { logout } >
139135 < LockOpenTwoToneIcon sx = { { mr : 1 } } />
140136 Sign out
141137 </ Button >
142138 </ Box >
143139 </ Popover >
144140 </ >
145141 ) ;
146- }
147-
148- export default HeaderUserbox ;
142+ } ;
0 commit comments