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.

176 lines
7.5 KiB

  1. import * as React from "react";
  2. import * as HttpUtils from "utils/HttpUtils";
  3. import * as UrlUtils from "utils/ApiPathConst";
  4. import {
  5. Grid, Typography, Button,
  6. Stack, Box,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. } from '@mui/material';
  9. import { notifyDownloadSuccess } from 'utils/CommonFunction';
  10. import { FormattedMessage, useIntl } from "react-intl";
  11. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  12. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  13. const Index = () => {
  14. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  15. const [warningText, setWarningText] = React.useState("");
  16. const [resultStr, setResultStr] = React.useState("");
  17. const intl = useIntl();
  18. const BackgroundHead = {
  19. backgroundImage: `url(${titleBackgroundImg})`,
  20. width: 'auto',
  21. height: 'auto',
  22. backgroundSize: 'contain',
  23. backgroundRepeat: 'no-repeat',
  24. backgroundColor: '#0C489E',
  25. backgroundPosition: 'right'
  26. }
  27. const readFile = (event) => {
  28. let file = event.target.files[0];
  29. if (file) {
  30. if (file.name.toLowerCase().substr(file.name.length - 5).includes(".xlsx")
  31. ) {
  32. HttpUtils.postWithFiles({
  33. url: UrlUtils.DR_IMPORT,
  34. params:null,
  35. files: [event.target.files[0]],
  36. onSuccess: function (responData) {
  37. if(responData?.msg){
  38. setResultStr(<><span style={{"color": "red"}}>Error</span><br/><span style={{"whiteSpace": "pre-line"}}>{responData?.msg}</span></>)
  39. }else if(responData?.success){
  40. setResultStr(<><span style={{"color": "green"}}>Success</span><br/>Record Count: {responData.recordCount}</>)
  41. }
  42. }
  43. });
  44. } else {
  45. setWarningText(intl.formatMessage({ id: 'requireValidFileWithFormat' }));
  46. setIsWarningPopUp(true);
  47. setAttachment({});
  48. document.getElementById("uploadFileBtn").value = "";
  49. return;
  50. }
  51. }
  52. document.getElementById("uploadFileBtn").value = "";
  53. }
  54. return (
  55. <Grid container sx={{ minHeight: '87vh', backgroundColor: 'backgroundColor.default' }} direction="column" alignItems="center">
  56. <Grid item xs={12} md={12} width="100%" >
  57. <div style={BackgroundHead}>
  58. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  59. <Typography ml={15} color='#FFF' variant="h4" sx={{ display: { xs: 'none', sm: 'none', md: 'block' } }}>
  60. DR Import
  61. </Typography>
  62. </Stack>
  63. </div>
  64. </Grid>
  65. <Grid item xs={12} md={12} sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, }} width="98%">
  66. <Box xs={12} md={12} sx={{ borderRadius: '10px', backgroundColor: '#fff', p: 4 }}>
  67. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  68. <Button
  69. aria-label={intl.formatMessage({ id: 'uploadFileBtn' })}
  70. component="span"
  71. variant="outlined"
  72. size="large"
  73. onClick={()=>{
  74. HttpUtils.fileDownload({
  75. url: UrlUtils.DR_EXPORT,
  76. onSuccess: ()=>{
  77. notifyDownloadSuccess();
  78. }
  79. });
  80. }}
  81. >Export DR Excel</Button>
  82. <Grid item sx={{ pl: 4 }}>
  83. <Grid container direction="row" justifyContent="flex-start" alignItems="center">
  84. <Grid item xs={12} md={6} lg={6} sx={{ wordBreak: 'break-word' }}>
  85. <input
  86. id="uploadFileBtn"
  87. name="file"
  88. type="file"
  89. accept=".xlsx"
  90. style={{ display: 'none' }}
  91. onChange={(event) => {
  92. readFile(event)
  93. }}
  94. />
  95. </Grid>
  96. </Grid>
  97. </Grid>
  98. <Grid item >
  99. <Grid container direction="row" justifyContent="flex-start" alignItems="center">
  100. <Grid item xs={12} >
  101. <label htmlFor="uploadFileBtn">
  102. <Button
  103. aria-label={intl.formatMessage({ id: 'uploadFileBtn' })}
  104. component="span"
  105. variant="outlined"
  106. size="large"
  107. >Import DR Excel</Button>
  108. </label>
  109. </Grid>
  110. </Grid>
  111. </Grid>
  112. </Stack>
  113. </Box>
  114. </Grid>
  115. <Grid item xs={12} md={12} sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, }} width="98%" >
  116. <Box xs={12} md={12} sx={{ borderRadius: '10px', backgroundColor: '#fff', p: 4 }}>
  117. <Typography variant="h4">Result:</Typography>
  118. <Box xs={12} md={12} sx={{ pl: 4 }}>
  119. {resultStr}
  120. </Box>
  121. </Box>
  122. </Grid>
  123. <div>
  124. <Dialog
  125. open={isWarningPopUp}
  126. onClose={() => setIsWarningPopUp(false)}
  127. PaperProps={{
  128. sx: {
  129. minWidth: '40vw',
  130. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  131. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  132. }
  133. }}
  134. >
  135. <DialogTitle>
  136. Action Fail
  137. </DialogTitle>
  138. <DialogContent style={{ display: 'flex', }}>
  139. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  140. </DialogContent>
  141. <DialogActions>
  142. <Button
  143. aria-label={intl.formatMessage({ id: 'ok' })}
  144. onClick={() => { setIsWarningPopUp(false); }}
  145. >
  146. <FormattedMessage id="ok" />
  147. </Button>
  148. </DialogActions>
  149. </Dialog>
  150. </div>
  151. </Grid>
  152. );
  153. };
  154. export default Index;