25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

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