您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

233 行
10 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. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  25. import dayjs from "dayjs";
  26. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  27. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  28. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  29. import { isGranted } from "auth/utils";
  30. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  31. const AuditLogSearchForm = ({ applySearch, searchCriteria, onGridReady}) => {
  32. // const navigate = useNavigate();
  33. const [minDate, setMinDate] = React.useState(searchCriteria.modifiedFrom);
  34. const [maxDate, setMaxDate] = React.useState(searchCriteria.modifiedTo);
  35. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  36. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  37. const [onDownload, setOnDownload] = React.useState(false);
  38. const marginBottom = 2.5;
  39. const { reset, register, handleSubmit } = useForm()
  40. React.useEffect(() => {
  41. setFromDateValue(minDate);
  42. }, [minDate]);
  43. React.useEffect(() => {
  44. setToDateValue(maxDate);
  45. }, [maxDate]);
  46. const onSubmit = (data) => {
  47. let sentDateFrom = "";
  48. let sentDateTo = "";
  49. if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") {
  50. sentDateFrom = DateUtils.dateValue(fromDateValue)
  51. sentDateTo = DateUtils.dateValue(toDateValue)
  52. }
  53. const temp = {
  54. username: data.userName,
  55. modifiedTo: sentDateTo,
  56. modifiedFrom: sentDateFrom,
  57. };
  58. applySearch(temp);
  59. };
  60. function resetForm() {
  61. reset();
  62. }
  63. function exportExcel() {
  64. setOnDownload(true)
  65. HttpUtils.fileDownload({
  66. url: UrlUtils.AUDIT_LOG_EXPORT,
  67. onResponse:()=>{
  68. setOnDownload(false)
  69. },
  70. onError:()=>{
  71. setOnDownload(false)
  72. }
  73. });
  74. }
  75. return (
  76. <MainCard xs={12} md={12} lg={12}
  77. border={false}
  78. content={false}>
  79. <form onSubmit={handleSubmit(onSubmit)}>
  80. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
  81. {/*row 1*/}
  82. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  83. <Typography variant="pnspsFormHeader" >
  84. Search
  85. </Typography>
  86. </Grid>
  87. {/*row 2*/}
  88. <Grid container display="flex" alignItems={"center"}>
  89. <Grid item xs={9} md={5} lg={5} sx={{ ml: 3, mr: 3, mb: 3 }}>
  90. <TextField
  91. fullWidth
  92. {...register("userName")}
  93. id='userName'
  94. label="Username"
  95. InputLabelProps={{
  96. shrink: true
  97. }}
  98. />
  99. </Grid>
  100. <Grid item xs={9} md={5} lg={5} sx={{ ml: 3, mr: 3, mb: 3 }}></Grid>
  101. <Grid item xs={9} s={6} md={6} lg={6} sx={{ml:3, mr:3, mb:marginBottom}}>
  102. <Grid container>
  103. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  104. <LocalizationProvider dateAdapter={AdapterDayjs}>
  105. <DemoItem components={['DatePicker']}>
  106. <DatePicker
  107. id="modifiedFrom"
  108. // onError={(newError) => setReceiptFromError(newError)}
  109. slotProps={{
  110. field: { readOnly: true, },
  111. // textField: {
  112. // helperText: receiptFromErrorMessage,
  113. // },
  114. }}
  115. format="DD/MM/YYYY"
  116. label="Modified From"
  117. value={minDate === null ? null : dayjs(minDate)}
  118. maxDate={maxDate === null ? null : dayjs(maxDate)}
  119. onChange={(newValue) => {
  120. // console.log(newValue)
  121. if(newValue!=null){
  122. setMinDate(newValue);
  123. }
  124. }}
  125. />
  126. </DemoItem >
  127. </LocalizationProvider>
  128. </Grid>
  129. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:0.8, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  130. To
  131. </Grid>
  132. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  133. <LocalizationProvider dateAdapter={AdapterDayjs}>
  134. <DemoItem components={['DatePicker']}>
  135. <DatePicker
  136. id="modifiedTo"
  137. // onError={(newError) => setReceiptFromError(newError)}
  138. slotProps={{
  139. field: { readOnly: true, },
  140. // textField: {
  141. // helperText: receiptFromErrorMessage,
  142. // },
  143. }}
  144. format="DD/MM/YYYY"
  145. label="Modified To"
  146. value={maxDate === null ? null : dayjs(maxDate)}
  147. minDate={minDate === null ? null : dayjs(minDate)}
  148. onChange={(newValue) => {
  149. // console.log(newValue)
  150. if(newValue!=null){
  151. setMaxDate(newValue);
  152. }
  153. }}
  154. />
  155. </DemoItem >
  156. </LocalizationProvider>
  157. </Grid>
  158. </Grid>
  159. </Grid>
  160. </Grid>
  161. {/*last row*/}
  162. <Grid container direction="row"
  163. justifyContent="space-between"
  164. alignItems="center">
  165. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  166. <Grid item xs={12} md={12}>
  167. <Grid container maxWidth justifyContent="flex-end">
  168. {isGranted("MAINTAIN_SETTING") ?
  169. <Grid item sx={{ ml: 3, mr: 3, mb: 3,}}>
  170. {onDownload?
  171. <LoadingComponent disableText={true} alignItems="flex-start"/>
  172. :
  173. <Button
  174. variant="contained"
  175. onClick={exportExcel}
  176. >
  177. Export
  178. </Button>
  179. }
  180. </Grid> : null
  181. }
  182. <Grid item sx={{ ml: 3, mr: 3, mb: 3,}}>
  183. <Button
  184. variant="contained"
  185. color="cancel"
  186. onClick={resetForm}
  187. >
  188. Reset
  189. </Button>
  190. </Grid>
  191. <Grid item sx={{ ml: 3, mb: 3 }}>
  192. <Button
  193. variant="contained"
  194. type="submit"
  195. disabled={onGridReady}
  196. >
  197. Search
  198. </Button>
  199. </Grid>
  200. </Grid>
  201. </Grid>
  202. </ThemeProvider>
  203. </Grid>
  204. </Grid>
  205. </form>
  206. </MainCard>
  207. );
  208. };
  209. export default AuditLogSearchForm;