// 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 {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst"; import {ThemeProvider} from "@emotion/react"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const SearchDemandNoteForm = ({ 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 { 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, issueId: issueSelected?.id, orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "", dnNo: data.dnNo, dateFrom: data.dateFrom, dateTo: data.dateTo, status: (data.status === '' || data.status.includes("all")) ? "" : data.status, }; 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({}); reset(); } function getIssueLabel(data) { if (data == {}) return ""; return data.issueYear + " Vol. " + FormatUtils.zeroPad(data.volume, 3) + ", No. " + FormatUtils.zeroPad(data.issueNo, 2) + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)"); } return (
{/*row 1*/} Search {/*row 2*/} getIssueLabel(option)} onChange={(event, newValue) => { if (newValue !== null) { setIssueSelected(newValue); } }} renderInput={(params) => ( )} /> { orgCombo ? { if (newValue !== null) { setOrgSelected(newValue); } }} renderInput={(params) => ( )} /> : <> } { setMinDate(DateUtils.dateStr(newValue)); }} InputLabelProps={{ shrink: true }} /> { setMaxDate(DateUtils.dateStr(newValue)); }} id="dateTo" type="date" label={"Issue Date(To)"} defaultValue={searchCriteria.dateTo} /> { 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) => ( )} /> {/*last row*/}
); }; export default SearchDemandNoteForm;