You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
7.6 KiB

  1. import PropTypes from 'prop-types';
  2. import { useRef, useState } from 'react';
  3. // material-ui
  4. import { useTheme } from '@mui/material/styles';
  5. import {
  6. // Avatar,
  7. Box,
  8. ButtonBase,
  9. CardContent,
  10. ClickAwayListener,
  11. Grid,
  12. IconButton,
  13. Paper,
  14. Popper,
  15. Stack,
  16. // Tab,
  17. // Tabs,
  18. Typography
  19. } from '@mui/material';
  20. // project import
  21. import MainCard from 'components/MainCard';
  22. import Transitions from 'components/@extended/Transitions';
  23. // import ProfileTab from './ProfileTab';
  24. // import SettingTab from './SettingTab';
  25. // assets
  26. import avatar1 from 'assets/images/users/avatar-1.png';
  27. import { LogoutOutlined,
  28. // SettingOutlined, UserOutlined
  29. } from '@ant-design/icons';
  30. import { handleLogoutFunction } from 'auth/index';
  31. import {useNavigate} from "react-router-dom";
  32. import {useDispatch} from "react-redux";
  33. import AccountCircleIcon from '@mui/icons-material/AccountCircle';
  34. // tab panel wrapper
  35. function TabPanel({ children, value, index, ...other }) {
  36. return (
  37. <div role="tabpanel" hidden={value !== index} id={`profile-tabpanel-${index}`} aria-labelledby={`profile-tab-${index}`} {...other}>
  38. {value === index && children}
  39. </div>
  40. );
  41. }
  42. TabPanel.propTypes = {
  43. children: PropTypes.node,
  44. index: PropTypes.any.isRequired,
  45. value: PropTypes.any.isRequired
  46. };
  47. // function a11yProps(index) {
  48. // return {
  49. // id: `profile-tab-${index}`,
  50. // 'aria-controls': `profile-tabpanel-${index}`
  51. // };
  52. // }
  53. // ==============================|| HEADER CONTENT - PROFILE ||============================== //
  54. const Profile = () => {
  55. const theme = useTheme();
  56. const navigate = useNavigate()
  57. const dispatch = useDispatch()
  58. const handleLogout = async () => {
  59. dispatch(handleLogoutFunction());
  60. //await handleLogoutFunction();
  61. navigate('/login');
  62. };
  63. const userData = JSON.parse(localStorage.getItem("userData"));
  64. const anchorRef = useRef(null);
  65. const [open, setOpen] = useState(false);
  66. const handleToggle = () => {
  67. setOpen((prevOpen) => !prevOpen);
  68. };
  69. const handleClose = (event) => {
  70. if (anchorRef.current && anchorRef.current.contains(event.target)) {
  71. return;
  72. }
  73. setOpen(false);
  74. };
  75. // const [value, setValue] = useState(0);
  76. // const handleChange = (event, newValue) => {
  77. // setValue(newValue);
  78. // };
  79. const iconBackColorOpen = 'grey.300';
  80. return (
  81. <Box sx={{ flexShrink: 0, ml: 0.75 }}>
  82. <ButtonBase
  83. sx={{
  84. p: 0.25,
  85. bgcolor: open ? iconBackColorOpen : 'transparent',
  86. borderRadius: 1,
  87. '&:hover': { bgcolor: 'secondary.lighter' }
  88. }}
  89. aria-label={intl.formatMessage({id: 'openLanguage'})}
  90. ref={anchorRef}
  91. aria-controls={open ? 'profile-grow' : undefined}
  92. aria-haspopup="true"
  93. onClick={handleToggle}
  94. >
  95. <Stack direction="row" alignItems="center" sx={{ p: 0.5 }}>
  96. <AccountCircleIcon style={{ color: 'black' }} alt="profile user" src={avatar1} sx={{ width: 32, height: 32 }} />
  97. <Typography style={{ color: 'black', fontSize: "1.2rem" }} variant="subtitle1">{userData == null ? "" : (userData.fullenName?userData.fullenName: userData.fullchName)}</Typography>
  98. </Stack>
  99. </ButtonBase>
  100. <Popper
  101. placement="bottom-end"
  102. open={open}
  103. anchorEl={anchorRef.current}
  104. role={undefined}
  105. transition
  106. disablePortal
  107. popperOptions={{
  108. modifiers: [
  109. {
  110. name: 'offset',
  111. options: {
  112. offset: [0, 9]
  113. }
  114. }
  115. ]
  116. }}
  117. >
  118. {({ TransitionProps }) => (
  119. <Transitions type="fade" in={open} {...TransitionProps}>
  120. {open && (
  121. <Paper
  122. sx={{
  123. boxShadow: theme.customShadows.z1,
  124. width: 290,
  125. minWidth: 240,
  126. maxWidth: 290,
  127. [theme.breakpoints.down('md')]: {
  128. maxWidth: 250
  129. }
  130. }}
  131. >
  132. <ClickAwayListener onClickAway={handleClose}>
  133. <MainCard elevation={0} border={false} content={false}>
  134. <CardContent sx={{ px: 2.5, pt: 3 }}>
  135. <Grid container justifyContent="space-between" alignItems="center">
  136. <Grid item>
  137. <Stack direction="row" spacing={1.25} alignItems="center">
  138. <AccountCircleIcon style={{ color: 'black' }} alt="profile user" src={avatar1} sx={{ width: 32, height: 32 }} />
  139. <Stack>
  140. <Typography style={{ color: 'black', fontSize: "1.2rem" }} variant="subtitle1">{userData == null ? "" : (userData.fullenName?userData.fullenName: userData.fullchName)}</Typography>
  141. {/* <Typography variant="body2" color="textSecondary">
  142. {userData == null ? "" : userData.fullenName}
  143. </Typography> */}
  144. {/* <Typography variant="subtitle1">{userData == null ? "" : userData.fullenName}</Typography> */}
  145. </Stack>
  146. </Stack>
  147. </Grid>
  148. <Grid item>
  149. <IconButton size="large" color="secondary" onClick={handleLogout}>
  150. <LogoutOutlined />
  151. </IconButton>
  152. </Grid>
  153. </Grid>
  154. </CardContent>
  155. {/* {open && (
  156. <>
  157. <Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
  158. <Tabs variant="fullWidth" value={value} onChange={handleChange} aria-label="profile tabs">
  159. <Tab
  160. sx={{
  161. display: 'flex',
  162. flexDirection: 'row',
  163. justifyContent: 'center',
  164. alignItems: 'center',
  165. textTransform: 'capitalize'
  166. }}
  167. icon={<UserOutlined style={{ marginBottom: 0, marginRight: '10px' }} />}
  168. label="Profile"
  169. {...a11yProps(0)}
  170. />
  171. <Tab
  172. sx={{
  173. display: 'flex',
  174. flexDirection: 'row',
  175. justifyContent: 'center',
  176. alignItems: 'center',
  177. textTransform: 'capitalize'
  178. }}
  179. icon={<SettingOutlined style={{ marginBottom: 0, marginRight: '10px' }} />}
  180. label="Setting"
  181. {...a11yProps(1)}
  182. />
  183. </Tabs>
  184. </Box>
  185. <TabPanel value={value} index={0} dir={theme.direction}>
  186. <ProfileTab handleLogout={handleLogout} />
  187. </TabPanel>
  188. <TabPanel value={value} index={1} dir={theme.direction}>
  189. <SettingTab />
  190. </TabPanel>
  191. </>
  192. )} */}
  193. </MainCard>
  194. </ClickAwayListener>
  195. </Paper>
  196. )}
  197. </Transitions>
  198. )}
  199. </Popper>
  200. </Box>
  201. );
  202. };
  203. export default Profile;