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.
 
 

221 line
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. };
  64. applySearch(temp);
  65. };
  66. function resetForm() {
  67. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  68. setMaxDate(DateUtils.dateValue(new Date()))
  69. reset();
  70. localStorage.setItem('searchCriteria',"")
  71. }
  72. return (
  73. <MainCard xs={12} md={12} lg={12}
  74. border={false}
  75. content={false}
  76. sx={_sx}
  77. >
  78. <form onSubmit={handleSubmit(onSubmit)}>
  79. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: marginBottom }} width="98%">
  80. {/*row 1*/}
  81. <Grid item justifyContent="space-between" alignItems="center" sx={{ mt: 1, ml: 3, mb: marginBottom }}>
  82. <Typography variant="pnspsFormHeader" >
  83. <FormattedMessage id="search"></FormattedMessage>
  84. </Typography>
  85. </Grid>
  86. {/*row 2*/}
  87. <Grid container display="flex" alignItems={"center"}>
  88. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  89. <TextField
  90. fullWidth
  91. {...register("key")}
  92. id='key'
  93. label={intl.formatMessage({ id: 'keyword' }) + ":"}
  94. defaultValue={searchCriteria.key}
  95. InputLabelProps={{
  96. shrink: true
  97. }}
  98. />
  99. </Grid>
  100. <Grid item xs={12} s={6} md={6} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}>
  101. <Grid container>
  102. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  103. <LocalizationProvider dateAdapter={AdapterDayjs}>
  104. <DemoItem components={['DatePicker']}>
  105. <DatePicker
  106. id="dateFrom"
  107. // onError={(newError) => setReceiptFromError(newError)}
  108. slotProps={{
  109. field: { readOnly: true, },
  110. // textField: {
  111. // helperText: receiptFromErrorMessage,
  112. // },
  113. }}
  114. format="DD/MM/YYYY"
  115. aria-label={intl.formatMessage({id: 'dateFrom'})}
  116. label={intl.formatMessage({id: 'dateFrom'})}
  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:1.3, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  130. <FormattedMessage id="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="dateTo"
  137. // onError={(newError) => setReceiptFromError(newError)}
  138. slotProps={{
  139. field: { readOnly: true, },
  140. // textField: {
  141. // helperText: receiptFromErrorMessage,
  142. // },
  143. }}
  144. format="DD/MM/YYYY"
  145. aria-label={intl.formatMessage({id: 'dateTo'})}
  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 maxWidth justifyContent="flex-end">
  163. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  164. {/* <Grid item sx={{ ml: 3 }}>
  165. <Button
  166. variant="contained"
  167. color="green"
  168. onClick={() => {
  169. navigate('/setting/announcement/details/' + 0);
  170. }}
  171. >
  172. <FormattedMessage id="create"></FormattedMessage>
  173. </Button>
  174. </Grid> */}
  175. <Grid item sx={{ ml: 3 }}>
  176. <Button
  177. variant="contained"
  178. onClick={resetForm}
  179. >
  180. <FormattedMessage id="reset"></FormattedMessage>
  181. </Button>
  182. </Grid>
  183. <Grid item sx={{ ml: 3 }}>
  184. <Button
  185. variant="contained"
  186. type="submit"
  187. disabled={onGridReady}
  188. aria-label={intl.formatMessage({id: 'submit'})}
  189. >
  190. <FormattedMessage id="submit"></FormattedMessage>
  191. </Button>
  192. </Grid>
  193. </ThemeProvider>
  194. </Grid>
  195. </Grid>
  196. </form>
  197. </MainCard>
  198. );
  199. };
  200. export default SearchPublicNoticeForm;