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.
 
 

191 line
7.6 KiB

  1. // material-uisubDivision
  2. import {
  3. Button,
  4. // FormControlLabel,
  5. Grid,
  6. TextField,
  7. Typography
  8. } from '@mui/material';
  9. import MainCard from "components/MainCard";
  10. import { useForm } from "react-hook-form";
  11. import {
  12. // useEffect,
  13. // useState
  14. } from "react";
  15. import * as React from "react";
  16. // import { useNavigate } from "react-router";
  17. import {PNSPS_BUTTON_THEME} from "themes/buttonConst";
  18. import {ThemeProvider} from "@emotion/react";
  19. import * as DateUtils from "utils/DateUtils";
  20. import * as UrlUtils from "utils/ApiPathConst";
  21. import * as HttpUtils from "utils/HttpUtils";
  22. import Loadable from 'components/Loadable';
  23. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  24. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  25. const AuditLogSearchForm = ({ applySearch, searchCriteria}) => {
  26. // const navigate = useNavigate();
  27. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  28. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  29. const [onDownload, setOnDownload] = React.useState(false);
  30. const marginBottom = 2.5;
  31. const { reset, register, handleSubmit } = useForm()
  32. const onSubmit = (data) => {
  33. const temp = {
  34. username: data.userName,
  35. modifiedTo: data.modifiedTo,
  36. modifiedFrom: data.modifiedFrom,
  37. };
  38. applySearch(temp);
  39. };
  40. function resetForm() {
  41. reset();
  42. }
  43. function exportExcel() {
  44. setOnDownload(true)
  45. HttpUtils.fileDownload({
  46. url: UrlUtils.AUDIT_LOG_EXPORT,
  47. onResponse:()=>{
  48. setOnDownload(false)
  49. },
  50. onError:()=>{
  51. setOnDownload(false)
  52. }
  53. });
  54. }
  55. return (
  56. <MainCard xs={12} md={12} lg={12}
  57. border={false}
  58. content={false}>
  59. <form onSubmit={handleSubmit(onSubmit)}>
  60. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
  61. {/*row 1*/}
  62. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  63. <Typography variant="pnspsFormHeader" >
  64. Search
  65. </Typography>
  66. </Grid>
  67. {/*row 2*/}
  68. <Grid container display="flex" alignItems={"center"}>
  69. <Grid item xs={9} md={5} lg={5} sx={{ ml: 3, mr: 3, mb: 3 }}>
  70. <TextField
  71. fullWidth
  72. {...register("userName")}
  73. id='userName'
  74. label="Username"
  75. InputLabelProps={{
  76. shrink: true
  77. }}
  78. />
  79. </Grid>
  80. <Grid item xs={9} md={5} lg={5} sx={{ ml: 3, mr: 3, mb: 3 }}></Grid>
  81. <Grid item xs={9} s={6} md={6} lg={6} sx={{ml:3, mr:3, mb:marginBottom}}>
  82. <Grid container>
  83. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  84. <TextField
  85. fullWidth
  86. {...register("modifiedFrom")}
  87. id="modifiedFrom"
  88. type="date"
  89. label="Modified From"
  90. defaultValue={searchCriteria.modifiedFrom}
  91. InputProps={{ inputProps: { max: maxDate } }}
  92. onChange={(newValue) => {
  93. setMinDate(DateUtils.dateStr(newValue));
  94. }}
  95. InputLabelProps={{
  96. shrink: true
  97. }}
  98. />
  99. </Grid>
  100. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:0.8, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  101. To
  102. </Grid>
  103. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  104. <TextField
  105. fullWidth
  106. InputLabelProps={{
  107. shrink: true
  108. }}
  109. {...register("modifiedTo")}
  110. InputProps={{ inputProps: { min: minDate } }}
  111. onChange={(newValue) => {
  112. console.log(newValue)
  113. setMaxDate(DateUtils.dateStr(newValue));
  114. }}
  115. id="modifiedTo"
  116. type="date"
  117. label="Modified To"
  118. defaultValue={searchCriteria.modifiedTo}
  119. />
  120. </Grid>
  121. </Grid>
  122. </Grid>
  123. </Grid>
  124. {/*last row*/}
  125. <Grid container direction="row"
  126. justifyContent="space-between"
  127. alignItems="center">
  128. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  129. <Grid item xs={12} md={12}>
  130. <Grid container maxWidth justifyContent="flex-end">
  131. <Grid item sx={{ ml: 3, mr: 3, mb: 3,}}>
  132. {onDownload?
  133. <LoadingComponent disableText={true} alignItems="flex-start"/>
  134. :
  135. <Button
  136. variant="contained"
  137. onClick={exportExcel}
  138. >
  139. Export
  140. </Button>
  141. }
  142. </Grid>
  143. <Grid item sx={{ ml: 3, mr: 3, mb: 3,}}>
  144. <Button
  145. variant="contained"
  146. color="cancel"
  147. onClick={resetForm}
  148. >
  149. Reset
  150. </Button>
  151. </Grid>
  152. <Grid item sx={{ ml: 3, mb: 3 }}>
  153. <Button
  154. variant="contained"
  155. type="submit"
  156. >
  157. Search
  158. </Button>
  159. </Grid>
  160. </Grid>
  161. </Grid>
  162. </ThemeProvider>
  163. </Grid>
  164. </Grid>
  165. </form>
  166. </MainCard>
  167. );
  168. };
  169. export default AuditLogSearchForm;