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

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