// material-uistatus 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 { isORGLoggedIn, } from "utils/Utils"; 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 }) => { const intl = useIntl(); const [type, setType] = React.useState([]); const [status, setStatus] = React.useState(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]); 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"); // const [selectedLabelsString, setSelectedLabelsString] = React.useState(''); const { reset, register, handleSubmit } = useForm() const marginBottom = 2.5; React.useEffect(() => { if(searchCriteria.status!=undefined){ if(localStorage.getItem('userData').creditor){ setStatus(ComboData.publicNoticeStatic_Creditor.find(item => item.type === searchCriteria.status)) }else{ setStatus(ComboData.publicNoticeStatic.find(item => item.type === searchCriteria.status)) } }else{ if(localStorage.getItem('userData').creditor){ setStatus(ComboData.publicNoticeStatic_Creditor[0]) }else{ setStatus(ComboData.publicNoticeStatic[0]) } } }, [searchCriteria]); React.useEffect(() => { setFromDateValue(minDate); }, [minDate]); React.useEffect(() => { setToDateValue(maxDate); }, [maxDate]); const onSubmit = (data) => { data.status = status.type; 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 = { appNo: data.appNo, dateFrom: sentDateFrom, dateTo: sentDateTo, contact: data.contact, careOf: data.careOf?data.careOf:"", status: (data.status === "" || data.status.includes('all')) ? "" : data.status, }; applySearch(temp); }; function resetForm() { setType([]); setStatus(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]); setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14))) setMaxDate(DateUtils.dateValue(new Date())) reset(); } return (
{/*row 1*/} {/*row 2*/} setReceiptFromError(newError)} slotProps={{ field: { readOnly: true, }, // textField: { // helperText: receiptFromErrorMessage, // }, }} format="DD/MM/YYYY" aria-label={intl.formatMessage({id: 'submitDateFrom'})} label={intl.formatMessage({id: 'submitDateFrom'})} 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: 'submitDateTo'})} value={maxDate === null ? null : dayjs(maxDate)} minDate={minDate === null ? null : dayjs(minDate)} onChange={(newValue) => { // console.log(newValue) if(newValue!=null){ setMaxDate(newValue); } }} /> {isORGLoggedIn()? :null } {/* */} options} options={ localStorage.getItem('userData').creditor ? ComboData.publicNoticeStatic_Creditor : ComboData.publicNoticeStatic } value={status} // inputValue={status?.labelCht} getOptionLabel={(option) => intl.formatMessage({id: option.label})} onChange={(event, newValue) => { if(newValue ==null){ setStatus(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]); }else{ setStatus(newValue); } }} renderInput={(params) => ( )} // InputLabelProps={{ // shrink: true // }} /> {/* options} options={ localStorage.getItem('userData').creditor ? ComboData.publicNoticeStatic_Creditor : ComboData.publicNoticeStatic } value={status} // inputValue={status?.labelCht} getOptionLabel={(option) => intl.formatMessage({id: option.label})} onChange={(event, newValue) => { console.log(newValue) const findAllIndex = newValue.findIndex((ele) => { return ele.type === "all" }) if (findAllIndex > -1) { setStatus([newValue[findAllIndex]]); setSelectedLabelsString('all') } else { const selectedLabels = newValue.map(option => option.type); const selectedLabelsString = `${selectedLabels.join(',')}`; setStatus(newValue); console.log(newValue) setSelectedLabelsString(selectedLabelsString); } console.log(selectedLabelsString) console.log(status) }} renderInput={(params) => ( )} // InputLabelProps={{ // shrink: true // }} /> */} {/*last row*/}
); }; export default SearchPublicNoticeForm;