// 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 DateUtils from "utils/DateUtils"; import {PNSPS_BUTTON_THEME} from "themes/buttonConst"; import {ThemeProvider} from "@emotion/react"; import { GeneralConfirmWindow } from "utils/CommonFunction"; import { isGrantedAny } from "auth/utils"; // import * as ComboData from "utils/ComboData"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const SearchHolidayForm = ({ applySearch, comboData, searchCriteria, onGridReady, onDeleteYear, waitDelete }) => { const [selectedYear, setSelectedYear] = React.useState(null); // const [defaultYear, setDefaultYear] = React.useState(searchCriteria.year); const [comboList, setComboList] = React.useState([]); const [isConfirmOpen, setIsConfirmOpen] = React.useState(false); // const [onReady, setOnReady] = React.useState(false); const { // register, handleSubmit } = useForm() const onSubmit = () => { if (selectedYear != null) { const temp = { year: selectedYear.label, }; applySearch(temp); } }; React.useEffect(() => { const nextCombo = Array.isArray(comboData) ? [...comboData] : []; setComboList(nextCombo); if (nextCombo.length === 0) { setSelectedYear(null); return; } const criteriaYear = searchCriteria?.year; const matchedByCriteria = criteriaYear != null ? nextCombo.find((obj) => String(obj.label) === String(criteriaYear)) : null; if (matchedByCriteria) { setSelectedYear(matchedByCriteria); return; } const matchedBySelected = selectedYear ? nextCombo.find((obj) => String(obj.label) === String(selectedYear.label)) : null; setSelectedYear(matchedBySelected || nextCombo[0]); }, [comboData, searchCriteria]); return (
{/*row 1*/} Year {/*row 2*/} option != null && typeof option === "object" && option.label != null ? String(option.label) : "" } isOptionEqualToValue={(option, value) => String(option?.label) === String(value?.label) } onChange={(event, newValue) => { setSelectedYear(newValue); }} sx={{ '& .MuiInputBase-root': { alignItems: 'center' }, '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' }, '& .MuiOutlinedInput-root': { height: 40 } }} renderInput={(params) => } /> {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) ? : null } {/* { setMaxDate(DateUtils.dateValue(newValue)); }} id="dateTo" type="date" label="To" defaultValue={searchCriteria.dateTo} /> */} {/* */}
setIsConfirmOpen(false)} onConfirmClose={() => { setIsConfirmOpen(false); if (selectedYear != null && onDeleteYear) { onDeleteYear(selectedYear.label); } }} />
); }; export default SearchHolidayForm;