// material-ui import { Button, 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 {ThemeProvider} from "@emotion/react"; import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const SearchPublicNoticeForm = ({ applySearch, orgComboData, searchCriteria, issueComboData }) => { const [type, setType] = React.useState([]); // const [status, setStatus] = React.useState({ key: 0, label: 'All', type: 'all' }); const [orgSelected, setOrgSelected] = React.useState({}); const [orgCombo, setOrgCombo] = React.useState(); const [issueSelected, setIssueSelected] = React.useState({}); const [issueCombo, setIssueCombo] = React.useState([]); const [selectedStatus, setSelectedStatus] = React.useState([]); const [selectedLabelsString, setSelectedLabelsString] = React.useState(''); const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom); const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo); const marginBottom = 2.5; const { reset, register, handleSubmit } = useForm() const onSubmit = (data) => { data.status = selectedLabelsString let typeArray = []; for (let i = 0; i < type.length; i++) { typeArray.push(type[i].label); } const temp = { appNo: data.appNo, dateFrom: data.dateFrom, dateTo: data.dateTo, contact: data.contact, status: (data.status === '' || data.status.includes("all")) ? "" : data.status, orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "", issueId: issueSelected?.id, groupNo: data.groupNo, }; applySearch(temp); }; React.useEffect(() => { if (orgComboData && orgComboData.length > 0) { setOrgCombo(orgComboData); } }, [orgComboData]); React.useEffect(() => { if (issueComboData && issueComboData.length > 0) { setIssueCombo(issueComboData); } }, [issueComboData]); function resetForm() { setType([]); // setStatus({ key: 0, label: 'All', type: 'all' }); setOrgSelected({}); setIssueSelected({}); setSelectedStatus([]); reset(); } function getIssueLabel(data) { if (data == {}) return ""; return data.year + " Vol. " + FormatUtils.zeroPad(data.volume, 3) + ", No. " + FormatUtils.zeroPad(data.issueNo, 2) + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)"); } return (
{/*row 1*/} Search Form {/*row 2*/} { setMinDate(DateUtils.dateStr(newValue)); }} InputLabelProps={{ shrink: true }} /> To { setMaxDate(DateUtils.dateStr(newValue)); }} id="dateTo" type="date" //label={"Submit Date(To)"} defaultValue={searchCriteria.dateTo} /> {/* options} options={ComboData.publicNoticeStatic_GLD} value={status} inputValue={status?.label} onChange={(event, newValue) => { if (newValue !== null) { setStatus(newValue); } }} renderInput={(params) => ( )} InputLabelProps={{ shrink: true }} /> */} { const findAllIndex = newValue.findIndex((ele) => { return ele.type === "all" }) if (findAllIndex > -1) { setSelectedStatus([newValue[findAllIndex]]); setSelectedLabelsString('all') } else { const selectedLabels = newValue.map(option => option.type); const selectedLabelsString = `${selectedLabels.join(',')}`; setSelectedStatus(newValue); setSelectedLabelsString(selectedLabelsString); } }} getOptionLabel={(option) => option.label} renderInput={(params) => ( )} /> { orgCombo ? { if (newValue !== null) { setOrgSelected(newValue); } }} renderInput={(params) => ( )} /> : <> } getIssueLabel(option)} onChange={(event, newValue) => { if (newValue !== null) { setIssueSelected(newValue); } }} renderInput={(params) => ( )} /> {/*last row*/}
); }; export default SearchPublicNoticeForm;