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.
 
 

167 lines
6.8 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. const BackgroundHead = {
  14. backgroundImage: `url(${titleBackgroundImg})`,
  15. width: '100%',
  16. height: '100%',
  17. backgroundSize: 'contain',
  18. backgroundRepeat: 'no-repeat',
  19. backgroundColor: '#0C489E',
  20. backgroundPosition: 'right'
  21. }
  22. import {PNSPS_LONG_BUTTON_THEME} from "themes/buttonConst";
  23. import {ThemeProvider} from "@emotion/react";
  24. import { notifySaveSuccess } from 'utils/CommonFunction';
  25. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  26. const Index = () => {
  27. const [attachments, setAttachments] = React.useState([]);
  28. const [waitImport, setWaitImport] = React.useState(false);
  29. const [waitDownload, setWaitDownload] = React.useState(false);
  30. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  31. const [warningText, setWarningText] = React.useState("");
  32. React.useEffect(() => {
  33. if (attachments.length > 0) {
  34. importHoliday();
  35. }
  36. }, [attachments]);
  37. const readFile = (event) => {
  38. let file = event.target.files[0];
  39. if (file) {
  40. if (!file.name.toLowerCase().substr(file.name.length - 5).includes(".xlsx")) {
  41. setWarningText("Please upload a valid file (File format: .xlsx).");
  42. setIsWarningPopUp(true);
  43. document.getElementById("uploadFileBtn").value = "";
  44. return;
  45. }
  46. file['id'] = attachments.length;
  47. setAttachments([
  48. ...attachments,
  49. file
  50. ]);
  51. document.getElementById("uploadFileBtn").value = "";
  52. }
  53. }
  54. const doExport=()=>{
  55. setWaitDownload(true)
  56. HttpUtils.fileDownload({
  57. url: UrlUtils.GET_ISSUE_LIST,
  58. onResponse: () => {
  59. setTimeout(()=> setWaitDownload(false), 500)
  60. }
  61. });
  62. }
  63. const importHoliday = () => {
  64. setWaitImport(true);
  65. if (!attachments || attachments.length <= 0) {
  66. setWarningText("Please upload file.");
  67. setSaving(false);
  68. return;
  69. }
  70. HttpUtils.postWithFiles({
  71. url: UrlUtils.POST_ISSUE_FILE,
  72. files: attachments,
  73. onSuccess: () => {
  74. notifySaveSuccess()
  75. setWaitImport(false);
  76. setAttachments([]);
  77. // loadForm();
  78. }
  79. });
  80. }
  81. return (
  82. <Grid container sx={{minHeight: '87vh', backgroundColor: 'backgroundColor.default'}} direction="column" justifyContent="flex-start" alignItems="center" >
  83. <Grid item xs={12} width="100%">
  84. <div style={BackgroundHead} width="100%">
  85. <Stack direction="row" height='70px'>
  86. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>Gazette Issue</Typography>
  87. </Stack>
  88. </div>
  89. </Grid>
  90. <Grid item xs={12} md={12} lg={6} width="100%">
  91. <Stack direction="row" justifyContent="flex-start" alignItems="center" spacing={2} sx={{ml:2,mt:1}} >
  92. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  93. <label htmlFor="downloadFileBtn">
  94. <Button
  95. component="span"
  96. variant="contained"
  97. size="large"
  98. disabled={waitDownload}
  99. onClick={doExport}
  100. >
  101. <Typography variant="h5">Export</Typography>
  102. </Button>
  103. </label>
  104. </ThemeProvider>
  105. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  106. <input
  107. id="uploadFileBtn"
  108. name="file"
  109. type="file"
  110. accept=".xlsx"
  111. style={{ display: 'none' }}
  112. disabled={waitImport}
  113. onChange={(event) => {
  114. readFile(event)
  115. }}
  116. />
  117. <label htmlFor="uploadFileBtn">
  118. <Button
  119. component="span"
  120. variant="contained"
  121. size="large"
  122. disabled={waitImport}
  123. >
  124. <Typography variant="h5">Upload Files</Typography>
  125. </Button>
  126. </label>
  127. </ThemeProvider>
  128. </Stack>
  129. </Grid>
  130. <div>
  131. <Dialog
  132. open={isWarningPopUp}
  133. onClose={() => setIsWarningPopUp(false)}
  134. PaperProps={{
  135. sx: {
  136. minWidth: '40vw',
  137. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  138. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  139. }
  140. }}
  141. >
  142. <DialogTitle><Typography variant="h3">Warning</Typography></DialogTitle>
  143. <DialogContent style={{ display: 'flex', }}>
  144. <Typography variant="h4" style={{ padding: '16px' }}>{warningText}</Typography>
  145. </DialogContent>
  146. <DialogActions>
  147. <Button onClick={() => setIsWarningPopUp(false)}><Typography variant="h5">OK</Typography></Button>
  148. </DialogActions>
  149. </Dialog>
  150. </div>
  151. </Grid >
  152. );
  153. };
  154. export default Index;