// material-ui import { Button, Autocomplete, Grid, TextField, Typography } from '@mui/material'; import MainCard from "../../../components/MainCard"; import {useForm} from "react-hook-form"; import { useState, useEffect} from "react"; import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst"; import {ThemeProvider} from "@emotion/react"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const UserSearchForm_Organization = ({applySearch, orgComboData, onGridReady, searchCriteria}) => { const [type, setType] = useState([]); const [accountFilter, setAccountFilter] = useState("All"); const [orgCombo, setOrgCombo] = useState(); const [orgSelected, setOrgSelected] = useState({}); const { reset, register, handleSubmit } = useForm() useEffect(() => { if(searchCriteria.accountFilter!=undefined){ if(searchCriteria.accountFilter === ""){ setAccountFilter("All") }else{ setAccountFilter(searchCriteria.accountFilter) } }else{ setAccountFilter("All") } }, [searchCriteria]); const onSubmit = (data) => { let typeArray = []; for(let i =0; i < type.length; i++){ typeArray.push(type[i].label); } const temp = { username: data.userName, fullenName: data.fullenName, email: data.email, contactTel: data.phone, contactPerson: data.contactPerson, brNoStr: data.brNoStr, orgName: orgSelected?.name ? orgSelected?.name : "", accountFilter: accountFilter=="All"?null:accountFilter, }; applySearch(temp); }; useEffect(() => { if (orgComboData && orgComboData.length > 0) { setOrgCombo(orgComboData); if(searchCriteria.orgName!=undefined){ setOrgSelected(orgComboData.find(item => item.name === searchCriteria.orgName)) } } }, [orgComboData]); function resetForm(){ setType([]); setAccountFilter("All"); setOrgSelected({}); reset({ userName:"", fullenName:"", email:"", phone:"", contactPerson:"", brNoStr:"", }); } return (
{/*row 1*/} Search {/*row 2*/} { orgCombo ? option.groupType} size="small" value={orgSelected} getOptionLabel={(option) => option.name? option.name : ""} inputValue={orgSelected ? orgSelected.name!=undefined?orgSelected.name:"" : ""} onChange={(event, newValue) => { if (newValue !== null) { setOrgSelected(newValue); }else{ setOrgSelected({}); } }} renderInput={(params) => ( )} renderGroup={(params) => ( {params.group} {params.children} )} /> : <> } { if (newValue !== null){ setAccountFilter(newValue); }else{ setAccountFilter("All"); } }} renderInput={(params) => ( )} /> {/**/} {/* */} {/**/} {/*last row*/}
); }; export default UserSearchForm_Organization;