Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

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