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.
 
 

446 line
20 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. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  18. import dayjs from "dayjs";
  19. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  20. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  21. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  22. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  23. const SearchPublicNoticeForm = ({ applySearch, orgComboData, searchCriteria, issueComboData, onGridReady
  24. }) => {
  25. const [type, setType] = React.useState([]);
  26. const [status, setStatus] = React.useState(searchCriteria.statusKey!=undefined?ComboData.proofStatus_GLD[searchCriteria.statusKey]:ComboData.proofStatus_GLD[0]);
  27. const [orgSelected, setOrgSelected] = React.useState({});
  28. const [orgCombo, setOrgCombo] = React.useState();
  29. const [issueSelected, setIssueSelected] = React.useState({});
  30. const [issueCombo, setIssueCombo] = React.useState([]);
  31. const [groupSelected, setGroupSelected] = React.useState(searchCriteria.gazettGroup!=undefined?ComboData.groupTitle.find(item => item.code === searchCriteria.gazettGroup):{});
  32. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  33. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  34. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  35. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  36. // React.useEffect(() => {
  37. // if(searchCriteria.status!=undefined){
  38. // if(searchCriteria.status === ""){
  39. // ComboData.proofStatus_GLD[0]
  40. // }else{
  41. // setSelectedStatus(ComboData.proofStatus_GLD.find(item => item.type === searchCriteria.status))
  42. // }
  43. // }else{
  44. // setSelectedStatus(ComboData.proofStatus_GLD[0])
  45. // }
  46. // }, [searchCriteria]);
  47. React.useEffect(() => {
  48. setFromDateValue(minDate);
  49. }, [minDate]);
  50. React.useEffect(() => {
  51. setToDateValue(maxDate);
  52. }, [maxDate]);
  53. const intl = useIntl();
  54. const { locale } = intl;
  55. const marginBottom = 2.5;
  56. const { reset, register, handleSubmit } = useForm()
  57. const onSubmit = (data) => {
  58. let typeArray = [];
  59. let sentDateFrom = "";
  60. let sentDateTo = "";
  61. for (let i = 0; i < type.length; i++) {
  62. typeArray.push(type[i].label);
  63. }
  64. if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") {
  65. sentDateFrom = DateUtils.dateValue(fromDateValue)
  66. sentDateTo = DateUtils.dateValue(toDateValue)
  67. }
  68. const temp = {
  69. refNo: data.refNo,
  70. code: data.code,
  71. issueId: issueSelected?.id,
  72. gazettGroup: groupSelected?.code,
  73. dateFrom: sentDateFrom,
  74. dateTo: sentDateTo,
  75. contact: data.contact,
  76. orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "",
  77. statusKey:status?.key,
  78. };
  79. if(status?.type && status?.type != 'all'){
  80. if (status?.type == "Confirmed"){
  81. temp["replyed"] = "T";
  82. temp["action"] = true;
  83. temp["cancelled"] = false;
  84. }else if(status?.type == "Re-proofing"){
  85. temp["replyed"] = "T";
  86. temp["action"] = false;
  87. temp["cancelled"] = false;
  88. }else if(status?.type == "No Reply"){
  89. temp["replyed"] = "F";
  90. temp["timeOut"] = "T";
  91. temp["cancelled"] = false;
  92. }else if(status?.type == "Cancelled"){
  93. temp["cancelled"] = true;
  94. } else{
  95. temp["replyed"] = "F";
  96. temp["timeOut"] = "F";
  97. temp["cancelled"] = false;
  98. }
  99. }
  100. applySearch(temp);
  101. };
  102. React.useEffect(() => {
  103. if (orgComboData && orgComboData.length > 0) {
  104. setOrgCombo(orgComboData);
  105. if(searchCriteria.orgId!=undefined){
  106. setOrgSelected(orgComboData.find(item => item.key === searchCriteria.orgId))
  107. }
  108. }
  109. }, [orgComboData]);
  110. React.useEffect(() => {
  111. if (issueComboData && issueComboData.length > 0) {
  112. setIssueCombo(issueComboData);
  113. if(searchCriteria.issueId!=undefined){
  114. setIssueSelected(issueComboData.find(item => item.id === searchCriteria.issueId))
  115. }
  116. }
  117. }, [issueComboData]);
  118. function resetForm() {
  119. setType([]);
  120. setStatus(ComboData.proofStatus[0]);
  121. setOrgSelected({});
  122. setIssueSelected({});
  123. setGroupSelected({});
  124. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  125. setMaxDate(DateUtils.dateValue(new Date()))
  126. reset({
  127. refNo:"",
  128. code:"",
  129. contact:""
  130. });
  131. localStorage.setItem('searchCriteria',"")
  132. }
  133. function getIssueLabel(data) {
  134. let issueYear = data.issueYear
  135. let volume = data.volume;
  136. let issueNo = data.issueNo;
  137. let issueDate = data.issueDate;
  138. if (locale === 'zh-HK') {
  139. return issueYear
  140. + " 第" + volume + "卷,"
  141. + " 第" + issueNo + "期,"
  142. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  143. + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")";
  144. } else if (locale === 'zh-CN') {
  145. return issueYear
  146. + " 第" + volume + "卷,"
  147. + " 第" + issueNo + "期,"
  148. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  149. + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")";
  150. }
  151. return issueYear
  152. + " Vol. " + FormatUtils.zeroPad(volume, 3)
  153. + ", No. " + FormatUtils.zeroPad(issueNo, 2)
  154. + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)");
  155. }
  156. return (
  157. <MainCard xs={12} md={12} lg={12}
  158. border={false}
  159. content={false}
  160. sx={{ backgroundColor: '#fff' }}
  161. >
  162. <form onSubmit={handleSubmit(onSubmit)}>
  163. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1 }} width="98%">
  164. {/*row 1*/}
  165. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  166. <Typography variant="pnspsFormHeader" >
  167. Search
  168. </Typography>
  169. </Grid>
  170. {/*row 2*/}
  171. <Grid container alignItems={"center"}>
  172. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  173. <TextField
  174. fullWidth
  175. {...register("refNo")}
  176. id='refNo'
  177. label="Proof No."
  178. defaultValue={searchCriteria.refNo}
  179. InputLabelProps={{
  180. shrink: true
  181. }}
  182. />
  183. </Grid>
  184. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  185. <TextField
  186. fullWidth
  187. {...register("code")}
  188. id='code'
  189. label="Application No. / Gazette Code"
  190. defaultValue={searchCriteria.code}
  191. InputLabelProps={{
  192. shrink: true
  193. }}
  194. />
  195. </Grid>
  196. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  197. <Autocomplete
  198. {...register("issueId")}
  199. disablePortal
  200. size="small"
  201. id="issueId"
  202. options={issueCombo}
  203. value={issueSelected}
  204. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  205. getOptionLabel={(option) => getIssueLabel(option)}
  206. onChange={(event, newValue) => {
  207. setIssueSelected(newValue);
  208. }}
  209. renderInput={(params) => (
  210. <TextField {...params}
  211. label="Gazette Issue No."
  212. InputLabelProps={{
  213. shrink: true
  214. }}
  215. />
  216. )}
  217. />
  218. </Grid>
  219. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  220. <Autocomplete
  221. {...register("gazettGroup")}
  222. disablePortal
  223. size="small"
  224. id="gazettGroup"
  225. options={ComboData.groupTitle}
  226. value={groupSelected}
  227. inputValue={(groupSelected?.label) ? groupSelected?.label : ""}
  228. getOptionLabel={(option) => option.label}
  229. onChange={(event, newValue) => {
  230. setGroupSelected(newValue);
  231. }}
  232. renderInput={(params) => (
  233. <TextField {...params}
  234. label="Gazette Group"
  235. InputLabelProps={{
  236. shrink: true
  237. }}
  238. />
  239. )}
  240. />
  241. </Grid>
  242. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:marginBottom}}>
  243. <Grid container spacing={1}>
  244. <Grid item xs={6}>
  245. <LocalizationProvider dateAdapter={AdapterDayjs}>
  246. <DemoItem components={['DatePicker']}>
  247. <DatePicker
  248. id="dateFrom"
  249. // onError={(newError) => setReceiptFromError(newError)}
  250. slotProps={{
  251. field: { readOnly: true, },
  252. // textField: {
  253. // helperText: receiptFromErrorMessage,
  254. // },
  255. }}
  256. format="DD/MM/YYYY"
  257. label="Proof Issue Date (From)"
  258. value={minDate === null ? null : dayjs(minDate)}
  259. maxDate={maxDate === null ? null : dayjs(maxDate)}
  260. onChange={(newValue) => {
  261. // console.log(newValue)
  262. if(newValue!=null){
  263. setMinDate(newValue);
  264. }
  265. }}
  266. />
  267. </DemoItem >
  268. </LocalizationProvider>
  269. </Grid>
  270. <Grid item xs={6}>
  271. <LocalizationProvider dateAdapter={AdapterDayjs}>
  272. <DemoItem components={['DatePicker']}>
  273. <DatePicker
  274. id="dateTo"
  275. // onError={(newError) => setReceiptFromError(newError)}
  276. slotProps={{
  277. field: { readOnly: true, },
  278. // textField: {
  279. // helperText: receiptFromErrorMessage,
  280. // },
  281. }}
  282. format="DD/MM/YYYY"
  283. label="Proof Issue Date (To)"
  284. value={maxDate === null ? null : dayjs(maxDate)}
  285. minDate={minDate === null ? null : dayjs(minDate)}
  286. onChange={(newValue) => {
  287. // console.log(newValue)
  288. if(newValue!=null){
  289. setMaxDate(newValue);
  290. }
  291. }}
  292. />
  293. </DemoItem >
  294. </LocalizationProvider>
  295. </Grid>
  296. </Grid>
  297. </Grid>
  298. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  299. <TextField
  300. fullWidth
  301. {...register("contact")}
  302. id="contact"
  303. label="Client"
  304. defaultValue={searchCriteria.contact}
  305. InputLabelProps={{
  306. shrink: true
  307. }}
  308. />
  309. </Grid>
  310. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  311. <Autocomplete
  312. {...register("status")}
  313. disablePortal={false}
  314. id="status"
  315. size="small"
  316. filterOptions={(options) => options}
  317. options={ComboData.proofStatus_GLD}
  318. value={status}
  319. getOptionLabel={(option) => option.type? intl.formatMessage({ id: option.i18nLabel }) : ""}
  320. inputValue={status? intl.formatMessage({id: status.i18nLabel}):""}
  321. onChange={(event, newValue) => {
  322. if (newValue !== null) {
  323. setStatus(newValue);
  324. }
  325. }}
  326. renderInput={(params) => (
  327. <TextField {...params}
  328. label="Status"
  329. />
  330. )}
  331. InputLabelProps={{
  332. shrink: true
  333. }}
  334. />
  335. </Grid>
  336. {
  337. orgCombo ?
  338. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  339. <Autocomplete
  340. {...register("orgId")}
  341. disablePortal
  342. id="orgId"
  343. options={orgCombo}
  344. groupBy={(option) => option.groupType}
  345. size="small"
  346. value={orgSelected}
  347. getOptionLabel={(option) => option.name? option.name : ""}
  348. inputValue={orgSelected ? orgSelected.name!=undefined?orgSelected.name:"" : ""}
  349. onChange={(event, newValue) => {
  350. if (newValue !== null) {
  351. setOrgSelected(newValue);
  352. }else{
  353. setOrgSelected({});
  354. }
  355. }}
  356. renderInput={(params) => (
  357. <TextField {...params}
  358. label="Organisation"
  359. InputLabelProps={{
  360. shrink: true
  361. }}
  362. />
  363. )}
  364. renderGroup={(params) => (
  365. <Grid item key={params.key}>
  366. <Typography fontSize={20} fontStyle="italic" p={1}>
  367. {params.group}
  368. </Typography>
  369. {params.children}
  370. </Grid>
  371. )}
  372. />
  373. </Grid>
  374. : <></>
  375. }
  376. </Grid>
  377. {/*last row*/}
  378. <Grid container maxWidth justifyContent="flex-end">
  379. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  380. <Grid item sx={{ ml: 3, mb: 3 }}>
  381. <Button
  382. variant="contained"
  383. color="cancel"
  384. onClick={resetForm}
  385. >
  386. Reset
  387. </Button>
  388. </Grid>
  389. <Grid item sx={{ ml: 3, mb: 3 }}>
  390. <Button
  391. variant="contained"
  392. type="submit"
  393. disabled={onGridReady}
  394. >
  395. Submit
  396. </Button>
  397. </Grid>
  398. </ThemeProvider>
  399. </Grid>
  400. </Grid>
  401. </form>
  402. </MainCard>
  403. );
  404. };
  405. export default SearchPublicNoticeForm;