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.

233 wiersze
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. start:0,
  58. limit:10
  59. };
  60. applySearch(temp);
  61. };
  62. function resetForm() {
  63. reset();
  64. }
  65. function exportExcel() {
  66. setOnDownload(true)
  67. HttpUtils.fileDownload({
  68. url: UrlUtils.AUDIT_LOG_EXPORT,
  69. params: searchCriteria,
  70. onResponse:()=>{
  71. setOnDownload(false)
  72. },
  73. onError:()=>{
  74. setOnDownload(false)
  75. }
  76. });
  77. }
  78. return (
  79. <MainCard xs={12} md={12} lg={12}
  80. border={false}
  81. content={false}>
  82. <form onSubmit={handleSubmit(onSubmit)}>
  83. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
  84. {/*row 1*/}
  85. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  86. <Typography variant="pnspsFormHeader" >
  87. Search
  88. </Typography>
  89. </Grid>
  90. {/*row 2*/}
  91. <Grid container display="flex" alignItems={"center"}>
  92. <Grid item xs={9} md={5} lg={5} sx={{ ml: 3, mr: 3, mb: 3 }}>
  93. <TextField
  94. fullWidth
  95. {...register("userName")}
  96. id='userName'
  97. label="Username"
  98. InputLabelProps={{
  99. shrink: true
  100. }}
  101. />
  102. </Grid>
  103. <Grid item xs={9} md={5} lg={5} sx={{ ml: 3, mr: 3, mb: 3 }}></Grid>
  104. <Grid item xs={9} s={6} md={6} lg={6} sx={{ml:3, mr:3, mb:marginBottom}}>
  105. <Grid container>
  106. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  107. <LocalizationProvider dateAdapter={AdapterDayjs}>
  108. <DemoItem components={['DatePicker']}>
  109. <DatePicker
  110. id="modifiedFrom"
  111. // onError={(newError) => setReceiptFromError(newError)}
  112. slotProps={{
  113. field: { readOnly: true, },
  114. // textField: {
  115. // helperText: receiptFromErrorMessage,
  116. // },
  117. }}
  118. format="DD/MM/YYYY"
  119. label="Modified From"
  120. value={minDate === null ? null : dayjs(minDate)}
  121. maxDate={maxDate === null ? null : dayjs(maxDate)}
  122. onChange={(newValue) => {
  123. // console.log(newValue)
  124. if(newValue!=null){
  125. setMinDate(newValue);
  126. }
  127. }}
  128. />
  129. </DemoItem >
  130. </LocalizationProvider>
  131. </Grid>
  132. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:0.8, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  133. To
  134. </Grid>
  135. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  136. <LocalizationProvider dateAdapter={AdapterDayjs}>
  137. <DemoItem components={['DatePicker']}>
  138. <DatePicker
  139. id="modifiedTo"
  140. // onError={(newError) => setReceiptFromError(newError)}
  141. slotProps={{
  142. field: { readOnly: true, },
  143. // textField: {
  144. // helperText: receiptFromErrorMessage,
  145. // },
  146. }}
  147. format="DD/MM/YYYY"
  148. label="Modified To"
  149. value={maxDate === null ? null : dayjs(maxDate)}
  150. minDate={minDate === null ? null : dayjs(minDate)}
  151. onChange={(newValue) => {
  152. // console.log(newValue)
  153. if(newValue!=null){
  154. setMaxDate(newValue);
  155. }
  156. }}
  157. />
  158. </DemoItem >
  159. </LocalizationProvider>
  160. </Grid>
  161. </Grid>
  162. </Grid>
  163. </Grid>
  164. {/*last row*/}
  165. <Grid container direction="row"
  166. justifyContent="space-between"
  167. alignItems="center">
  168. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  169. <Grid item xs={12} md={12}>
  170. <Grid container maxWidth justifyContent="flex-end">
  171. {isGranted("MAINTAIN_SETTING") ?
  172. <Grid item sx={{ ml: 3, mr: 3, mb: 3,}}>
  173. <Button
  174. variant="contained"
  175. onClick={exportExcel}
  176. disabled={onDownload}
  177. >
  178. Export
  179. </Button>
  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;