Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

466 rader
17 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, Grid,
  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, isCreditorLoggedIn } 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. import LocaleSelector from "./HeaderContent/LocaleSelector";
  49. import { FormattedMessage } from "react-intl";
  50. const drawerWidth = 240;
  51. // const navItems = ['Home', 'About', 'Contact'];
  52. // ==============================|| MAIN LAYOUT - HEADER ||============================== //
  53. function Header(props) {
  54. const { window } = props;
  55. const [mobileOpen, setMobileOpen] = useState(false);
  56. const dispatch = useDispatch()
  57. const navigate = useNavigate()
  58. const handleDrawerToggle = () => {
  59. setMobileOpen((prevState) => !prevState);
  60. };
  61. const handleLogout = async () => {
  62. dispatch(handleLogoutFunction());
  63. //await handleLogoutFunction();
  64. navigate('/login');
  65. };
  66. const loginContent = (
  67. isGLDLoggedIn() ?
  68. <div id="adminContent">
  69. <li>
  70. <Link className="dashboard" to='/dashboard'>
  71. <Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }} >
  72. Dashboard
  73. </Typography>
  74. </Link>
  75. </li>
  76. <li>
  77. <Link className="application" to='/application/search'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }}>Application</Typography></Link>
  78. </li>
  79. <li>
  80. <Link className="proof" to='/proof/search'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>Proof</Typography></Link>
  81. </li>
  82. <li>
  83. <Link className="client" ><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>Payment</Typography><KeyboardArrowDownIcon sx={{ fontSize: '1.0rem' }} /></Link>
  84. <ul className='dropdown'>
  85. <li>
  86. <Link className="payment" to='/paymentPage/search'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>Payment Record</Typography></Link>
  87. </li>
  88. <li>
  89. <Link className="downloadXML" to='/gfmis/search'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>GFMIS Generate XML</Typography></Link>
  90. </li>
  91. <li>
  92. <Link className="createDemandNote" to='/paymentPage/createDemandNote' ><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>Create Demand Note</Typography></Link>
  93. </li>
  94. <li>
  95. <Link className="demandNote" to='/paymentPage/demandNote' ><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>Demand Note</Typography></Link>
  96. </li>
  97. </ul>
  98. </li>
  99. <li>
  100. <Link className="client" ><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>Client</Typography><KeyboardArrowDownIcon sx={{ fontSize: '1.0rem' }} /></Link>
  101. <ul className='dropdown'>
  102. <li>
  103. <Link className="userSearchview" to='/userSearchview'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2, mt: 1, mb: 1 }}>Users (GLD)</Typography></Link>
  104. </li>
  105. <li>
  106. <Link className="indUser" to='/indUser'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2, mt: 1, mb: 1 }}>Users (Individual)</Typography></Link>
  107. </li>
  108. <li>
  109. <Link className="orgUser" to='/orgUser'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2, mt: 1, mb: 1 }}>Users (Organisation)</Typography></Link>
  110. </li>
  111. <li>
  112. <Link className="org" to='/org'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2, mt: 1, mb: 1 }}>Organisation</Typography></Link>
  113. </li>
  114. <li>
  115. <Link className="usergroupSearchview" to='/usergroupSearchview'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2, mt: 1, mb: 1 }}>User Group</Typography></Link>
  116. </li>
  117. </ul>
  118. </li>
  119. <li>
  120. <Link className="emailTemplate" to='/emailTemplate'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 0 }}>Email Template</Typography></Link>
  121. </li>
  122. {/* <li>
  123. <Link className="logout" onClick={handleLogout}><Typography variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>Logout</Typography></Link>
  124. </li> */}
  125. </div>
  126. :
  127. <div id="individualUserContent">
  128. <li>
  129. <Link className="dashboard" to='/dashboard'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }}>
  130. <FormattedMessage id="mainPage" />
  131. </Typography></Link>
  132. </li>
  133. <li>
  134. <Link className="myDocumet" to='/publicNotice'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }}>
  135. <FormattedMessage id="myPublicNotice" />
  136. </Typography></Link>
  137. </li>
  138. <li>
  139. <Link className="documentRecord" to='/proof/search'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }}>
  140. <FormattedMessage id="proofRecord" />
  141. </Typography></Link>
  142. </li>
  143. <li>
  144. {isCreditorLoggedIn() ?
  145. <>
  146. <Link className="paymentRecord">
  147. <Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }}>
  148. <FormattedMessage id="paymentHistory"/>
  149. </Typography>
  150. <KeyboardArrowDownIcon sx={{ fontSize: '1.0rem' }} />
  151. </Link>
  152. <ul className='dropdown'>
  153. <li>
  154. <Link className="manageOrgUser" to='/paymentPage/search'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }}>
  155. <FormattedMessage id="onlinePaymentHistory" />
  156. </Typography></Link>
  157. </li>
  158. <li>
  159. <Link className="manageOrgUser" to='/paymentPage/demandNote'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }}>繳款通知記錄</Typography></Link>
  160. </li>
  161. </ul>
  162. </>
  163. :
  164. <Link className="manageOrgUser" to='/paymentPage/search'><Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }}>
  165. <FormattedMessage id="onlinePaymentHistory" />
  166. </Typography></Link>
  167. }
  168. </li>
  169. <li>
  170. {isPrimaryLoggedIn() ?
  171. <>
  172. <Link className="userSetting" >
  173. <Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }} onClick={(event) => console.log(event)}>
  174. <FormattedMessage id="setting" />
  175. </Typography>
  176. <KeyboardArrowDownIcon sx={{ fontSize: '1.0rem' }} />
  177. </Link>
  178. <ul className='dropdown'>
  179. <li>
  180. <Link className="manageOrgUser" to='setting/manageUser'>
  181. <Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>
  182. <FormattedMessage id="companyOrUserRecord" />
  183. </Typography>
  184. </Link>
  185. </li>
  186. </ul>
  187. </>
  188. :
  189. <>
  190. <Link className="userSetting" >
  191. <Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 1 }} onClick={(event) => console.log(event)}>
  192. <FormattedMessage id="setting" />
  193. </Typography>
  194. </Link>
  195. </>
  196. }
  197. </li>
  198. {/* <li>
  199. <Link className="logout" onClick={handleLogout}><Typography variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>登出</Typography></Link>
  200. </li> */}
  201. </div>
  202. );
  203. const logoutContent = (
  204. <div>
  205. <li>
  206. <Link className="login" to='/login'>
  207. <Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>
  208. <FormattedMessage id="login" />
  209. </Typography>
  210. </Link>
  211. </li>
  212. <li>
  213. <Link className="register" to='/register'>
  214. <Typography style={{ opacity: 0.9 }} variant={"pnspsHeaderTitle"} sx={{ ml: 2 }}>
  215. <FormattedMessage id="register" />
  216. </Typography>
  217. </Link>
  218. </li>
  219. </div>
  220. );
  221. const drawer = (
  222. isUserLoggedIn() ?
  223. <Stack id="sidebar" direction="column" justifyContent="center" alignItems="center" /*onClick={handleDrawerToggle}*/ sx={{ textAlign: 'center' }}>
  224. <Typography variant="h6" sx={{ my: 2 }}>
  225. PNSPS
  226. </Typography>
  227. <Divider />
  228. <ul id="sidebartop">
  229. {loginContent}
  230. </ul>
  231. <Divider />
  232. <ul id="sidebarbottom">
  233. <li>
  234. <Link className="logout" onClick={handleLogout}>登出</Link>
  235. </li>
  236. </ul>
  237. </Stack>
  238. :
  239. <Stack id="sidebar" direction="column" justifyContent="center" alignItems="center" onClick={handleDrawerToggle} sx={{ textAlign: 'center' }}>
  240. <Typography variant="h6" sx={{ my: 2 }}>
  241. PNSPS
  242. </Typography>
  243. <Divider />
  244. <ul id="sidebartop">
  245. {logoutContent}
  246. </ul>
  247. <Divider />
  248. </Stack>
  249. );
  250. const container = window !== undefined ? () => window().document.body : undefined;
  251. return (
  252. isUserLoggedIn() ?
  253. // User Login success
  254. <Box>
  255. <AppBar component="nav">
  256. <Toolbar id="nav" width="100%">
  257. {isGLDLoggedIn()
  258. ? <Stack
  259. direction="row"
  260. justifyContent="flex-start"
  261. alignItems="center"
  262. spacing={0}
  263. >
  264. <Box sx={{ display: { xs: 'none', sm: 'none', md: 'block' } }}>
  265. <AdminLogo />
  266. </Box>
  267. <IconButton
  268. color="inherit"
  269. aria-label="open drawer"
  270. edge="start"
  271. onClick={handleDrawerToggle}
  272. sx={{ mr: 2, display: { md: 'none' } }}
  273. >
  274. <MenuIcon style={{ color: '#0C489E' }} />
  275. </IconButton>
  276. <Box sx={{ mr: 2, display: { md: 'none' } }}>
  277. <MobileLogo />
  278. <span id="mobileTitle" >PNSPS</span>
  279. </Box>
  280. </Stack> :
  281. <Stack
  282. direction="row"
  283. justifyContent="flex-start"
  284. alignItems="center"
  285. spacing={0}
  286. >
  287. <Box sx={{ width: '260px', flexGrow: 1, display: { xs: 'none', sm: 'none', md: 'block' } }}>
  288. <Stack direction="row" justifyContent="flex-start" alignItems="center">
  289. <Logo />
  290. <Stack justifyContent="flex-start" alignItems="center">
  291. {/*<span id="systemTitle">公共啟事提交</span>*/}
  292. {/*<span id="systemTitle">及繳費系統</span>*/}
  293. <span id="systemTitle">
  294. <FormattedMessage id="PNSPS" />
  295. </span>
  296. </Stack>
  297. </Stack>
  298. </Box>
  299. <IconButton
  300. color="inherit"
  301. aria-label="open drawer"
  302. edge="start"
  303. onClick={handleDrawerToggle}
  304. sx={{ mr: 2, display: { md: 'none' } }}
  305. >
  306. <MenuIcon style={{ color: '#0C489E' }} />
  307. </IconButton>
  308. <Box sx={{ mr: 2, display: { md: 'none' } }}>
  309. <Stack direction="row" justifyContent="flex-start" alignItems="center">
  310. <MobileLogo />
  311. <span id="mobileTitle" >
  312. <FormattedMessage id="PNSPS" />
  313. </span>
  314. </Stack>
  315. </Box>
  316. </Stack>
  317. }
  318. <Box sx={{ display: { xs: 'none', sm: 'none', md: 'block' }, width: "100%" }}>
  319. <Stack
  320. direction="row"
  321. justifyContent="space-between"
  322. alignItems="center"
  323. spacing={1}
  324. >
  325. <ul id="navbar" width="100%" >
  326. {loginContent}
  327. </ul>
  328. <Grid item>
  329. <Grid container direction="row" >
  330. {
  331. isGLDLoggedIn() ?
  332. <Grid item />
  333. :
  334. <LocaleSelector />
  335. }
  336. <Profile />
  337. </Grid>
  338. </Grid>
  339. </Stack>
  340. </Box>
  341. </Toolbar>
  342. </AppBar>
  343. <Box component="nav">
  344. <Drawer
  345. container={container}
  346. variant="temporary"
  347. open={mobileOpen}
  348. onClose={handleDrawerToggle}
  349. ModalProps={{
  350. keepMounted: true, // Better open performance on mobile.
  351. }}
  352. sx={{
  353. display: { sm: 'block', md: 'none' },
  354. '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
  355. }}
  356. >
  357. {drawer}
  358. </Drawer>
  359. </Box>
  360. </Box> :
  361. <Box>
  362. <AppBar component="nav">
  363. <Toolbar id="nav" width="100%">
  364. <Stack
  365. direction="row"
  366. justifyContent="flex-start"
  367. alignItems="center"
  368. spacing={0}
  369. >
  370. <Box sx={{ flexGrow: 1, display: { xs: 'none', sm: 'none', md: 'block' } }}>
  371. <Stack direction="row" justifyContent="flex-start" alignItems="center">
  372. <Logo />
  373. <Stack justifyContent="flex-start" alignItems="center">
  374. <span id="systemTitle">
  375. <FormattedMessage id="PNSPS" />
  376. </span>
  377. </Stack>
  378. </Stack>
  379. </Box>
  380. <IconButton
  381. color="inherit"
  382. aria-label="open drawer"
  383. edge="start"
  384. onClick={handleDrawerToggle}
  385. sx={{ mr: 2, display: { md: 'none' } }}
  386. >
  387. <MenuIcon style={{ color: '#0C489E' }} />
  388. </IconButton>
  389. <Box sx={{ flexGrow: 1, mr: 2, display: { sm: 'block', md: 'none' } }}>
  390. <Stack direction="row" justifyContent="space-between" alignItems="center">
  391. <MobileLogo />
  392. <Stack justifyContent="flex-start" alignItems="center">
  393. <span id="mobileTitle">
  394. <FormattedMessage id="PNSPS" />
  395. </span>
  396. </Stack>
  397. <Stack justifyContent="flex-end" alignItems="center">
  398. <LocaleSelector />
  399. </Stack>
  400. </Stack>
  401. </Box>
  402. </Stack>
  403. <Box sx={{ display: { xs: 'none', sm: 'none', md: 'block' }, width: "75%" }}>
  404. <Stack
  405. direction="row"
  406. justifyContent="space-between"
  407. alignItems="center"
  408. spacing={1}
  409. >
  410. <ul id="navbar" width="100%" >
  411. {logoutContent}
  412. </ul>
  413. <LocaleSelector />
  414. {/* <Profile /> */}
  415. </Stack>
  416. </Box>
  417. </Toolbar>
  418. </AppBar>
  419. <Box component="nav">
  420. <Drawer
  421. container={container}
  422. variant="temporary"
  423. open={mobileOpen}
  424. onClose={handleDrawerToggle}
  425. ModalProps={{
  426. keepMounted: true, // Better open performance on mobile.
  427. }}
  428. sx={{
  429. display: { sm: 'block', md: 'none' },
  430. '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
  431. }}
  432. >
  433. {drawer}
  434. </Drawer>
  435. </Box>
  436. </Box>
  437. );
  438. }
  439. Header.propTypes = {
  440. /**
  441. * Injected by the documentation to work in an iframe.
  442. * You won't need it on your project.
  443. */
  444. window: PropTypes.func,
  445. };
  446. export default Header;