選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

361 行
12 KiB

  1. import PropTypes from 'prop-types';
  2. import React
  3. , { useState }
  4. from 'react';
  5. import { useDispatch } from "react-redux";
  6. import { useNavigate } from "react-router-dom";
  7. // material-ui
  8. // import { useTheme } from '@mui/material/styles';
  9. import {
  10. AppBar,
  11. // Container,
  12. Typography,
  13. Box,
  14. Stack,
  15. // IconButton,
  16. // Menu,
  17. // MenuItem,
  18. // Button,
  19. // Tooltip,
  20. // Avatar,
  21. // Stack,
  22. Toolbar,
  23. Divider,
  24. // List,
  25. // ListItem,
  26. // ListItemButton,
  27. // ListItemText,
  28. IconButton,
  29. Drawer,
  30. // useMediaQuery
  31. } from '@mui/material';
  32. import MenuIcon from '@mui/icons-material/Menu';
  33. import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
  34. // project import
  35. // import AppBarStyled from './AppBarStyled';
  36. // import HeaderContent from './HeaderContent';
  37. import Logo from 'components/Logo';
  38. import AdminLogo from 'components/AdminLogo';
  39. import MobileLogo from 'components/MobileLogo';
  40. import Profile from './HeaderContent/Profile';
  41. import "assets/style/navbarStyles.css";
  42. import { isUserLoggedIn, isGLDLoggedIn, isPrimaryLoggedIn } from "utils/Utils";
  43. import { handleLogoutFunction } from 'auth/index';
  44. // assets
  45. // import { MenuFoldOutlined,MenuOutlined } from '@ant-design/icons';
  46. // import { AppBar } from '../../../../node_modules/@mui/material/index';
  47. import { Link } from "react-router-dom";
  48. const drawerWidth = 240;
  49. // const navItems = ['Home', 'About', 'Contact'];
  50. // ==============================|| MAIN LAYOUT - HEADER ||============================== //
  51. function Header(props) {
  52. const { window } = props;
  53. const [mobileOpen, setMobileOpen] = useState(false);
  54. const dispatch = useDispatch()
  55. const navigate = useNavigate()
  56. const handleDrawerToggle = () => {
  57. setMobileOpen((prevState) => !prevState);
  58. };
  59. const handleLogout = async () => {
  60. dispatch(handleLogoutFunction());
  61. //await handleLogoutFunction();
  62. navigate('/login');
  63. };
  64. const loginContent = (
  65. isGLDLoggedIn() ?
  66. <div id="adminContent">
  67. <li>
  68. <Link className="dashboard" to='/dashboard'><Typography variant={"headerTitle1"} sx={{ ml: 1 }} >Dashboard</Typography></Link>
  69. </li>
  70. <li>
  71. <Link className="application" to='/application/search'><Typography variant={"headerTitle1"} sx={{ ml: 1 }}>Application</Typography></Link>
  72. </li>
  73. <li>
  74. <Link className="proof" to='/proof/search'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>Proof</Typography></Link>
  75. </li>
  76. <li>
  77. <Link className="payment" to='/dashboard'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>Payment</Typography></Link>
  78. </li>
  79. <li>
  80. <Link className="client" ><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>Client</Typography><KeyboardArrowDownIcon /></Link>
  81. <ul className='dropdown'>
  82. <li>
  83. <Link className="userSearchview" to='/userSearchview'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>Users (GLD)</Typography></Link>
  84. </li>
  85. <li>
  86. <Link className="indUser" to='/indUser'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>Users (Individual)</Typography></Link>
  87. </li>
  88. <li>
  89. <Link className="orgUser" to='/orgUser'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>Users (Organisation)</Typography></Link>
  90. </li>
  91. <li>
  92. <Link className="org" to='/org'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>Organisation</Typography></Link>
  93. </li>
  94. <li>
  95. <Link className="usergroupSearchview" to='/usergroupSearchview'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>User Group</Typography></Link>
  96. </li>
  97. </ul>
  98. </li>
  99. <li>
  100. <Link className="emailTemplate" to='/emailTemplate'><Typography variant={"headerTitle1"} sx={{ ml: 0 }}>Email Template</Typography></Link>
  101. </li>
  102. {/* <li>
  103. <Link className="logout" onClick={handleLogout}><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>Logout</Typography></Link>
  104. </li> */}
  105. </div>
  106. :
  107. <div id="individualUserContent">
  108. <li>
  109. <Link className="dashboard" to='/dashboard'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>主頁</Typography></Link>
  110. </li>
  111. <li>
  112. <Link className="myDocumet" to='/publicNotice'><Typography variant={"headerTitle1"} sx={{ ml: 0.5 }}>我的公共啟事</Typography></Link>
  113. </li>
  114. <li>
  115. <Link className="documentRecord" to='/proof/search'><Typography variant={"headerTitle1"} sx={{ ml: 1.5 }}>校對記錄</Typography></Link>
  116. </li>
  117. <li>
  118. <Link className="paymentRecord" to='/paymentPage/search'><Typography variant={"headerTitle1"} sx={{ ml: 1.5 }}>付款記錄</Typography></Link>
  119. </li>
  120. <li>
  121. <Link className="userSetting" to='/dashboard'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>設定</Typography><KeyboardArrowDownIcon /></Link>
  122. {isPrimaryLoggedIn() ?
  123. <ul className='dropdown'>
  124. <li>
  125. <Link className="manageOrgUser" to='setting/manageUser'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>公司/機構用戶記錄</Typography></Link>
  126. </li>
  127. </ul>
  128. :
  129. <></>
  130. }
  131. </li>
  132. {/* <li>
  133. <Link className="logout" onClick={handleLogout}><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>登出</Typography></Link>
  134. </li> */}
  135. </div>
  136. );
  137. const logoutContent = (
  138. <div>
  139. <li>
  140. <Link className="login" to='/login'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>登入</Typography></Link>
  141. </li>
  142. <li>
  143. <Link className="register" to='/register'><Typography variant={"headerTitle1"} sx={{ ml: 2 }}>申請</Typography></Link>
  144. </li>
  145. </div>
  146. );
  147. const drawer = (
  148. isUserLoggedIn() ?
  149. <Stack id="sidebar" direction="column" justifyContent="center" alignItems="center" onClick={handleDrawerToggle} sx={{ textAlign: 'center' }}>
  150. <Typography variant="h6" sx={{ my: 2 }}>
  151. PNSPS
  152. </Typography>
  153. <Divider />
  154. <ul id="sidebartop">
  155. {loginContent}
  156. </ul>
  157. <Divider />
  158. <ul id="sidebarbottom">
  159. <li>
  160. <Link className="logout" onClick={handleLogout}>登出</Link>
  161. </li>
  162. </ul>
  163. </Stack>
  164. :
  165. <Stack id="sidebar" direction="column" justifyContent="center" alignItems="center" onClick={handleDrawerToggle} sx={{ textAlign: 'center' }}>
  166. <Typography variant="h6" sx={{ my: 2 }}>
  167. PNSPS
  168. </Typography>
  169. <Divider />
  170. <ul id="sidebartop">
  171. {logoutContent}
  172. </ul>
  173. <Divider />
  174. </Stack>
  175. );
  176. const container = window !== undefined ? () => window().document.body : undefined;
  177. return (
  178. isUserLoggedIn() ?
  179. // User Login success
  180. <Box>
  181. <AppBar component="nav">
  182. <Toolbar id="nav" width="100%">
  183. {isGLDLoggedIn()
  184. ? <Stack
  185. direction="row"
  186. justifyContent="flex-start"
  187. alignItems="center"
  188. spacing={0}
  189. >
  190. <Box sx={{ display: { xs: 'none', sm: 'block' } }}>
  191. <AdminLogo />
  192. </Box>
  193. <IconButton
  194. color="inherit"
  195. aria-label="open drawer"
  196. edge="start"
  197. onClick={handleDrawerToggle}
  198. sx={{ mr: 2, display: { sm: 'none' } }}
  199. >
  200. <MenuIcon style={{ color: '#0C489E' }} />
  201. </IconButton>
  202. <Box sx={{ mr: 2, display: { sm: 'none' } }}>
  203. <MobileLogo />
  204. <span id="mobileTitle" >PNSPS</span>
  205. </Box>
  206. </Stack> :
  207. <Stack
  208. direction="row"
  209. justifyContent="flex-start"
  210. alignItems="center"
  211. spacing={0}
  212. >
  213. <Box sx={{ width: '260px', flexGrow: 1, display: { xs: 'none', sm: 'block' } }}>
  214. <Stack direction="row" justifyContent="flex-start" alignItems="center">
  215. <Logo />
  216. <Stack justifyContent="flex-start" alignItems="center">
  217. <span id="systemTitle">公共啟事提交</span>
  218. <span id="systemTitle">及繳費系統</span>
  219. </Stack>
  220. </Stack>
  221. </Box>
  222. <IconButton
  223. color="inherit"
  224. aria-label="open drawer"
  225. edge="start"
  226. onClick={handleDrawerToggle}
  227. sx={{ mr: 2, display: { sm: 'none' } }}
  228. >
  229. <MenuIcon style={{ color: '#0C489E' }} />
  230. </IconButton>
  231. <Box sx={{ mr: 2, display: { sm: 'none' } }}>
  232. <Stack direction="row" justifyContent="flex-start" alignItems="center">
  233. <MobileLogo />
  234. <span id="mobileTitle" >公共啟事提交及繳費系統</span>
  235. </Stack>
  236. </Box>
  237. </Stack>
  238. }
  239. <Box sx={{ display: { xs: 'none', sm: 'block' }, width: "100%" }}>
  240. <Stack
  241. direction="row"
  242. justifyContent="space-between"
  243. alignItems="center"
  244. spacing={1}
  245. >
  246. <ul id="navbar" width="100%" >
  247. {loginContent}
  248. </ul>
  249. <Profile />
  250. </Stack>
  251. </Box>
  252. </Toolbar>
  253. </AppBar>
  254. <Box component="nav">
  255. <Drawer
  256. container={container}
  257. variant="temporary"
  258. open={mobileOpen}
  259. onClose={handleDrawerToggle}
  260. ModalProps={{
  261. keepMounted: true, // Better open performance on mobile.
  262. }}
  263. sx={{
  264. display: { xs: 'block', sm: 'none' },
  265. '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
  266. }}
  267. >
  268. {drawer}
  269. </Drawer>
  270. </Box>
  271. </Box> :
  272. <Box>
  273. <AppBar component="nav">
  274. <Toolbar id="nav" width="100%">
  275. <Stack
  276. direction="row"
  277. justifyContent="flex-start"
  278. alignItems="center"
  279. spacing={0}
  280. >
  281. <Box sx={{ flexGrow: 1, display: { xs: 'none', sm: 'block' } }}>
  282. <Stack direction="row" justifyContent="flex-start" alignItems="center">
  283. <Logo />
  284. <Stack justifyContent="flex-start" alignItems="center">
  285. <span id="systemTitle">公共啟事提交及繳費系統</span>
  286. </Stack>
  287. </Stack>
  288. </Box>
  289. <IconButton
  290. color="inherit"
  291. aria-label="open drawer"
  292. edge="start"
  293. onClick={handleDrawerToggle}
  294. sx={{ mr: 2, display: { sm: 'none' } }}
  295. >
  296. <MenuIcon style={{ color: '#0C489E' }} />
  297. </IconButton>
  298. <Box sx={{ mr: 2, display: { sm: 'none' } }}>
  299. <MobileLogo />
  300. <span id="mobileTitle" >公共啟事提交及繳費系統</span>
  301. </Box>
  302. </Stack>
  303. <Box sx={{ display: { xs: 'none', sm: 'block' }, width: "75%" }}>
  304. <Stack
  305. direction="row"
  306. justifyContent="space-between"
  307. alignItems="center"
  308. spacing={1}
  309. >
  310. <ul id="navbar" width="100%" >
  311. {logoutContent}
  312. </ul>
  313. {/* <Profile /> */}
  314. </Stack>
  315. </Box>
  316. </Toolbar>
  317. </AppBar>
  318. <Box component="nav">
  319. <Drawer
  320. container={container}
  321. variant="temporary"
  322. open={mobileOpen}
  323. onClose={handleDrawerToggle}
  324. ModalProps={{
  325. keepMounted: true, // Better open performance on mobile.
  326. }}
  327. sx={{
  328. display: { xs: 'block', sm: 'none' },
  329. '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
  330. }}
  331. >
  332. {drawer}
  333. </Drawer>
  334. </Box>
  335. </Box>
  336. );
  337. }
  338. Header.propTypes = {
  339. /**
  340. * Injected by the documentation to work in an iframe.
  341. * You won't need it on your project.
  342. */
  343. window: PropTypes.func,
  344. };
  345. export default Header;