Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

187 rader
7.8 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete,
  6. Typography
  7. } from '@mui/material';
  8. import MainCard from "components/MainCard";
  9. import { useForm } from "react-hook-form";
  10. import * as React from "react";
  11. import * as DateUtils from "utils/DateUtils";
  12. import * as ComboData from "utils/ComboData";
  13. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  14. import {ThemeProvider} from "@emotion/react";
  15. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  16. const SearchPublicNoticeForm = ({ applySearch, searchCriteria }) => {
  17. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  18. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  19. const [status, setStatus] = React.useState(ComboData.paymentStatus[0]);
  20. const { reset, register, handleSubmit } = useForm()
  21. const marginBottom = 2.5;
  22. const onSubmit = (data) => {
  23. const temp = {
  24. code: data.code,
  25. transNo: data.transNo,
  26. dateFrom: data.dateFrom,
  27. dateTo: data.dateTo,
  28. status : (status?.type && status?.type != 'all') ? status?.type : "",
  29. };
  30. applySearch(temp);
  31. };
  32. function resetForm() {
  33. setStatus(ComboData.paymentStatus[0]);
  34. reset();
  35. }
  36. return (
  37. <MainCard xs={12} md={12} lg={12}
  38. border={false}
  39. content={false}
  40. >
  41. <form onSubmit={handleSubmit(onSubmit)} >
  42. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: marginBottom}} width="98%">
  43. {/*row 1*/}
  44. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  45. <Typography variant="pnspsFormHeader" >
  46. Search
  47. </Typography>
  48. </Grid>
  49. {/*row 2*/}
  50. <Grid container display="flex" alignItems={"center"}>
  51. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3,mb: marginBottom}}>
  52. <TextField
  53. fullWidth
  54. {...register("code")}
  55. id='code'
  56. label="Application No."
  57. defaultValue={searchCriteria.code}
  58. InputLabelProps={{
  59. shrink: true
  60. }}
  61. />
  62. </Grid>
  63. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:marginBottom}}>
  64. <Grid container spacing={1}>
  65. <Grid item xs={6}>
  66. <TextField
  67. fullWidth
  68. {...register("dateFrom")}
  69. id="dateFrom"
  70. type="date"
  71. label="Transaction Date (From)"
  72. defaultValue={searchCriteria.dateFrom}
  73. InputProps={{ inputProps: { max: maxDate } }}
  74. onChange={(newValue) => {
  75. setMinDate(DateUtils.dateValue(newValue));
  76. }}
  77. InputLabelProps={{
  78. shrink: true
  79. }}
  80. />
  81. </Grid>
  82. <Grid item xs={6}>
  83. <TextField
  84. fullWidth
  85. InputLabelProps={{
  86. shrink: true
  87. }}
  88. {...register("dateTo")}
  89. InputProps={{ inputProps: { min: minDate } }}
  90. onChange={(newValue) => {
  91. setMaxDate(DateUtils.dateValue(newValue));
  92. }}
  93. id="dateTo"
  94. type="date"
  95. label="Transaction Date (To)"
  96. defaultValue={searchCriteria.dateTo}
  97. />
  98. </Grid>
  99. </Grid>
  100. </Grid>
  101. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom}}>
  102. <TextField
  103. fullWidth
  104. {...register("transNo")}
  105. id='transNo'
  106. label="Transaction No."
  107. defaultValue={searchCriteria.transNo}
  108. InputLabelProps={{
  109. shrink: true
  110. }}
  111. />
  112. </Grid>
  113. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  114. <Autocomplete
  115. {...register("status")}
  116. disablePortal={false}
  117. size="small"
  118. id="status"
  119. filterOptions={(options) => options}
  120. options={ComboData.paymentStatus}
  121. value={status}
  122. getOptionLabel={(option) => option.label}
  123. inputValue={status?.label ? status?.label : ""}
  124. onChange={(event, newValue) => {
  125. if(newValue==null){
  126. setStatus(ComboData.paymentStatus[0]);
  127. }else{
  128. setStatus(newValue);
  129. }
  130. }}
  131. renderInput={(params) => (
  132. <TextField {...params}
  133. label="Status"
  134. />
  135. )}
  136. InputLabelProps={{
  137. shrink: true
  138. }}
  139. />
  140. </Grid>
  141. </Grid>
  142. </Grid>
  143. {/*last row*/}
  144. <Grid container maxWidth justifyContent="flex-end">
  145. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  146. <Grid item sx={{ ml: 3, mb: 3}}>
  147. <Button
  148. variant="contained"
  149. color="cancel"
  150. onClick={resetForm}
  151. >
  152. Reset
  153. </Button>
  154. </Grid>
  155. <Grid item sx={{ ml: 3, mr: 3, mb: 3 }}>
  156. <Button
  157. variant="contained"
  158. type="submit"
  159. >
  160. Submit
  161. </Button>
  162. </Grid>
  163. </ThemeProvider>
  164. </Grid>
  165. </form>
  166. </MainCard>
  167. );
  168. };
  169. export default SearchPublicNoticeForm;