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.
 
 

318 lines
13 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. CardContent,
  5. Grid, TextField,
  6. Autocomplete
  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 ComboData from "utils/ComboData";
  12. import * as DateUtils from "utils/DateUtils";
  13. import * as FormatUtils from "utils/FormatUtils";
  14. import { Typography } from '../../../../node_modules/@mui/material/index';
  15. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  16. const SearchPublicNoticeForm = ({ applySearch, orgComboData, searchCriteria, issueComboData
  17. }) => {
  18. const [type, setType] = React.useState([]);
  19. const [status, setStatus] = React.useState(ComboData.proofStatus[0]);
  20. const [orgSelected, setOrgSelected] = React.useState({});
  21. const [orgCombo, setOrgCombo] = React.useState();
  22. const [issueSelected, setIssueSelected] = React.useState({});
  23. const [issueCombo, setIssueCombo] = React.useState([]);
  24. const [groupSelected, setGroupSelected] = React.useState({});
  25. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  26. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  27. const { reset, register, handleSubmit } = useForm()
  28. const onSubmit = (data) => {
  29. let typeArray = [];
  30. for (let i = 0; i < type.length; i++) {
  31. typeArray.push(type[i].label);
  32. }
  33. const temp = {
  34. refNo: data.refNo,
  35. code: data.code,
  36. issueId: issueSelected?.id,
  37. gazettGroup: groupSelected?.type,
  38. dateFrom: data.dateFrom,
  39. dateTo: data.dateTo,
  40. contact: data.contact,
  41. replyed: (status?.type && status?.type != 'all') ? status?.type : "",
  42. orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "",
  43. };
  44. applySearch(temp);
  45. };
  46. React.useEffect(() => {
  47. if (orgComboData && orgComboData.length > 0) {
  48. setOrgCombo(orgComboData);
  49. }
  50. }, [orgComboData]);
  51. React.useEffect(() => {
  52. if (issueComboData && issueComboData.length > 0) {
  53. setIssueCombo(issueComboData);
  54. }
  55. }, [issueComboData]);
  56. function resetForm() {
  57. setType([]);
  58. setStatus(ComboData.proofStatus[0]);
  59. setOrgSelected({});
  60. setIssueSelected({});
  61. setGroupSelected({});
  62. reset();
  63. }
  64. function getIssueLabel(data) {
  65. if (data == {}) return "";
  66. return data.year
  67. + " Vol. " + FormatUtils.zeroPad(data.volume, 3)
  68. + ", No. " + FormatUtils.zeroPad(data.issueNo, 2)
  69. + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)");
  70. }
  71. return (
  72. <MainCard xs={12} md={12} lg={12}
  73. border={false}
  74. content={false}
  75. sx={{ backgroundColor: '#fff' }}
  76. >
  77. <form onSubmit={handleSubmit(onSubmit)}>
  78. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 3, mb: 3 }} width="98%">
  79. {/*row 1*/}
  80. <CardContent sx={{ px: 2.5, pt: 3 }}>
  81. <Grid item justifyContent="space-between" alignItems="center">
  82. <Typography variant="h5">Search Form</Typography>
  83. </Grid>
  84. </CardContent>
  85. {/*row 2*/}
  86. <Grid container alignItems={"center"}>
  87. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  88. <TextField
  89. fullWidth
  90. {...register("refNo")}
  91. id='refNo'
  92. label="Proof No."
  93. defaultValue={searchCriteria.refNo}
  94. InputLabelProps={{
  95. shrink: true
  96. }}
  97. />
  98. </Grid>
  99. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  100. <TextField
  101. fullWidth
  102. {...register("code")}
  103. id='code'
  104. label="Application / Gazette Code"
  105. defaultValue={searchCriteria.code}
  106. InputLabelProps={{
  107. shrink: true
  108. }}
  109. />
  110. </Grid>
  111. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  112. <Autocomplete
  113. {...register("issueId")}
  114. disablePortal
  115. id="issueId"
  116. options={issueCombo}
  117. value={issueSelected}
  118. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  119. getOptionLabel={(option) => getIssueLabel(option)}
  120. onChange={(event, newValue) => {
  121. setIssueSelected(newValue);
  122. }}
  123. renderInput={(params) => (
  124. <TextField {...params}
  125. label="Gazette Issue"
  126. InputLabelProps={{
  127. shrink: true
  128. }}
  129. />
  130. )}
  131. />
  132. </Grid>
  133. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  134. <Autocomplete
  135. {...register("gazettGroup")}
  136. disablePortal
  137. id="gazettGroup"
  138. options={ComboData.groupTitle}
  139. value={groupSelected}
  140. inputValue={(groupSelected?.label) ? groupSelected?.label : ""}
  141. getOptionLabel={(option) => option.label}
  142. onChange={(event, newValue) => {
  143. setGroupSelected(newValue);
  144. }}
  145. renderInput={(params) => (
  146. <TextField {...params}
  147. label="Gazette Group"
  148. InputLabelProps={{
  149. shrink: true
  150. }}
  151. />
  152. )}
  153. />
  154. </Grid>
  155. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  156. <TextField
  157. fullWidth
  158. {...register("dateFrom")}
  159. id="dateFrom"
  160. type="date"
  161. label="Proof Date (From)"
  162. defaultValue={searchCriteria.dateFrom}
  163. InputProps={{ inputProps: { max: maxDate } }}
  164. onChange={(newValue) => {
  165. setMinDate(DateUtils.dateStr(newValue));
  166. }}
  167. InputLabelProps={{
  168. shrink: true
  169. }}
  170. />
  171. </Grid>
  172. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  173. <TextField
  174. fullWidth
  175. InputLabelProps={{
  176. shrink: true
  177. }}
  178. {...register("dateTo")}
  179. InputProps={{ inputProps: { min: minDate } }}
  180. onChange={(newValue) => {
  181. setMaxDate(DateUtils.dateStr(newValue));
  182. }}
  183. id="dateTo"
  184. type="date"
  185. label="Proof Date(To)"
  186. defaultValue={searchCriteria.dateTo}
  187. />
  188. </Grid>
  189. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  190. <TextField
  191. fullWidth
  192. {...register("contact")}
  193. id="contact"
  194. label="Contact Person"
  195. defaultValue={searchCriteria.contact}
  196. InputLabelProps={{
  197. shrink: true
  198. }}
  199. />
  200. </Grid>
  201. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  202. <Autocomplete
  203. {...register("status")}
  204. disablePortal
  205. id="status"
  206. filterOptions={(options) => options}
  207. options={ComboData.proofStatus}
  208. value={status}
  209. inputValue={status?.label ? status?.label : ""}
  210. onChange={(event, newValue) => {
  211. if (newValue !== null) {
  212. setStatus(newValue);
  213. }
  214. }}
  215. renderInput={(params) => (
  216. <TextField {...params}
  217. label="Status"
  218. />
  219. )}
  220. InputLabelProps={{
  221. shrink: true
  222. }}
  223. />
  224. </Grid>
  225. {
  226. orgCombo ?
  227. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  228. <Autocomplete
  229. {...register("orgId")}
  230. disablePortal={false}
  231. id="orgId"
  232. options={orgCombo}
  233. value={orgSelected}
  234. inputValue={(orgSelected?.label) ? orgSelected?.label : ""}
  235. onChange={(event, newValue) => {
  236. setOrgSelected(newValue);
  237. }}
  238. renderInput={(params) => (
  239. <TextField {...params}
  240. label="Organisation"
  241. InputLabelProps={{
  242. shrink: true
  243. }}
  244. />
  245. )}
  246. />
  247. </Grid>
  248. : <></>
  249. }
  250. </Grid>
  251. {/*last row*/}
  252. <Grid container maxWidth justifyContent="flex-end">
  253. <Grid item sx={{ ml: 3, mr: 3, mb: 3, mt: 3 }}>
  254. <Button
  255. size="large"
  256. variant="contained"
  257. onClick={resetForm}
  258. sx={{
  259. textTransform: 'capitalize',
  260. alignItems: 'end'
  261. }}>
  262. <Typography variant="h5">Clear</Typography>
  263. </Button>
  264. </Grid>
  265. <Grid item sx={{ ml: 3, mr: 3, mb: 3, mt: 3 }}>
  266. <Button
  267. size="large"
  268. variant="contained"
  269. type="submit"
  270. sx={{
  271. textTransform: 'capitalize',
  272. alignItems: 'end'
  273. }}>
  274. <Typography variant="h5">Submit</Typography>
  275. </Button>
  276. </Grid>
  277. </Grid>
  278. </Grid>
  279. </form>
  280. </MainCard>
  281. );
  282. };
  283. export default SearchPublicNoticeForm;