Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

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