|
- // material-ui
- import {
- Button,
- CardContent,
- Grid, TextField,
- Autocomplete
- } 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 { Typography } from '../../../../node_modules/@mui/material/index';
- // ==============================|| DASHBOARD - DEFAULT ||============================== //
-
-
- const SearchPublicNoticeForm = ({ applySearch, orgComboData, searchCriteria, issueComboData
- }) => {
-
- const [type, setType] = React.useState([]);
- const [status, setStatus] = React.useState(ComboData.proofStatus[0]);
- const [orgSelected, setOrgSelected] = React.useState({});
- const [orgCombo, setOrgCombo] = React.useState();
- const [issueSelected, setIssueSelected] = React.useState({});
- const [issueCombo, setIssueCombo] = React.useState([]);
- const [groupSelected, setGroupSelected] = React.useState({});
-
- const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
- const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
-
-
- const { reset, register, handleSubmit } = useForm()
- const onSubmit = (data) => {
-
- let typeArray = [];
-
- for (let i = 0; i < type.length; i++) {
- typeArray.push(type[i].label);
- }
-
- const temp = {
- refNo: data.refNo,
- code: data.code,
- issueId: issueSelected?.id,
- gazettGroup: groupSelected?.type,
- dateFrom: data.dateFrom,
- dateTo: data.dateTo,
- contact: data.contact,
- replyed: (status?.type && status?.type != 'all') ? status?.type : "",
- orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "",
-
- };
- 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(ComboData.proofStatus[0]);
- setOrgSelected({});
- setIssueSelected({});
- setGroupSelected({});
- reset();
- }
-
- function getIssueLabel(data) {
- if (data == {}) return "";
- return data.year
- + " Vol. " + zeroPad(data.volume, 3)
- + ", No. " + zeroPad(data.issueNo, 2)
- + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)");
- }
-
- function zeroPad(num, places) {
- num = num ? num : 0;
- var zero = places - num.toString().length + 1;
- return Array(+(zero > 0 && zero)).join("0") + num;
- }
-
- return (
- <MainCard xs={12} md={12} lg={12}
- border={false}
- content={false}
- sx={{ backgroundColor: 'backgroundColor.default' }}
- >
-
- <form onSubmit={handleSubmit(onSubmit)}>
- <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 3, mb: 3 }} width="98%">
-
- {/*row 1*/}
- <CardContent sx={{ px: 2.5, pt: 3 }}>
- <Grid item justifyContent="space-between" alignItems="center">
- <Typography variant="h5">Search Form</Typography>
- </Grid>
- </CardContent>
-
- {/*row 2*/}
- <Grid container alignItems={"center"}>
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- {...register("refNo")}
- id='refNo'
- label="Proof No."
- defaultValue={searchCriteria.refNo}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- {...register("code")}
- id='code'
- label="Application / Gazette Code"
- defaultValue={searchCriteria.code}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <Autocomplete
- {...register("issueId")}
- disablePortal
- id="issueId"
- options={issueCombo}
- value={issueSelected}
- inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
- getOptionLabel={(option) => getIssueLabel(option)}
- onChange={(event, newValue) => {
- setIssueSelected(newValue);
- }}
- renderInput={(params) => (
- <TextField {...params}
- label="Gazette Issue"
- InputLabelProps={{
- shrink: true
- }}
- />
- )}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <Autocomplete
- {...register("gazettGroup")}
- disablePortal
- id="gazettGroup"
- options={ComboData.groupTitle}
- value={groupSelected}
- inputValue={(groupSelected?.label) ? groupSelected?.label : ""}
- getOptionLabel={(option) => option.label}
- onChange={(event, newValue) => {
- setGroupSelected(newValue);
- }}
- renderInput={(params) => (
- <TextField {...params}
- label="Gazette Group"
- InputLabelProps={{
- shrink: true
- }}
- />
- )}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- {...register("dateFrom")}
- id="dateFrom"
- type="date"
- label="Proof Date (From)"
- defaultValue={searchCriteria.dateFrom}
- InputProps={{ inputProps: { max: maxDate } }}
- onChange={(newValue) => {
- setMinDate(DateUtils.dateStr(newValue));
- }}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- InputLabelProps={{
- shrink: true
- }}
- {...register("dateTo")}
- InputProps={{ inputProps: { min: minDate } }}
- onChange={(newValue) => {
- setMaxDate(DateUtils.dateStr(newValue));
- }}
- id="dateTo"
- type="date"
- label="Proof Date(To)"
- defaultValue={searchCriteria.dateTo}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- {...register("contact")}
- id="contact"
- label="Contact Person"
- defaultValue={searchCriteria.contact}
- InputLabelProps={{
- shrink: true
- }}
- />
-
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <Autocomplete
- {...register("status")}
- disablePortal
- id="status"
- filterOptions={(options) => options}
- options={ComboData.proofStatus}
- value={status}
- inputValue={status?.label ? status?.label : ""}
- onChange={(event, newValue) => {
- if (newValue !== null) {
- setStatus(newValue);
- }
- }}
- renderInput={(params) => (
- <TextField {...params}
- label="Status"
- />
- )}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
- {
- orgCombo ?
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <Autocomplete
- {...register("orgId")}
- disablePortal={false}
- id="orgId"
- options={orgCombo}
- value={orgSelected}
- inputValue={(orgSelected?.label) ? orgSelected?.label : ""}
- onChange={(event, newValue) => {
- setOrgSelected(newValue);
- }}
- renderInput={(params) => (
- <TextField {...params}
- label="Organization"
- InputLabelProps={{
- shrink: true
- }}
- />
- )}
- />
- </Grid>
- : <></>
- }
-
-
- </Grid>
-
-
- {/*last row*/}
- <Grid container maxWidth justifyContent="flex-end">
-
- <Grid item sx={{ ml: 3, mr: 3, mb: 3, mt: 3 }}>
- <Button
- size="large"
- variant="contained"
- onClick={resetForm}
- sx={{
- textTransform: 'capitalize',
- alignItems: 'end'
- }}>
- <Typography variant="h5">Clear</Typography>
- </Button>
- </Grid>
-
- <Grid item sx={{ ml: 3, mr: 3, mb: 3, mt: 3 }}>
- <Button
- size="large"
- variant="contained"
- type="submit"
- sx={{
- textTransform: 'capitalize',
- alignItems: 'end'
- }}>
- <Typography variant="h5">Submit</Typography>
- </Button>
- </Grid>
- </Grid>
- </Grid>
- </form>
- </MainCard>
- );
- };
-
- export default SearchPublicNoticeForm;
|