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

index.js 15 KiB

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