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.
 
 

155 regels
6.3 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. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  15. const SearchPublicNoticeForm = ({ applySearch, searchCriteria}) => {
  16. const navigate = useNavigate()
  17. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  18. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  19. const marginBottom = 2.5;
  20. const { reset, register, handleSubmit } = useForm()
  21. const onSubmit = (data) => {
  22. const temp = {
  23. key: data.key,
  24. dateFrom: data.dateFrom,
  25. dateTo: data.dateTo,
  26. };
  27. applySearch(temp);
  28. };
  29. function resetForm() {
  30. reset();
  31. }
  32. return (
  33. <MainCard xs={12} md={12} lg={12}
  34. border={false}
  35. content={false}
  36. sx={{ backgroundColor: '#fff' }}
  37. >
  38. <form onSubmit={handleSubmit(onSubmit)}>
  39. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: marginBottom}} width="98%">
  40. {/*row 1*/}
  41. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:marginBottom}}>
  42. <Typography variant="pnspsFormHeader" >
  43. Search
  44. </Typography>
  45. </Grid>
  46. {/*row 2*/}
  47. <Grid container display="flex" alignItems={"center"}>
  48. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  49. <TextField
  50. fullWidth
  51. {...register("key")}
  52. id='key'
  53. label={"Key"}
  54. defaultValue={searchCriteria.key}
  55. InputLabelProps={{
  56. shrink: true
  57. }}
  58. />
  59. </Grid>
  60. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:marginBottom}}>
  61. <Grid container spacing={1}>
  62. <Grid item xs={6}>
  63. <TextField
  64. fullWidth
  65. {...register("dateFrom")}
  66. id="dateFrom"
  67. type="date"
  68. label={"Submit Date (From)"}
  69. defaultValue={searchCriteria.dateFrom}
  70. InputProps={{ inputProps: { max: maxDate } }}
  71. onChange={(newValue) => {
  72. setMinDate(DateUtils.dateValue(newValue));
  73. }}
  74. InputLabelProps={{
  75. shrink: true
  76. }}
  77. sx={{ "& .MuiInputBase-input": {display:"block"} }}
  78. />
  79. </Grid>
  80. <Grid item xs={6}>
  81. <TextField
  82. fullWidth
  83. InputLabelProps={{
  84. shrink: true
  85. }}
  86. {...register("dateTo")}
  87. InputProps={{ inputProps: { min: minDate } }}
  88. onChange={(newValue) => {
  89. setMaxDate(DateUtils.dateValue(newValue));
  90. }}
  91. id="dateTo"
  92. type="date"
  93. label={"Submit Date (To)"}
  94. defaultValue={searchCriteria.dateTo}
  95. sx={{ "& .MuiInputBase-input": {display:"block"} }}
  96. />
  97. </Grid>
  98. </Grid>
  99. </Grid>
  100. </Grid>
  101. {/*last row*/}
  102. <Grid container maxWidth justifyContent="flex-end">
  103. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  104. <Grid item sx={{ ml: 3 }}>
  105. <Button
  106. variant="contained"
  107. color="green"
  108. onClick={()=>{
  109. navigate('/setting/announcement/details/' + 0);
  110. }}
  111. >
  112. Create
  113. </Button>
  114. </Grid>
  115. <Grid item sx={{ ml: 3 }}>
  116. <Button
  117. variant="contained"
  118. color="cancel"
  119. onClick={resetForm}
  120. >
  121. Reset
  122. </Button>
  123. </Grid>
  124. <Grid item sx={{ ml: 3 }}>
  125. <Button
  126. variant="contained"
  127. type="submit"
  128. >
  129. Submit
  130. </Button>
  131. </Grid>
  132. </ThemeProvider>
  133. </Grid>
  134. </Grid>
  135. </form>
  136. </MainCard>
  137. );
  138. };
  139. export default SearchPublicNoticeForm;