// material-ui import { Button, CardContent, Grid, TextField, Autocomplete, Typography } from '@mui/material'; import MainCard from "components/MainCard"; import { useForm } from "react-hook-form"; import * as React from "react"; import * as ComboData from "utils/ComboData"; import * as DateUtils from "utils/DateUtils"; import * as FormatUtils from "utils/FormatUtils"; import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst"; import {ThemeProvider} from "@emotion/react"; import {FormattedMessage, useIntl} from "react-intl"; import {DatePicker} from "@mui/x-date-pickers/DatePicker"; import dayjs from "dayjs"; import {DemoItem} from "@mui/x-date-pickers/internals/demo"; import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider"; import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, onGridReady }) => { const intl = useIntl(); const { locale } = intl; const [type, setType] = React.useState([]); const [status, setStatus] = React.useState(searchCriteria.statusKey!=undefined?ComboData.proofStatusFull[searchCriteria.statusKey]:ComboData.proofStatusFull[0]); const [issueSelected, setIssueSelected] = React.useState({}); const [issueCombo, setIssueCombo] = React.useState([]); const [groupSelected, setGroupSelected] = React.useState(searchCriteria.gazettGroup!=undefined?ComboData.groupTitle.find(item => item.code === searchCriteria.gazettGroup):{}); const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom); const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo); const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy"); const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy"); React.useEffect(() => { setFromDateValue(minDate); }, [minDate]); React.useEffect(() => { setToDateValue(maxDate); }, [maxDate]); const _sx = { padding: "4 2 4 2", boxShadow: 1, border: 1, borderColor: '#DDD', '& .MuiDataGrid-cell': { borderTop: 1, borderBottom: 1, borderColor: "#EEE" }, '& .MuiDataGrid-footerContainer': { border: 1, borderColor: "#EEE" } } const { reset, register, handleSubmit } = useForm() const onSubmit = (data) => { let typeArray = []; let sentDateFrom = ""; let sentDateTo = ""; for (let i = 0; i < type.length; i++) { typeArray.push(type[i].label); } if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") { sentDateFrom = DateUtils.dateValue(fromDateValue) sentDateTo = DateUtils.dateValue(toDateValue) } const temp = { refNo: data.refNo, code: data.code, issueId: issueSelected?.id, gazettGroup: groupSelected?.type, dateFrom: sentDateFrom, dateTo: sentDateTo, statusKey:status?.key, }; if(status?.type && status?.type != 'all'){ if (status?.type == "Confirmed"){ temp["replyed"] = "T"; temp["action"] = true; }else if(status?.type == "Re-proofing"){ temp["replyed"] = "T"; temp["action"] = false; }else if(status?.type == "No Reply"){ temp["replyed"] = "F"; temp["timeOut"] = "T"; }else{ temp["replyed"] = "F"; temp["timeOut"] = "F"; } } applySearch(temp); }; React.useEffect(() => { if (issueComboData && issueComboData.length > 0) { setIssueCombo(issueComboData); if(searchCriteria.issueId!=undefined){ setIssueSelected(issueComboData.find(item => item.id === searchCriteria.issueId)) } } }, [issueComboData]); function resetForm() { setType([]); setStatus(ComboData.proofStatusFull[0]); setIssueSelected({}); setGroupSelected({}); setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14))) setMaxDate(DateUtils.dateValue(new Date())) reset({ refNo:"", code:"", }); localStorage.setItem('searchCriteria',"") } function getIssueLabel(data) { let issueYear = data.issueYear let volume = data.volume; let issueNo = data.issueNo; let issueDate = data.issueDate; if (locale === 'zh-HK') { return issueYear + " 第" + volume + "卷," + " 第" + issueNo + "期," + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日") + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")"; } else if (locale === 'zh-CN') { return issueYear + " 第" + volume + "卷," + " 第" + issueNo + "期," + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日") + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")"; } return issueYear + " Vol. " + FormatUtils.zeroPad(volume, 3) + ", No. " + FormatUtils.zeroPad(issueNo, 2) + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)"); } return (
{/*row 1*/} {/*row 2*/} getIssueLabel(option)} onChange={(event, newValue) => { setIssueSelected(newValue); }} renderInput={(params) => ( )} /> {/* option.labelCht} onChange={(event, newValue) => { setGroupSelected(newValue); }} renderInput={(params) => ( )} /> */} setReceiptFromError(newError)} slotProps={{ field: { readOnly: true, }, // textField: { // helperText: receiptFromErrorMessage, // }, }} format="DD/MM/YYYY" label={intl.formatMessage({id: 'proofDateFrom'})} value={minDate === null ? null : dayjs(minDate)} maxDate={maxDate === null ? null : dayjs(maxDate)} onChange={(newValue) => { // console.log(newValue) if(newValue!=null){ setMinDate(newValue); } }} /> setReceiptFromError(newError)} slotProps={{ field: { readOnly: true, }, // textField: { // helperText: receiptFromErrorMessage, // }, }} format="DD/MM/YYYY" label={intl.formatMessage({id: 'proofDateTo'})} value={maxDate === null ? null : dayjs(maxDate)} minDate={minDate === null ? null : dayjs(minDate)} onChange={(newValue) => { // console.log(newValue) if(newValue!=null){ setMaxDate(newValue); } }} /> {/* */} options} options={ComboData.proofStatusFull} value={status} getOptionLabel={(option) => option.type? intl.formatMessage({ id: option.i18nLabel }) : ""} inputValue={status? intl.formatMessage({ id: status.i18nLabel }) : ""} onChange={(event, newValue) => { if (newValue !== null) { setStatus(newValue); }else{ setStatus(ComboData.proofStatus[0]); } }} renderInput={(params) => ( )} InputLabelProps={{ shrink: true }} /> {/*last row*/}
); }; export default SearchPublicNoticeForm;