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.
 
 

343 line
15 KiB

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