diff --git a/src/pages/GazetteIssue/ExportForm.js b/src/pages/GazetteIssue/ExportForm.js index 04207eb..817b66b 100644 --- a/src/pages/GazetteIssue/ExportForm.js +++ b/src/pages/GazetteIssue/ExportForm.js @@ -67,8 +67,8 @@ const SearchGazetteIssueForm = ({ applyExport, comboData, waitDownload}) => { {/*row 2*/} - - + + { /> - - {/* { - setMaxDate(DateUtils.dateValue(newValue)); - }} - id="dateTo" - type="date" - label="To" - defaultValue={searchCriteria.dateTo} - /> */} - - - {/* - */} - - - + + + {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) ? + + + + + + : null + } + + setIsConfirmOpen(false)} + onConfirmClose={() => { + setIsConfirmOpen(false); + if (selectedYear != null && onDeleteYear) { + onDeleteYear(selectedYear.label); + } + }} + /> ); }; diff --git a/src/pages/GazetteIssue/index.js b/src/pages/GazetteIssue/index.js index 3138bc4..f4ee22c 100644 --- a/src/pages/GazetteIssue/index.js +++ b/src/pages/GazetteIssue/index.js @@ -8,6 +8,7 @@ import { import * as UrlUtils from "utils/ApiPathConst"; import * as React from "react"; import * as HttpUtils from "utils/HttpUtils"; +import axios from "axios"; import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png' import Loadable from 'components/Loadable'; const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); @@ -26,10 +27,10 @@ const BackgroundHead = { backgroundColor: '#0C489E', backgroundPosition: 'right' }; -import { PNSPS_LONG_BUTTON_THEME } from "themes/buttonConst"; +import { PNSPS_BUTTON_THEME } from "themes/buttonConst"; import { ThemeProvider } from "@emotion/react"; import { dateStr_Year } from "utils/DateUtils"; -import { notifySaveSuccess } from 'utils/CommonFunction'; +import { notifyDeleteSuccess, notifySaveSuccess } from 'utils/CommonFunction'; import { isGrantedAny } from "auth/utils"; import { useIntl } from 'react-intl'; @@ -50,6 +51,7 @@ const Index = () => { const [attachments, setAttachments] = React.useState([]); const [waitImport, setWaitImport] = React.useState(false); const [waitDownload, setWaitDownload] = React.useState(false); + const [waitDelete, setWaitDelete] = React.useState(false); const [isWarningPopUp, setIsWarningPopUp] = React.useState(false); const [warningText, setWarningText] = React.useState(""); const fileInputRef = React.useRef(null); @@ -96,6 +98,43 @@ const Index = () => { 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_ISSUE_YEAR}/${year}`) + .then(() => { + notifyDeleteSuccess(); + HttpUtils.get({ + url: UrlUtils.GET_ISSUE_YEAR_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(() => { if (Object.keys(exportCriteria).length > 0) { doExport(); @@ -138,6 +177,7 @@ const Index = () => { setWaitImport(true); if (!attachments || attachments.length <= 0) { setWarningText("Please upload file."); + setIsWarningPopUp(true); setWaitImport(false); return; } @@ -149,6 +189,14 @@ const Index = () => { setWaitImport(false); setAttachments([]); loadCombo(); + }, + onError: (error) => { + const msg = error?.response?.data?.error + || "Import failed. Please try again."; + setWarningText(msg); + setIsWarningPopUp(true); + setWaitImport(false); + setAttachments([]); } }); }; @@ -185,10 +233,9 @@ const Index = () => { {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) && - + { @@ -260,7 +310,7 @@ const Index = () => { Warning - {warningText} + {warningText} + + + {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) ? - + - - diff --git a/src/pages/Holiday/index.js b/src/pages/Holiday/index.js index 2ae0a16..eba8318 100644 --- a/src/pages/Holiday/index.js +++ b/src/pages/Holiday/index.js @@ -27,7 +27,7 @@ const BackgroundHead = { backgroundPosition: 'right' }; -import { PNSPS_LONG_BUTTON_THEME } from "themes/buttonConst"; +import { PNSPS_BUTTON_THEME } from "themes/buttonConst"; import { ThemeProvider } from "@emotion/react"; import { dateStr_Year } from "utils/DateUtils"; import { notifyDeleteSuccess, notifySaveSuccess } from 'utils/CommonFunction'; @@ -221,22 +221,20 @@ const Index = () => { - + {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) ? - + { } }} > - Upload Files + Upload File