Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

276 wiersze
11 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Button,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. } from '@mui/material';
  9. import * as UrlUtils from "utils/ApiPathConst";
  10. import * as React from "react";
  11. import * as HttpUtils from "utils/HttpUtils";
  12. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  13. import Loadable from 'components/Loadable';
  14. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  15. import MainCard from 'components/MainCard';
  16. const ExportForm = Loadable(React.lazy(() => import('./ExportForm')));
  17. const SearchForm = Loadable(React.lazy(() => import('./SearchForm')));
  18. const GazetteIssueTable = Loadable(React.lazy(() => import('./DataGrid')))
  19. const BackgroundHead = {
  20. backgroundImage: `url(${titleBackgroundImg})`,
  21. width: '100%',
  22. height: '100%',
  23. backgroundSize: 'contain',
  24. backgroundRepeat: 'no-repeat',
  25. backgroundColor: '#0C489E',
  26. backgroundPosition: 'right'
  27. }
  28. import {PNSPS_LONG_BUTTON_THEME} from "themes/buttonConst";
  29. import {ThemeProvider} from "@emotion/react";
  30. import { dateStr_Year } from "utils/DateUtils";
  31. import { notifySaveSuccess } from 'utils/CommonFunction';
  32. import { isGrantedAny } from "auth/utils";
  33. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  34. const Index = () => {
  35. const [comboData, setComboData] = React.useState([]);
  36. const [holidayComboData, setHolidayComboData] = React.useState([]);
  37. const [onReady, setOnReady] = React.useState(false);
  38. const [onGridReady, setGridOnReady] = React.useState(false);
  39. const [onSearchReady, setOnSearchReady] = React.useState(false);
  40. const [onExportReady, setOnExportReady] = React.useState(false);
  41. const [searchCriteria, setSearchCriteria] = React.useState({
  42. year: dateStr_Year(new Date()),
  43. // dateFrom: DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)),
  44. });
  45. const [exportCriteria, setExportCriteria] = React.useState({
  46. // year: dateStr_Year(new Date()),
  47. // dateFrom: DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)),
  48. });
  49. const [attachments, setAttachments] = React.useState([]);
  50. const [waitImport, setWaitImport] = React.useState(false);
  51. const [waitDownload, setWaitDownload] = React.useState(false);
  52. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  53. const [warningText, setWarningText] = React.useState("");
  54. React.useEffect(() => {
  55. // console.log(searchCriteria)
  56. setOnSearchReady(false)
  57. loadCombo();
  58. }, [searchCriteria]);
  59. function loadCombo() {
  60. HttpUtils.get({
  61. url: UrlUtils.GET_ISSUE_YEAR_COMBO,
  62. onSuccess: (responseData) => {
  63. let combo = responseData;
  64. setComboData(combo);
  65. setOnSearchReady(true)
  66. loadHolidayCombo(true)
  67. // setOnReady(true);
  68. }
  69. });
  70. }
  71. function loadHolidayCombo() {
  72. HttpUtils.get({
  73. url: UrlUtils.GET_HOLIDAY_COMBO,
  74. onSuccess: (responseData) => {
  75. let combo = responseData
  76. setHolidayComboData(combo)
  77. setOnExportReady(true)
  78. setOnReady(true)
  79. }
  80. });
  81. }
  82. function applySearch(input) {
  83. setGridOnReady(true)
  84. setSearchCriteria(input);
  85. }
  86. function applyExport(input) {
  87. setExportCriteria(input);
  88. }
  89. function applyGridOnReady(input) {
  90. setGridOnReady(input);
  91. }
  92. React.useEffect(() => {
  93. if (Object.keys(exportCriteria).length > 0) {
  94. // console.log(exportCriteria)
  95. doExport();
  96. }
  97. }, [exportCriteria]);
  98. React.useEffect(() => {
  99. if (attachments.length > 0) {
  100. importHoliday();
  101. }
  102. }, [attachments]);
  103. const readFile = (event) => {
  104. let file = event.target.files[0];
  105. if (file) {
  106. if (!file.name.toLowerCase().substr(file.name.length - 5).includes(".xlsx")) {
  107. setWarningText("Please upload a valid file (File format: .xlsx).");
  108. setIsWarningPopUp(true);
  109. document.getElementById("uploadFileBtn").value = "";
  110. return;
  111. }
  112. file['id'] = attachments.length;
  113. setAttachments([
  114. ...attachments,
  115. file
  116. ]);
  117. document.getElementById("uploadFileBtn").value = "";
  118. }
  119. }
  120. const doExport=()=>{
  121. setWaitDownload(true)
  122. HttpUtils.fileDownload({
  123. url: UrlUtils.GET_ISSUE_LIST,
  124. params: exportCriteria,
  125. onResponse: () => {
  126. setTimeout(()=> setWaitDownload(false), 500)
  127. }
  128. });
  129. }
  130. const importHoliday = () => {
  131. setWaitImport(true);
  132. if (!attachments || attachments.length <= 0) {
  133. setWarningText("Please upload file.");
  134. setSaving(false);
  135. return;
  136. }
  137. HttpUtils.postWithFiles({
  138. url: UrlUtils.POST_ISSUE_FILE,
  139. files: attachments,
  140. onSuccess: () => {
  141. notifySaveSuccess()
  142. setWaitImport(false);
  143. setAttachments([]);
  144. loadCombo();
  145. loadForm();
  146. }
  147. });
  148. }
  149. return (
  150. !onReady ?
  151. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  152. <Grid item>
  153. <LoadingComponent />
  154. </Grid>
  155. </Grid>
  156. :
  157. (
  158. <Grid container sx={{minHeight: '87vh', backgroundColor: 'backgroundColor.default'}} direction="column" justifyContent="flex-start" alignItems="center" >
  159. <Grid item xs={12} width="100%">
  160. <div style={BackgroundHead} width="100%">
  161. <Stack direction="row" height='70px'>
  162. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>Gazette Issue</Typography>
  163. </Stack>
  164. </div>
  165. </Grid>
  166. {!onExportReady?
  167. <LoadingComponent />:
  168. <Grid item xs={12} md={12} lg={12} width="100%">
  169. <ExportForm
  170. applyExport={applyExport}
  171. comboData={holidayComboData}
  172. waitDownload={waitDownload}
  173. />
  174. </Grid>
  175. }
  176. {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) ?
  177. <Grid item xs={12} md={12} lg={6} width="100%">
  178. <Stack direction="row" justifyContent="flex-start" alignItems="center" spacing={2} sx={{ml:2,mt:1}} >
  179. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  180. <input
  181. id="uploadFileBtn"
  182. name="file"
  183. type="file"
  184. accept=".xlsx"
  185. style={{ display: 'none' }}
  186. disabled={waitImport}
  187. onChange={(event) => {
  188. readFile(event)
  189. }}
  190. />
  191. <label htmlFor="uploadFileBtn">
  192. <Button
  193. component="span"
  194. variant="contained"
  195. size="large"
  196. disabled={waitImport}
  197. >
  198. <Typography variant="h5">Upload Files</Typography>
  199. </Button>
  200. </label>
  201. </ThemeProvider>
  202. </Stack>
  203. </Grid>
  204. :null
  205. }
  206. {/*row 1*/}
  207. <Grid item xs={12} md={12} lg={12} width="100%">
  208. <SearchForm
  209. applySearch={applySearch}
  210. comboData={comboData}
  211. onGridReady={onGridReady}
  212. />
  213. </Grid>
  214. {/*row 2*/}
  215. {!onSearchReady?
  216. <LoadingComponent/>:
  217. <Grid item xs={12} md={12} lg={12} width="100%">
  218. <MainCard elevation={0}
  219. border={false}
  220. content={false}
  221. >
  222. <GazetteIssueTable
  223. searchCriteria={searchCriteria}
  224. applyGridOnReady={applyGridOnReady}
  225. />
  226. </MainCard>
  227. </Grid>
  228. }
  229. <div>
  230. <Dialog
  231. open={isWarningPopUp}
  232. onClose={() => setIsWarningPopUp(false)}
  233. PaperProps={{
  234. sx: {
  235. minWidth: '40vw',
  236. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  237. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  238. }
  239. }}
  240. >
  241. <DialogTitle><Typography variant="h3">Warning</Typography></DialogTitle>
  242. <DialogContent style={{ display: 'flex', }}>
  243. <Typography variant="h4" style={{ padding: '16px' }}>{warningText}</Typography>
  244. </DialogContent>
  245. <DialogActions>
  246. <Button onClick={() => setIsWarningPopUp(false)}><Typography variant="h5">OK</Typography></Button>
  247. </DialogActions>
  248. </Dialog>
  249. </div>
  250. </Grid >
  251. )
  252. );
  253. };
  254. export default Index;