Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

201 строка
8.9 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Typography
  6. } from '@mui/material';
  7. import MainCard from "components/MainCard";
  8. import { useForm } from "react-hook-form";
  9. import * as React from "react";
  10. import * as DateUtils from "utils/DateUtils";
  11. import {ThemeProvider} from "@emotion/react";
  12. import { useNavigate } from "react-router-dom";
  13. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  14. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  15. import dayjs from "dayjs";
  16. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  17. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  18. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  19. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  20. const SearchPublicNoticeForm = ({ applySearch, searchCriteria, onGridReady}) => {
  21. const navigate = useNavigate()
  22. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  23. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  24. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  25. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  26. React.useEffect(() => {
  27. // console.log(minDate)
  28. setFromDateValue(minDate);
  29. }, [minDate]);
  30. React.useEffect(() => {
  31. setToDateValue(maxDate);
  32. }, [maxDate]);
  33. const marginBottom = 2.5;
  34. const { reset, register, handleSubmit } = useForm()
  35. const onSubmit = (data) => {
  36. let sentDateFrom = "";
  37. let sentDateTo = "";
  38. if( fromDateValue!="dd / mm / yyyy"&&toDateValue!="dd / mm / yyyy"){
  39. sentDateFrom = DateUtils.dateValue(fromDateValue)
  40. sentDateTo = DateUtils.dateValue(toDateValue)
  41. }
  42. const temp = {
  43. key: data.key,
  44. dateFrom: sentDateFrom,
  45. dateTo: sentDateTo,
  46. start:0,
  47. limit:10
  48. };
  49. applySearch(temp);
  50. };
  51. function resetForm() {
  52. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  53. setMaxDate(DateUtils.dateValue(new Date()))
  54. reset({key:""});
  55. localStorage.setItem('searchCriteria',"")
  56. }
  57. return (
  58. <MainCard xs={12} md={12} lg={12}
  59. border={false}
  60. content={false}
  61. sx={{ backgroundColor: '#fff' }}
  62. >
  63. <form onSubmit={handleSubmit(onSubmit)}>
  64. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: marginBottom}} width="98%">
  65. {/*row 1*/}
  66. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:marginBottom}}>
  67. <Typography variant="pnspsFormHeader" >
  68. Search
  69. </Typography>
  70. </Grid>
  71. {/*row 2*/}
  72. <Grid container display="flex" alignItems={"center"}>
  73. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  74. <TextField
  75. fullWidth
  76. {...register("key")}
  77. id='key'
  78. label={"Key"}
  79. defaultValue={searchCriteria.key}
  80. InputLabelProps={{
  81. shrink: true
  82. }}
  83. />
  84. </Grid>
  85. <Grid item xs={12} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:marginBottom}}>
  86. <Grid container spacing={1}>
  87. <Grid item xs={6}>
  88. <LocalizationProvider dateAdapter={AdapterDayjs}>
  89. <DemoItem components={['DatePicker']}>
  90. <DatePicker
  91. id="dateFrom"
  92. // onError={(newError) => setReceiptFromError(newError)}
  93. slotProps={{
  94. field: { readOnly: true, },
  95. // textField: {
  96. // helperText: receiptFromErrorMessage,
  97. // },
  98. }}
  99. format="DD/MM/YYYY"
  100. label={"Submit Date (From)"}
  101. value={minDate === null ? null : dayjs(minDate)}
  102. maxDate={maxDate === null ? null : dayjs(maxDate)}
  103. onChange={(newValue) => {
  104. // console.log(newValue)
  105. if(newValue!=null){
  106. setMinDate(newValue);
  107. }
  108. }}
  109. />
  110. </DemoItem >
  111. </LocalizationProvider>
  112. </Grid>
  113. <Grid item xs={6}>
  114. <LocalizationProvider dateAdapter={AdapterDayjs}>
  115. <DemoItem components={['DatePicker']}>
  116. <DatePicker
  117. id="dateTo"
  118. // onError={(newError) => setReceiptFromError(newError)}
  119. slotProps={{
  120. field: { readOnly: true, },
  121. // textField: {
  122. // helperText: receiptFromErrorMessage,
  123. // },
  124. }}
  125. format="DD/MM/YYYY"
  126. label={"Submit Date (To)"}
  127. value={maxDate === null ? null : dayjs(maxDate)}
  128. minDate={minDate === null ? null : dayjs(minDate)}
  129. onChange={(newValue) => {
  130. // console.log(newValue)
  131. if(newValue!=null){
  132. setMaxDate(newValue);
  133. }
  134. }}
  135. />
  136. </DemoItem >
  137. </LocalizationProvider>
  138. </Grid>
  139. </Grid>
  140. </Grid>
  141. </Grid>
  142. {/*last row*/}
  143. <Grid container maxWidth justifyContent="flex-end">
  144. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  145. <Grid item sx={{ ml: 3 }}>
  146. <Button
  147. variant="contained"
  148. color="green"
  149. onClick={()=>{
  150. navigate('/setting/announcement/details/' + 0);
  151. }}
  152. >
  153. Create
  154. </Button>
  155. </Grid>
  156. <Grid item sx={{ ml: 3 }}>
  157. <Button
  158. variant="contained"
  159. color="cancel"
  160. onClick={resetForm}
  161. >
  162. Reset
  163. </Button>
  164. </Grid>
  165. <Grid item sx={{ ml: 3 }}>
  166. <Button
  167. variant="contained"
  168. type="submit"
  169. disabled={onGridReady}
  170. >
  171. Submit
  172. </Button>
  173. </Grid>
  174. </ThemeProvider>
  175. </Grid>
  176. </Grid>
  177. </form>
  178. </MainCard>
  179. );
  180. };
  181. export default SearchPublicNoticeForm;