|
- // 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 * as ComboData from "utils/ComboData";
- // ==============================|| DASHBOARD - DEFAULT ||============================== //
-
-
- const SearchGazetteIssueForm = ({ applySearch, comboData, onGridReady}) => {
- const [selectedYear, setSelectedYear] = React.useState([]);
- // const [defaultYear, setDefaultYear] = React.useState(searchCriteria.year);
- const [comboList, setComboList] = React.useState([]);
- // const [onReady, setOnReady] = React.useState(false);
-
- const {
- // register,
- handleSubmit } = useForm()
-
- const onSubmit = () => {
- if (selectedYear !=null){
- const temp = {
- year: selectedYear.label,
- };
- applySearch(temp);
- }
- };
-
- React.useEffect(() => {
- if (comboData && comboData.length > 0) {
- // console.log(comboData)
- // const labelValue = comboData.find(obj => obj.label === searchCriteria.year);
- // console.log(labelValue)
- if(selectedYear.length == 0){
- setSelectedYear(comboData[0])
- }
- setComboList(comboData)
- // setSelectedYear(searchCriteria.dateFrom)
- }
- }, [comboData]);
-
-
- return (
- <MainCard xs={12} md={12} lg={12}
- border={false}
- content={false}
- >
-
- <form onSubmit={handleSubmit(onSubmit)} >
- <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
- {/*row 1*/}
- <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:1}}>
- <Typography variant="h5" >
- Search
- </Typography>
- </Grid>
- {/*row 2*/}
-
- <Grid container display="flex" alignItems={"center"}>
- <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <Autocomplete
- disablePortal
- id="year-combo"
- value={selectedYear}
- // defaultValue={selectedYear}
- options={comboList}
- // disabled={checkCountry}
- getOptionLabel={(option) => option.label ? option.label : ""}
- onChange={(event, newValue) => {
- setSelectedYear(newValue);
- }}
- sx={{
- "& .MuiInputBase-root": { height: "41px" },
- "#year-combo": { padding: "0px 0px 0px 0px" },
- "& .MuiAutocomplete-endAdornment": { top: "auto" },
- }}
- renderInput={(params) => <TextField {...params} placeholder={""}/>}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}>
- {/* <TextField
- fullWidth
- InputLabelProps={{
- shrink: true
- }}
- {...register("dateTo")}
- InputProps={{ inputProps: { min: minDate } }}
- onChange={(newValue) => {
- setMaxDate(DateUtils.dateValue(newValue));
- }}
- id="dateTo"
- type="date"
- label="To"
- defaultValue={searchCriteria.dateTo}
- /> */}
- </Grid>
-
- {/* <Grid item xs={9} s={6} md={4} lg={3}>
- </Grid> */}
- </Grid>
- <Grid container justifyContent="flex-end" direction="row" alignItems="center" spacing={3}>
- <ThemeProvider theme={PNSPS_BUTTON_THEME}>
- <Grid item sx={{ ml: 3, mb: 3, }} >
- <Button
- variant="contained"
- type="submit"
- disabled={onGridReady}
- >
- Search
- </Button>
- </Grid>
- </ThemeProvider>
- </Grid>
- </Grid>
- </form>
- </MainCard>
- );
- };
-
- export default SearchGazetteIssueForm;
|