|
- // material-uisubDivision
- import {
- Button,
- // FormControlLabel,
- Grid,
- TextField,
- Typography
- } from '@mui/material';
- import MainCard from "components/MainCard";
- import { useForm } from "react-hook-form";
-
- import {
- // useEffect,
- // useState
- } from "react";
-
- import * as React from "react";
- // import { useNavigate } from "react-router";
- import {PNSPS_BUTTON_THEME} from "themes/buttonConst";
- import {ThemeProvider} from "@emotion/react";
- import * as DateUtils from "utils/DateUtils";
- import * as UrlUtils from "utils/ApiPathConst";
- import * as HttpUtils from "utils/HttpUtils";
- import Loadable from 'components/Loadable';
-
- const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
-
- // ==============================|| DASHBOARD - DEFAULT ||============================== //
-
-
- const AuditLogSearchForm = ({ applySearch, searchCriteria}) => {
- // const navigate = useNavigate();
-
- const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
- const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
- const [onDownload, setOnDownload] = React.useState(false);
-
- const marginBottom = 2.5;
-
- const { reset, register, handleSubmit } = useForm()
- const onSubmit = (data) => {
-
- const temp = {
- username: data.userName,
- modifiedTo: data.modifiedTo,
- modifiedFrom: data.modifiedFrom,
- };
- applySearch(temp);
- };
-
-
- function resetForm() {
- reset();
- }
-
- function exportExcel() {
- setOnDownload(true)
- HttpUtils.fileDownload({
- url: UrlUtils.AUDIT_LOG_EXPORT,
- onResponse:()=>{
- setOnDownload(false)
- },
- onError:()=>{
- setOnDownload(false)
- }
- });
- }
-
- 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:2.5}}>
- <Typography variant="pnspsFormHeader" >
- Search
- </Typography>
- </Grid>
- {/*row 2*/}
-
- <Grid container display="flex" alignItems={"center"}>
- <Grid item xs={9} md={5} lg={5} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- {...register("userName")}
- id='userName'
- label="Username"
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
- <Grid item xs={9} md={5} lg={5} sx={{ ml: 3, mr: 3, mb: 3 }}></Grid>
-
- <Grid item xs={9} s={6} md={6} lg={6} sx={{ml:3, mr:3, mb:marginBottom}}>
- <Grid container>
- <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
- <TextField
- fullWidth
- {...register("modifiedFrom")}
- id="modifiedFrom"
- type="date"
- label="Modified From"
- defaultValue={searchCriteria.modifiedFrom}
- InputProps={{ inputProps: { max: maxDate } }}
- onChange={(newValue) => {
- setMinDate(DateUtils.dateStr(newValue));
- }}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
- <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:0.8, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
- To
- </Grid>
-
- <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
- <TextField
- fullWidth
- InputLabelProps={{
- shrink: true
- }}
- {...register("modifiedTo")}
- InputProps={{ inputProps: { min: minDate } }}
- onChange={(newValue) => {
- console.log(newValue)
- setMaxDate(DateUtils.dateStr(newValue));
- }}
- id="modifiedTo"
- type="date"
- label="Modified To"
- defaultValue={searchCriteria.modifiedTo}
- />
- </Grid>
- </Grid>
- </Grid>
- </Grid>
-
- {/*last row*/}
- <Grid container direction="row"
- justifyContent="space-between"
- alignItems="center">
- <ThemeProvider theme={PNSPS_BUTTON_THEME}>
- <Grid item xs={12} md={12}>
- <Grid container maxWidth justifyContent="flex-end">
- <Grid item sx={{ ml: 3, mr: 3, mb: 3,}}>
- {onDownload?
- <LoadingComponent disableText={true} alignItems="flex-start"/>
- :
- <Button
- variant="contained"
- onClick={exportExcel}
- >
- Export
- </Button>
- }
- </Grid>
- <Grid item sx={{ ml: 3, mr: 3, mb: 3,}}>
- <Button
- variant="contained"
- color="cancel"
- onClick={resetForm}
- >
- Reset
- </Button>
- </Grid>
- <Grid item sx={{ ml: 3, mb: 3 }}>
- <Button
- variant="contained"
- type="submit"
- >
- Search
- </Button>
- </Grid>
- </Grid>
- </Grid>
- </ThemeProvider>
- </Grid>
- </Grid>
- </form>
- </MainCard>
- );
- };
-
- export default AuditLogSearchForm;
|