You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

256 lines
9.8 KiB

  1. import { useState } from 'react';
  2. // material-ui
  3. import {
  4. Grid,
  5. Typography,
  6. Stack,
  7. Button,
  8. Box,
  9. Dialog, DialogTitle, DialogContent, DialogActions,
  10. } from '@mui/material';
  11. import { isORGLoggedIn, } from "utils/Utils";
  12. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  13. import { FormattedMessage, useIntl } from "react-intl";
  14. import AdsClickRoundedIcon from '@mui/icons-material/AdsClickRounded';
  15. import * as React from "react";
  16. import Loadable from 'components/Loadable';
  17. import * as HttpUtils from "utils/HttpUtils";
  18. import * as UrlUtils from "utils/ApiPathConst";
  19. import * as DateUtils from "utils/DateUtils";
  20. import { checkPaymentSuspension } from "utils/Utils";
  21. const Message = Loadable(React.lazy(() => import('./Message')));
  22. const Notice = Loadable(React.lazy(() => import('./Notice')));
  23. // import { lazy } from 'react';
  24. const LoadingComponent = Loadable(React.lazy(() => import('../../extra-pages/LoadingComponent')));
  25. import { useNavigate } from "react-router-dom";
  26. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  27. const DashboardDefault = () => {
  28. const navigate = useNavigate()
  29. const intl = useIntl();
  30. const userData = JSON.parse(localStorage.getItem("userData"));
  31. const BackgroundHead = {
  32. // backgroundColor: '#0d47a1',
  33. backgroundImage: `url(${titleBackgroundImg})`,
  34. width: '100%',
  35. height: '100%',
  36. backgroundSize: 'contain',
  37. backgroundRepeat: 'no-repeat',
  38. backgroundColor: '#0C489E',
  39. backgroundPosition: 'right'
  40. }
  41. const { locale } = intl;
  42. const [messageOnReady, setMessageOnReady] = useState(false);
  43. const [onNoticeReady, setNoticeOnReady] = useState(false);
  44. const [isLoading, setLoding] = useState(true);
  45. const [itemList, setItemList] = React.useState([]);
  46. const [listData, setListData] = React.useState([]);
  47. const [isPopUp, setIsPopUp] = React.useState(false);
  48. React.useEffect(() => {
  49. loadMessageData()
  50. loadNoticeData()
  51. localStorage.setItem('searchCriteria',"")
  52. }, []);
  53. const getWelcomeMsg=()=>{
  54. var current = new Date()
  55. var curHr = current.getHours()
  56. if (curHr < 12) {
  57. return <FormattedMessage id="welcomeMsg_am" />
  58. } else if (curHr < 18) {
  59. return <FormattedMessage id="welcomeMsg_pm" />
  60. } else {
  61. return <FormattedMessage id="welcomeMsg_night" />
  62. }
  63. }
  64. React.useEffect(() => {
  65. // console.log(messageOnReady)
  66. // console.log(onNoticeReady)
  67. if(messageOnReady&&onNoticeReady){
  68. setLoding(false)
  69. if(checkPaymentSuspension()){
  70. setIsPopUp(true);
  71. }
  72. // console.log(123)
  73. }
  74. }, [messageOnReady,onNoticeReady]);
  75. const loadMessageData = () => {
  76. HttpUtils.get({
  77. url: UrlUtils.GET_MSG_DASHBOARD,
  78. onSuccess: function (response) {
  79. let list = []
  80. response.map((item) => {
  81. list.push(
  82. <Button onClick={()=>{navigate("/msg/details/"+item.id);}} color={item.readTime?"gray":"black"} style={{justifyContent: "flex-start"}} sx={{p:2}}>
  83. <Stack direction="column" >
  84. <Typography variant='string' align="justify"><b>{item.subject}</b></Typography>
  85. <Typography align="justify">{DateUtils.datetimeStr(item.sentDate)}</Typography>
  86. </Stack>
  87. </Button>
  88. )
  89. });
  90. setItemList(list);
  91. setMessageOnReady(true);
  92. // console.log('123')
  93. },
  94. onError: function (){
  95. // console.log('123')
  96. setMessageOnReady(true);
  97. }
  98. });
  99. // props.setMessageOnReady(true);
  100. };
  101. const loadNoticeData = () => {
  102. HttpUtils.get({
  103. url: UrlUtils.GET_ANNOUNCE_DASHBOARD,
  104. onSuccess: function (response) {
  105. setListData(response);
  106. setNoticeOnReady(true)
  107. },
  108. onError: function () {
  109. setNoticeOnReady(true)
  110. }
  111. });
  112. };
  113. return (
  114. isLoading ?
  115. <Grid container sx={{ minHeight: '87vh' }} direction="column">
  116. <Grid item xs={12} >
  117. <div style={BackgroundHead}>
  118. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  119. {/* <Typography variant="h5">我的公共啟事</Typography> */}
  120. <Typography color='#FFF' variant="h5" sx={{ ml: 10, display: { xs: 'none', sm: 'none', md: 'block' } }}>
  121. {isORGLoggedIn() ? userData.fullenName: (locale === 'en' ?userData.fullenName: userData.fullchName)}, {getWelcomeMsg()}
  122. </Typography>
  123. </Stack>
  124. </div>
  125. </Grid>
  126. <Grid item xs={12} md={12} sx={{ textAlign: "center" }}>
  127. <Grid container sx={{ minHeight: '75vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  128. <Grid item>
  129. <LoadingComponent />
  130. </Grid>
  131. </Grid>
  132. </Grid>
  133. </Grid>
  134. :
  135. <Grid container sx={{ minHeight: '87vh' }} direction="column">
  136. <Grid item xs={12} >
  137. <div style={BackgroundHead}>
  138. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  139. {/* <Typography variant="h5">我的公共啟事</Typography> */}
  140. <Typography color='#FFF' variant="h5" sx={{ ml: 10, display: { xs: 'none', sm: 'none', md: 'block' } }}>
  141. {isORGLoggedIn() ? userData.fullenName: (locale === 'en' ?userData.fullenName: userData.fullchName)}, {getWelcomeMsg()}
  142. </Typography>
  143. </Stack>
  144. </div>
  145. </Grid>
  146. <Grid item xs={12} md={12} sx={{ textAlign: "center" }}>
  147. <Grid container justifyContent="center" spacing={2} sx={{ pt: 2 }} alignitems="stretch" >
  148. <Grid item xs={12} lg={5} sx={{ pt: 2 }} style={{ height: '100%' }}>
  149. <Button
  150. xs={12} onClick={() => { navigate("/publicNotice/apply"); }}
  151. style={{ justifyContent: "flex-start" }}
  152. aria-label={intl.formatMessage({ id: 'submitApplication' })}
  153. sx={{ width: "100%", p: 4, border: '3px solid #e1edfc', borderRadius: '10px', backgroundColor: "#e1edfc" }}
  154. >
  155. <Stack direction="row" spacing={2}>
  156. <AdsClickRoundedIcon />
  157. <Stack direction="column" alignItems="start">
  158. <Typography variant="h4" >
  159. <FormattedMessage id="submitApplication" />
  160. </Typography>
  161. <Typography >
  162. <FormattedMessage id="applicationSubheading" />
  163. </Typography>
  164. </Stack>
  165. </Stack>
  166. </Button>
  167. <Stack direction="row" justifyContent="space-between" sx={{ pl: 2, pr: 2, pt: 2 }} >
  168. <Typography variant="h4">
  169. <FormattedMessage id="announcement" />
  170. </Typography>
  171. <Button
  172. color="gray"
  173. aria-label={intl.formatMessage({ id: 'viewAllAnnouncement' })}
  174. onClick={()=>{navigate("/announcement/search")}}
  175. ><u>
  176. <FormattedMessage id="viewAllAnnouncement" />
  177. </u></Button>
  178. </Stack>
  179. <Box xs={12} md={12} sx={{ p: 1, border: '3px solid #eee', borderRadius: '10px' }} >
  180. <Notice
  181. listData = {listData}
  182. />
  183. </Box>
  184. </Grid>
  185. <Grid item xs={12} lg={5} sx={{ pt: 2 }} style={{ height: '100%' }}>
  186. <Stack direction="row" justifyContent="space-between" sx={{ pl: 2, pr: 2, pt: 2 }} >
  187. <Typography variant="h4">
  188. <FormattedMessage id="systemMessage" />
  189. </Typography>
  190. <Button
  191. aria-label={intl.formatMessage({ id: 'viewAllSystemMessage' })}
  192. onClick={() => { navigate("/msg/search"); }}
  193. color="gray"
  194. ><u>
  195. <FormattedMessage id="viewAllSystemMessage" />
  196. </u></Button>
  197. </Stack>
  198. <Box xs={12} md={12} sx={{ p: 1, fontSize: 12, border: '3px solid #eee', borderRadius: '10px' }} >
  199. <Message
  200. itemList = {itemList}
  201. />
  202. </Box>
  203. </Grid>
  204. </Grid>
  205. </Grid>
  206. <div>
  207. <Dialog
  208. open={isPopUp}
  209. onClose={() => setIsPopUp(false)}
  210. PaperProps={{
  211. sx: {
  212. minWidth: '40vw',
  213. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  214. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  215. }
  216. }}
  217. >
  218. <DialogTitle>
  219. <Typography variant="h5">
  220. <FormattedMessage id="systemNotice" />
  221. </Typography>
  222. </DialogTitle>
  223. <DialogContent style={{ display: 'flex', }}>
  224. <Typography variant="h5" style={{ padding: '16px' }}>
  225. <div dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: "suspensionMessageText" }) }} />
  226. </Typography>
  227. </DialogContent>
  228. <DialogActions>
  229. <Button onClick={() => setIsPopUp(false)}><Typography variant="h5"><FormattedMessage id="ok" /></Typography></Button>
  230. </DialogActions>
  231. </Dialog>
  232. </div>
  233. </Grid>
  234. );
  235. };
  236. export default DashboardDefault;