|
|
@@ -8,6 +8,7 @@ import { |
|
|
import * as UrlUtils from "utils/ApiPathConst"; |
|
|
import * as UrlUtils from "utils/ApiPathConst"; |
|
|
import * as React from "react"; |
|
|
import * as React from "react"; |
|
|
import * as HttpUtils from "utils/HttpUtils"; |
|
|
import * as HttpUtils from "utils/HttpUtils"; |
|
|
|
|
|
import axios from "axios"; |
|
|
|
|
|
|
|
|
import Loadable from 'components/Loadable'; |
|
|
import Loadable from 'components/Loadable'; |
|
|
const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); |
|
|
const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); |
|
|
@@ -29,7 +30,7 @@ const BackgroundHead = { |
|
|
import { PNSPS_LONG_BUTTON_THEME } from "themes/buttonConst"; |
|
|
import { PNSPS_LONG_BUTTON_THEME } from "themes/buttonConst"; |
|
|
import { ThemeProvider } from "@emotion/react"; |
|
|
import { ThemeProvider } from "@emotion/react"; |
|
|
import { dateStr_Year } from "utils/DateUtils"; |
|
|
import { dateStr_Year } from "utils/DateUtils"; |
|
|
import { notifySaveSuccess } from 'utils/CommonFunction'; |
|
|
|
|
|
|
|
|
import { notifyDeleteSuccess, notifySaveSuccess } from 'utils/CommonFunction'; |
|
|
import { isGrantedAny } from "auth/utils"; |
|
|
import { isGrantedAny } from "auth/utils"; |
|
|
import { useIntl } from 'react-intl'; |
|
|
import { useIntl } from 'react-intl'; |
|
|
|
|
|
|
|
|
@@ -49,6 +50,7 @@ const Index = () => { |
|
|
const [attachments, setAttachments] = React.useState([]); |
|
|
const [attachments, setAttachments] = React.useState([]); |
|
|
const [waitImport, setWaitImport] = React.useState(false); |
|
|
const [waitImport, setWaitImport] = React.useState(false); |
|
|
const [waitDownload, setWaitDownload] = React.useState(false); |
|
|
const [waitDownload, setWaitDownload] = React.useState(false); |
|
|
|
|
|
const [waitDelete, setWaitDelete] = React.useState(false); |
|
|
const [isWarningPopUp, setIsWarningPopUp] = React.useState(false); |
|
|
const [isWarningPopUp, setIsWarningPopUp] = React.useState(false); |
|
|
const [warningText, setWarningText] = React.useState(""); |
|
|
const [warningText, setWarningText] = React.useState(""); |
|
|
const fileInputRef = React.useRef(null); |
|
|
const fileInputRef = React.useRef(null); |
|
|
@@ -58,13 +60,17 @@ const Index = () => { |
|
|
loadForm(); |
|
|
loadForm(); |
|
|
}, [searchCriteria]); |
|
|
}, [searchCriteria]); |
|
|
|
|
|
|
|
|
function loadForm() { |
|
|
|
|
|
|
|
|
function loadForm(refreshCombo = false, criteria = null) { |
|
|
|
|
|
const params = criteria || searchCriteria; |
|
|
HttpUtils.get({ |
|
|
HttpUtils.get({ |
|
|
url: UrlUtils.GET_HOLIDAY, |
|
|
url: UrlUtils.GET_HOLIDAY, |
|
|
params: searchCriteria, |
|
|
|
|
|
|
|
|
params, |
|
|
onSuccess: (responseData) => { |
|
|
onSuccess: (responseData) => { |
|
|
setRecord(responseData); |
|
|
setRecord(responseData); |
|
|
if (comboData.length === 0) { |
|
|
|
|
|
|
|
|
if (criteria) { |
|
|
|
|
|
setSearchCriteria(criteria); |
|
|
|
|
|
} |
|
|
|
|
|
if (refreshCombo || comboData.length === 0) { |
|
|
loadCombo(); |
|
|
loadCombo(); |
|
|
} else { |
|
|
} else { |
|
|
setOnSearchReady(true); |
|
|
setOnSearchReady(true); |
|
|
@@ -77,8 +83,7 @@ const Index = () => { |
|
|
HttpUtils.get({ |
|
|
HttpUtils.get({ |
|
|
url: UrlUtils.GET_HOLIDAY_COMBO, |
|
|
url: UrlUtils.GET_HOLIDAY_COMBO, |
|
|
onSuccess: (responseData) => { |
|
|
onSuccess: (responseData) => { |
|
|
let combo = responseData; |
|
|
|
|
|
setComboData(combo); |
|
|
|
|
|
|
|
|
setComboData(Array.isArray(responseData) ? [...responseData] : []); |
|
|
setOnReady(true); |
|
|
setOnReady(true); |
|
|
setOnSearchReady(true); |
|
|
setOnSearchReady(true); |
|
|
} |
|
|
} |
|
|
@@ -94,6 +99,43 @@ const Index = () => { |
|
|
setGridOnReady(input); |
|
|
setGridOnReady(input); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function deleteYear(year) { |
|
|
|
|
|
if (year == null || year === "") { |
|
|
|
|
|
setWarningText("Please select a year."); |
|
|
|
|
|
setIsWarningPopUp(true); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
setWaitDelete(true); |
|
|
|
|
|
setOnSearchReady(false); |
|
|
|
|
|
axios.delete(`${UrlUtils.DELETE_HOLIDAY_YEAR}/${year}`) |
|
|
|
|
|
.then(() => { |
|
|
|
|
|
notifyDeleteSuccess(); |
|
|
|
|
|
HttpUtils.get({ |
|
|
|
|
|
url: UrlUtils.GET_HOLIDAY_COMBO, |
|
|
|
|
|
onSuccess: (responseData) => { |
|
|
|
|
|
const combo = Array.isArray(responseData) ? [...responseData] : []; |
|
|
|
|
|
setComboData(combo); |
|
|
|
|
|
setWaitDelete(false); |
|
|
|
|
|
const nextYear = combo.length > 0 ? combo[0].label : year; |
|
|
|
|
|
applySearch({ year: nextYear }); |
|
|
|
|
|
}, |
|
|
|
|
|
onError: () => { |
|
|
|
|
|
setComboData([]); |
|
|
|
|
|
setWaitDelete(false); |
|
|
|
|
|
applySearch({ year }); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
const msg = error?.response?.data?.error |
|
|
|
|
|
|| "Delete failed. Please try again."; |
|
|
|
|
|
setWarningText(msg); |
|
|
|
|
|
setIsWarningPopUp(true); |
|
|
|
|
|
setWaitDelete(false); |
|
|
|
|
|
setOnSearchReady(true); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
React.useEffect(() => { |
|
|
if (attachments.length > 0) { |
|
|
if (attachments.length > 0) { |
|
|
importHoliday(); |
|
|
importHoliday(); |
|
|
@@ -132,7 +174,9 @@ const Index = () => { |
|
|
setOnSearchReady(false); |
|
|
setOnSearchReady(false); |
|
|
if (!attachments || attachments.length <= 0) { |
|
|
if (!attachments || attachments.length <= 0) { |
|
|
setWarningText("Please upload file."); |
|
|
setWarningText("Please upload file."); |
|
|
|
|
|
setIsWarningPopUp(true); |
|
|
setWaitImport(false); |
|
|
setWaitImport(false); |
|
|
|
|
|
setOnSearchReady(true); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
HttpUtils.postWithFiles({ |
|
|
HttpUtils.postWithFiles({ |
|
|
@@ -142,7 +186,16 @@ const Index = () => { |
|
|
notifySaveSuccess(); |
|
|
notifySaveSuccess(); |
|
|
setWaitImport(false); |
|
|
setWaitImport(false); |
|
|
setAttachments([]); |
|
|
setAttachments([]); |
|
|
loadForm(); |
|
|
|
|
|
|
|
|
loadForm(true); |
|
|
|
|
|
}, |
|
|
|
|
|
onError: (error) => { |
|
|
|
|
|
const msg = error?.response?.data?.error |
|
|
|
|
|
|| "Import failed. Please try again."; |
|
|
|
|
|
setWarningText(msg); |
|
|
|
|
|
setIsWarningPopUp(true); |
|
|
|
|
|
setWaitImport(false); |
|
|
|
|
|
setAttachments([]); |
|
|
|
|
|
setOnSearchReady(true); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
@@ -226,6 +279,8 @@ const Index = () => { |
|
|
searchCriteria={searchCriteria} |
|
|
searchCriteria={searchCriteria} |
|
|
comboData={comboData} |
|
|
comboData={comboData} |
|
|
onGridReady={onGridReady} |
|
|
onGridReady={onGridReady} |
|
|
|
|
|
onDeleteYear={deleteYear} |
|
|
|
|
|
waitDelete={waitDelete} |
|
|
/> |
|
|
/> |
|
|
</Grid> |
|
|
</Grid> |
|
|
|
|
|
|
|
|
@@ -255,7 +310,7 @@ const Index = () => { |
|
|
> |
|
|
> |
|
|
<DialogTitle><Typography variant="h3">Warning</Typography></DialogTitle> |
|
|
<DialogTitle><Typography variant="h3">Warning</Typography></DialogTitle> |
|
|
<DialogContent style={{ display: 'flex' }}> |
|
|
<DialogContent style={{ display: 'flex' }}> |
|
|
<Typography variant="h4" style={{ padding: '16px' }}>{warningText}</Typography> |
|
|
|
|
|
|
|
|
<Typography variant="h4" style={{ padding: '16px', whiteSpace: 'pre-line' }}>{warningText}</Typography> |
|
|
</DialogContent> |
|
|
</DialogContent> |
|
|
<DialogActions> |
|
|
<DialogActions> |
|
|
<Button onClick={() => setIsWarningPopUp(false)}><Typography variant="h5">OK</Typography></Button> |
|
|
<Button onClick={() => setIsWarningPopUp(false)}><Typography variant="h5">OK</Typography></Button> |
|
|
|