diff --git a/src/pages/lionerUserSearchPage/UserSearchForm.js b/src/pages/lionerUserSearchPage/UserSearchForm.js index 5a9ee19..7781635 100644 --- a/src/pages/lionerUserSearchPage/UserSearchForm.js +++ b/src/pages/lionerUserSearchPage/UserSearchForm.js @@ -1,50 +1,45 @@ // material-ui import { Button, - FormControlLabel, - Grid, TextField, - Typography + Grid, + TextField, + Typography, + Dialog, + DialogTitle, + DialogContent, + DialogActions } from '@mui/material'; import MainCard from "../../components/MainCard"; import {useForm} from "react-hook-form"; - import {useEffect, useState} from "react"; import Autocomplete from '@mui/material/Autocomplete'; -import Checkbox from "@mui/material/Checkbox"; import * as React from "react"; +import axios from "axios"; // Added missing import import {apiPath} from "../../auth/utils"; -// import {GET_USER_GROUP_COMBO_LIST} from "../../utils/ApiPathConst"; import {useNavigate} from 'react-router-dom'; import {ThemeProvider} from "@emotion/react"; import {LIONER_BUTTON_THEME} from "../../themes/colorConst"; import {USER_GROUP_COMBO} from "../../utils/ComboConst"; import {CARD_MAX_WIDTH} from "../../themes/themeConst"; -// ==============================|| DASHBOARD - DEFAULT ||============================== // +// ==============================|| USER SEARCH FORM ||============================== // const UserSearchForm = ({applySearch}) => { - - const navigate = useNavigate() - const [type, setType] = useState([]); + const navigate = useNavigate(); const [userGroup, setUserGroup] = useState(null); - const [selectedUserType, setSelectedUserType] = useState(null); - const [userGroupList, setUserGroupList] = useState([]); - const [locked, setLocked] = useState(false); + const [locked] = useState(false); + const [twoFactorEnabled] = useState(false); + + // States for Report Dialog + const [openReportDialog, setOpenReportDialog] = useState(false); + const [reportDates, setReportDates] = useState({ fromDate: '', toDate: '' }); + const { reset, register, handleSubmit } = useForm(); - 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 = { username: data.userName, fullname: data.fullName, - post: data.post, groupId: userGroup !== null ? userGroup.id : null, email: data.email, phone: data.phone, @@ -54,25 +49,35 @@ const UserSearchForm = ({applySearch}) => { applySearch(temp); }; - useEffect(() => { - // axios.get(`${apiPath}${GET_USER_GROUP_COMBO_LIST}`) - // .then((response) => { - // if (response.status === 200) { - // setUserGroupList(response.data.records); - // } - // }) - // .catch(error => { - // console.log(error); - // return false; - // }); + const handleOpenReport = () => setOpenReportDialog(true); + const handleCloseReport = () => { + setOpenReportDialog(false); + setReportDates({ fromDate: '', toDate: '' }); + }; - }, []); + const handleExport = () => { + axios.get(`${apiPath}/client/excel-client-consultant-report`, { + params: reportDates, + responseType: 'blob', + }) + .then((response) => { + const url = window.URL.createObjectURL(new Blob([response.data])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', `Client_Consultant_Report_${reportDates.fromDate}_to_${reportDates.toDate}.xlsx`); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(url); + handleCloseReport(); + }) + .catch(error => { + console.error("Export failed", error); + }); + }; function resetForm(){ - setType([]); setUserGroup(null); - setSelectedUserType(null); - setLocked(false); reset(); } @@ -85,140 +90,111 @@ const UserSearchForm = ({applySearch}) => { content={false} sx={{width:CARD_MAX_WIDTH}} > -
- {/*row 1*/} - - {/*row 2*/} - - Username - - + Username + - - Full Name - - + Full Name + - - User Group - + User Group { - setUserGroup(newValue); - }} + value={userGroup} + options={USER_GROUP_COMBO} + onChange={(event, newValue) => setUserGroup(newValue)} renderInput={(params) => } /> - - Email - - + Email + - - Phone - - + Phone + - - {/* - - Show Locked User Only - - setLocked(event.target.checked)} - name="checked" - color="primary" - size="medium" - /> - */} - - - {/*last row*/} - - + - - + + - - - + + + - + - - - + + {/* Report Criteria Dialog */} + + Export Client Consultant Report + + + + From Date + setReportDates({ ...reportDates, fromDate: e.target.value })} + /> + + + To Date + setReportDates({ ...reportDates, toDate: e.target.value })} + /> + + + + + + + + + + ); }; -export default UserSearchForm; +export default UserSearchForm; \ No newline at end of file