import {
Grid,
Typography,
Stack,
Button,
Dialog, DialogTitle, DialogContent, DialogActions,
} from '@mui/material';
import * as UrlUtils from "utils/ApiPathConst";
import * as React from "react";
import * as HttpUtils from "utils/HttpUtils";
import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
import Loadable from 'components/Loadable';
const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
import MainCard from 'components/MainCard';
const ExportForm = Loadable(React.lazy(() => import('./ExportForm')));
const SearchForm = Loadable(React.lazy(() => import('./SearchForm')));
const GazetteIssueTable = Loadable(React.lazy(() => import('./DataGrid')));
const BackgroundHead = {
backgroundImage: `url(${titleBackgroundImg})`,
width: '100%',
height: '100%',
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
backgroundColor: '#0C489E',
backgroundPosition: 'right'
};
import { PNSPS_LONG_BUTTON_THEME } from "themes/buttonConst";
import { ThemeProvider } from "@emotion/react";
import { dateStr_Year } from "utils/DateUtils";
import { notifySaveSuccess } from 'utils/CommonFunction';
import { isGrantedAny } from "auth/utils";
// ==============================|| DASHBOARD - DEFAULT ||============================== //
const Index = () => {
const [comboData, setComboData] = React.useState([]);
const [holidayComboData, setHolidayComboData] = React.useState([]);
const [onReady, setOnReady] = React.useState(false);
const [onGridReady, setGridOnReady] = React.useState(false);
const [onSearchReady, setOnSearchReady] = React.useState(false);
const [onExportReady, setOnExportReady] = React.useState(false);
const [searchCriteria, setSearchCriteria] = React.useState({
year: dateStr_Year(new Date()),
});
const [exportCriteria, setExportCriteria] = React.useState({});
const [attachments, setAttachments] = React.useState([]);
const [waitImport, setWaitImport] = React.useState(false);
const [waitDownload, setWaitDownload] = React.useState(false);
const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
const [warningText, setWarningText] = React.useState("");
React.useEffect(() => {
setOnSearchReady(false);
loadCombo();
}, [searchCriteria]);
function loadCombo() {
HttpUtils.get({
url: UrlUtils.GET_ISSUE_YEAR_COMBO,
onSuccess: (responseData) => {
let combo = responseData;
setComboData(combo);
setOnSearchReady(true);
loadHolidayCombo(true);
}
});
}
function loadHolidayCombo() {
HttpUtils.get({
url: UrlUtils.GET_HOLIDAY_COMBO,
onSuccess: (responseData) => {
let combo = responseData;
setHolidayComboData(combo);
setOnExportReady(true);
setOnReady(true);
}
});
}
function applySearch(input) {
setGridOnReady(true);
setSearchCriteria(input);
}
function applyExport(input) {
setExportCriteria(input);
}
function applyGridOnReady(input) {
setGridOnReady(input);
}
React.useEffect(() => {
if (Object.keys(exportCriteria).length > 0) {
doExport();
}
}, [exportCriteria]);
React.useEffect(() => {
if (attachments.length > 0) {
importHoliday();
}
}, [attachments]);
const readFile = (event) => {
let file = event.target.files[0];
if (file) {
if (!file.name.toLowerCase().endsWith(".xlsx")) {
setWarningText("Please upload a valid file (File format: .xlsx).");
setIsWarningPopUp(true);
event.target.value = "";
return;
}
file['id'] = attachments.length;
setAttachments([...attachments, file]);
event.target.value = "";
}
};
const doExport = () => {
setWaitDownload(true);
HttpUtils.fileDownload({
url: UrlUtils.GET_ISSUE_LIST,
params: exportCriteria,
onResponse: () => {
setTimeout(() => setWaitDownload(false), 500);
}
});
};
const importHoliday = () => {
setWaitImport(true);
if (!attachments || attachments.length <= 0) {
setWarningText("Please upload file.");
setWaitImport(false);
return;
}
HttpUtils.postWithFiles({
url: UrlUtils.POST_ISSUE_FILE,
files: attachments,
onSuccess: () => {
notifySaveSuccess();
setWaitImport(false);
setAttachments([]);
loadCombo();
}
});
};
return (
!onReady ?
:
(
Gazette Issue
{!onExportReady ?
:
}
{isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) &&
}
{/* Row 1 */}
{/* Row 2 */}
{!onSearchReady ?
:
}
)
);
};
export default Index;