Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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