From 2d24120894fd187f0b7e61fadc1122b251c4e267 Mon Sep 17 00:00:00 2001 From: Alex Cheung Date: Tue, 20 Feb 2024 18:01:51 +0800 Subject: [PATCH] fix holiday with year selected --- src/layout/MainLayout/Header/index.js | 2 +- src/pages/Holiday/Search_GLD/DataGrid.js | 17 ++--- src/pages/Holiday/Search_GLD/SearchForm.js | 78 +++++++++++++--------- src/pages/Holiday/Search_GLD/index.js | 45 +++++++++---- src/utils/ApiPathConst.js | 3 +- 5 files changed, 90 insertions(+), 55 deletions(-) diff --git a/src/layout/MainLayout/Header/index.js b/src/layout/MainLayout/Header/index.js index 6b107ee..ea6c01e 100644 --- a/src/layout/MainLayout/Header/index.js +++ b/src/layout/MainLayout/Header/index.js @@ -361,7 +361,7 @@ function Header(props) { alignItems="center" spacing={0} > - + { + console.log(recordList) setRows(recordList); }, [recordList]); - // const handleEditClick = (id) => () => { - // navigate('/emailTemplate/' + id); - // }; - const columns = [ { - id: 'holiday_DAY', - field: 'holiday_DAY', + id: 'HOLIDAY_DAY', + field: 'HOLIDAY_DAY', headerName: 'Date', flex: 4, renderCell: (params) => { - let holiday_DAY = params.row.holiday_DAY; - return
{dateStr(holiday_DAY)}
+ let HOLIDAY_DAY = params.row.HOLIDAY_DAY; + return
{dateStr(HOLIDAY_DAY)}
}, }, { - id: 'description', - field: 'description', + id: 'DESCRIPTION', + field: 'DESCRIPTION', headerName: 'Description', flex: 5, }, diff --git a/src/pages/Holiday/Search_GLD/SearchForm.js b/src/pages/Holiday/Search_GLD/SearchForm.js index 693dafd..fcaf358 100644 --- a/src/pages/Holiday/Search_GLD/SearchForm.js +++ b/src/pages/Holiday/Search_GLD/SearchForm.js @@ -3,7 +3,7 @@ import { Button, Grid, TextField, - // Autocomplete, + Autocomplete, Typography } from '@mui/material'; import MainCard from "components/MainCard"; @@ -16,25 +16,38 @@ import {ThemeProvider} from "@emotion/react"; // ==============================|| DASHBOARD - DEFAULT ||============================== // -const SearchPublicNoticeForm = ({ applySearch, searchCriteria }) => { +const SearchPublicNoticeForm = ({ applySearch, comboData}) => { + const [selectedYear, setSelectedYear] = React.useState([]); + // const [defaultYear, setDefaultYear] = React.useState(searchCriteria.year); + const [comboList, setComboList] = React.useState([]); + // const [onReady, setOnReady] = React.useState(false); - // const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom); - const [maxDate] = React.useState(searchCriteria.dateFrom); - // const [status, setStatus] = React.useState(ComboData.paymentStatus[0]); + const { + // register, + handleSubmit } = useForm() - const { register, handleSubmit } = useForm() - - const onSubmit = (data) => { - const temp = { - // code: data.code, - // transNo: data.transNo, - dateFrom: data.dateFrom, - dateTo: data.dateTo, - // status : (status?.type && status?.type != 'all') ? status?.type : "", - }; - applySearch(temp); + 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 ( {
{/*row 1*/} - + - Date + Year {/*row 2*/} - { - // setMinDate(DateUtils.dateStr(newValue)); - // }} - InputLabelProps={{ - shrink: true + 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) => } /> diff --git a/src/pages/Holiday/Search_GLD/index.js b/src/pages/Holiday/Search_GLD/index.js index 37173c5..f650638 100644 --- a/src/pages/Holiday/Search_GLD/index.js +++ b/src/pages/Holiday/Search_GLD/index.js @@ -38,10 +38,11 @@ import { notifySaveSuccess } from 'utils/CommonFunction'; const Index = () => { const [record, setRecord] = React.useState([]); + const [comboData, setComboData] = React.useState([]); const [onReady, setOnReady] = React.useState(false); // const navigate = useNavigate() const [searchCriteria, setSearchCriteria] = React.useState({ - dateFrom: dateStr_Year(new Date()), + year: dateStr_Year(new Date()), // dateFrom: DateUtils.dateStr(new Date().setDate(new Date().getDate()-14)), }); const [attachments, setAttachments] = React.useState([]); @@ -49,20 +50,41 @@ const Index = () => { const [isWarningPopUp, setIsWarningPopUp] = React.useState(false); const [warningText, setWarningText] = React.useState(""); - React.useLayoutEffect(() => { - loadForm(); - }, []); + // React.useLayoutEffect(() => { + // loadForm(); + // }, []); React.useLayoutEffect(() => { - setOnReady(true); - }, [record]); + if (comboData && comboData.length > 0) { + setOnReady(true); + } + }, [comboData]); - const loadForm = () => { + React.useEffect(() => { + // console.log(searchCriteria) + loadForm(); + }, [searchCriteria]); + + function loadForm() { HttpUtils.get({ url: UrlUtils.GET_HOLIDAY, + params: searchCriteria, onSuccess: (responseData) => { - console.log(dateStr_Year(new Date())) + console.log(comboData) setRecord(responseData); + if (comboData.length == 0) { + loadCombo(); + } + } + }); + } + + function loadCombo() { + HttpUtils.get({ + url: UrlUtils.GET_HOLIDAY_COMBO, + onSuccess: (responseData) => { + let combo = responseData; + setComboData(combo); } }); } @@ -72,11 +94,9 @@ const Index = () => { } React.useEffect(() => { - if (!attachments || attachments.length <= 0) { - setAttachments([]); - return; + if (attachments.length > 0) { + importHoliday(); } - importHoliday(); }, [attachments]); const readFile = (event) => { @@ -166,6 +186,7 @@ const Index = () => { applySearch={applySearch} // generateXML={generateXML} searchCriteria={searchCriteria} + comboData={comboData} /> {/*row 2*/} diff --git a/src/utils/ApiPathConst.js b/src/utils/ApiPathConst.js index 040b280..bcd1daf 100644 --- a/src/utils/ApiPathConst.js +++ b/src/utils/ApiPathConst.js @@ -171,4 +171,5 @@ export const GEN_GFMIS_XML = apiPath+'/gfmis'; //GET //Holiday export const GET_HOLIDAY = apiPath+'/holiday/list'; //GET -export const POST_HOLIDAY = apiPath+'/holiday/import'; //POST \ No newline at end of file +export const POST_HOLIDAY = apiPath+'/holiday/import'; //POST +export const GET_HOLIDAY_COMBO = apiPath+'/holiday/combo'; //GET \ No newline at end of file