| @@ -67,8 +67,8 @@ const SearchGazetteIssueForm = ({ applyExport, comboData, waitDownload}) => { | |||
| </Grid> | |||
| {/*row 2*/} | |||
| <Grid container display="flex" alignItems={"center"}> | |||
| <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}> | |||
| <Grid container display="flex" alignItems={"center"} sx={{ mb: 1 }}> | |||
| <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3 }}> | |||
| <Autocomplete | |||
| disablePortal | |||
| id="year-combo" | |||
| @@ -93,34 +93,11 @@ const SearchGazetteIssueForm = ({ applyExport, comboData, waitDownload}) => { | |||
| /> | |||
| </Grid> | |||
| <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}> | |||
| {/* <TextField | |||
| fullWidth | |||
| InputLabelProps={{ | |||
| shrink: true | |||
| }} | |||
| {...register("dateTo")} | |||
| InputProps={{ inputProps: { min: minDate } }} | |||
| onChange={(newValue) => { | |||
| setMaxDate(DateUtils.dateValue(newValue)); | |||
| }} | |||
| id="dateTo" | |||
| type="date" | |||
| label="To" | |||
| defaultValue={searchCriteria.dateTo} | |||
| /> */} | |||
| </Grid> | |||
| {/* <Grid item xs={9} s={6} md={4} lg={3}> | |||
| </Grid> */} | |||
| </Grid> | |||
| <Grid container justifyContent="center" direction="row" alignItems="center" spacing={3}> | |||
| <ThemeProvider theme={PNSPS_BUTTON_THEME}> | |||
| <Grid item sx={{ ml: 3, mb: 3, }} > | |||
| <Grid item sx={{ mr: 3 }}> | |||
| <Button | |||
| variant="contained" | |||
| type="submit" | |||
| size="large" | |||
| disabled={waitDownload} | |||
| > | |||
| Export | |||
| @@ -12,14 +12,17 @@ import * as React from "react"; | |||
| // import * as DateUtils from "utils/DateUtils"; | |||
| import {PNSPS_BUTTON_THEME} from "themes/buttonConst"; | |||
| import {ThemeProvider} from "@emotion/react"; | |||
| import { GeneralConfirmWindow } from "utils/CommonFunction"; | |||
| import { isGrantedAny } from "auth/utils"; | |||
| // import * as ComboData from "utils/ComboData"; | |||
| // ==============================|| DASHBOARD - DEFAULT ||============================== // | |||
| const SearchGazetteIssueForm = ({ applySearch, comboData, onGridReady}) => { | |||
| const [selectedYear, setSelectedYear] = React.useState([]); | |||
| const SearchGazetteIssueForm = ({ applySearch, comboData, searchCriteria, onGridReady, onDeleteYear, waitDelete }) => { | |||
| const [selectedYear, setSelectedYear] = React.useState(null); | |||
| // const [defaultYear, setDefaultYear] = React.useState(searchCriteria.year); | |||
| const [comboList, setComboList] = React.useState([]); | |||
| const [isConfirmOpen, setIsConfirmOpen] = React.useState(false); | |||
| // const [onReady, setOnReady] = React.useState(false); | |||
| const { | |||
| @@ -27,7 +30,7 @@ const SearchGazetteIssueForm = ({ applySearch, comboData, onGridReady}) => { | |||
| handleSubmit } = useForm() | |||
| const onSubmit = () => { | |||
| if (selectedYear !=null){ | |||
| if (selectedYear != null) { | |||
| const temp = { | |||
| year: selectedYear.label, | |||
| }; | |||
| @@ -36,17 +39,28 @@ const SearchGazetteIssueForm = ({ applySearch, comboData, onGridReady}) => { | |||
| }; | |||
| 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) | |||
| const nextCombo = Array.isArray(comboData) ? [...comboData] : []; | |||
| setComboList(nextCombo); | |||
| if (nextCombo.length === 0) { | |||
| setSelectedYear(null); | |||
| return; | |||
| } | |||
| const criteriaYear = searchCriteria?.year; | |||
| const matchedByCriteria = criteriaYear != null | |||
| ? nextCombo.find((obj) => String(obj.label) === String(criteriaYear)) | |||
| : null; | |||
| if (matchedByCriteria) { | |||
| setSelectedYear(matchedByCriteria); | |||
| return; | |||
| } | |||
| }, [comboData]); | |||
| const matchedBySelected = selectedYear | |||
| ? nextCombo.find((obj) => String(obj.label) === String(selectedYear.label)) | |||
| : null; | |||
| setSelectedYear(matchedBySelected || nextCombo[0]); | |||
| }, [comboData, searchCriteria]); | |||
| return ( | |||
| @@ -65,8 +79,8 @@ const SearchGazetteIssueForm = ({ applySearch, comboData, onGridReady}) => { | |||
| </Grid> | |||
| {/*row 2*/} | |||
| <Grid container display="flex" alignItems={"center"}> | |||
| <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}> | |||
| <Grid container display="flex" alignItems={"center"} sx={{ mb: 1 }}> | |||
| <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3 }}> | |||
| <Autocomplete | |||
| disablePortal | |||
| id="year-combo" | |||
| @@ -79,6 +93,9 @@ const SearchGazetteIssueForm = ({ applySearch, comboData, onGridReady}) => { | |||
| ? String(option.label) | |||
| : "" | |||
| } | |||
| isOptionEqualToValue={(option, value) => | |||
| String(option?.label) === String(value?.label) | |||
| } | |||
| onChange={(event, newValue) => { | |||
| setSelectedYear(newValue); | |||
| }} | |||
| @@ -91,30 +108,8 @@ const SearchGazetteIssueForm = ({ applySearch, comboData, onGridReady}) => { | |||
| /> | |||
| </Grid> | |||
| <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}> | |||
| {/* <TextField | |||
| fullWidth | |||
| InputLabelProps={{ | |||
| shrink: true | |||
| }} | |||
| {...register("dateTo")} | |||
| InputProps={{ inputProps: { min: minDate } }} | |||
| onChange={(newValue) => { | |||
| setMaxDate(DateUtils.dateValue(newValue)); | |||
| }} | |||
| id="dateTo" | |||
| type="date" | |||
| label="To" | |||
| defaultValue={searchCriteria.dateTo} | |||
| /> */} | |||
| </Grid> | |||
| {/* <Grid item xs={9} s={6} md={4} lg={3}> | |||
| </Grid> */} | |||
| </Grid> | |||
| <Grid container justifyContent="flex-end" direction="row" alignItems="center" spacing={3}> | |||
| <ThemeProvider theme={PNSPS_BUTTON_THEME}> | |||
| <Grid item sx={{ ml: 3, mb: 3, }} > | |||
| <Grid item sx={{ mr: 3 }}> | |||
| <Button | |||
| variant="contained" | |||
| type="submit" | |||
| @@ -124,9 +119,40 @@ const SearchGazetteIssueForm = ({ applySearch, comboData, onGridReady}) => { | |||
| </Button> | |||
| </Grid> | |||
| </ThemeProvider> | |||
| {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) ? | |||
| <ThemeProvider theme={PNSPS_BUTTON_THEME}> | |||
| <Grid item sx={{ mr: 3 }}> | |||
| <Button | |||
| color="delete" | |||
| variant="contained" | |||
| disabled={!selectedYear || waitDelete || onGridReady} | |||
| onClick={() => setIsConfirmOpen(true)} | |||
| > | |||
| Delete | |||
| </Button> | |||
| </Grid> | |||
| </ThemeProvider> | |||
| : null | |||
| } | |||
| </Grid> | |||
| </Grid> | |||
| </form> | |||
| <GeneralConfirmWindow | |||
| isWindowOpen={isConfirmOpen} | |||
| title="Confirm Delete" | |||
| content={selectedYear | |||
| ? `Confirm to delete all gazette issues of year ${selectedYear.label}?` | |||
| : "Confirm to delete all gazette issues of the selected year?"} | |||
| onNormalClose={() => setIsConfirmOpen(false)} | |||
| onConfirmClose={() => { | |||
| setIsConfirmOpen(false); | |||
| if (selectedYear != null && onDeleteYear) { | |||
| onDeleteYear(selectedYear.label); | |||
| } | |||
| }} | |||
| /> | |||
| </MainCard> | |||
| ); | |||
| }; | |||
| @@ -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"]) && | |||
| <Grid item xs={12} md={12} lg={6} width="100%"> | |||
| <Stack direction="row" justifyContent="flex-start" alignItems="center" spacing={2} sx={{ ml: 2, mt: 1 }}> | |||
| <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}> | |||
| <ThemeProvider theme={PNSPS_BUTTON_THEME}> | |||
| <Button | |||
| variant="contained" | |||
| size="large" | |||
| disabled={waitImport} | |||
| type="button" | |||
| onClick={() => { | |||
| @@ -205,7 +252,7 @@ const Index = () => { | |||
| } | |||
| }} | |||
| > | |||
| <Typography variant="h5">Upload Files</Typography> | |||
| Upload Gazette Issue | |||
| </Button> | |||
| <input | |||
| id="uploadFileBtn" | |||
| @@ -227,8 +274,11 @@ const Index = () => { | |||
| <Grid item xs={12} md={12} lg={12} width="100%"> | |||
| <SearchForm | |||
| applySearch={applySearch} | |||
| searchCriteria={searchCriteria} | |||
| comboData={comboData} | |||
| onGridReady={onGridReady} | |||
| onDeleteYear={deleteYear} | |||
| waitDelete={waitDelete} | |||
| /> | |||
| </Grid> | |||
| @@ -260,7 +310,7 @@ const Index = () => { | |||
| <Typography variant="h3">Warning</Typography> | |||
| </DialogTitle> | |||
| <DialogContent style={{ display: 'flex' }}> | |||
| <Typography variant="h4" style={{ padding: '16px' }}>{warningText}</Typography> | |||
| <Typography variant="h4" style={{ padding: '16px', whiteSpace: 'pre-line' }}>{warningText}</Typography> | |||
| </DialogContent> | |||
| <DialogActions> | |||
| <Button onClick={() => setIsWarningPopUp(false)}> | |||
| @@ -79,8 +79,8 @@ const SearchHolidayForm = ({ applySearch, comboData, searchCriteria, onGridReady | |||
| </Grid> | |||
| {/*row 2*/} | |||
| <Grid container display="flex" alignItems={"center"}> | |||
| <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}> | |||
| <Grid container display="flex" alignItems={"center"} sx={{ mb: 1 }}> | |||
| <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3 }}> | |||
| <Autocomplete | |||
| disablePortal | |||
| id="year-combo" | |||
| @@ -108,9 +108,21 @@ const SearchHolidayForm = ({ applySearch, comboData, searchCriteria, onGridReady | |||
| /> | |||
| </Grid> | |||
| <ThemeProvider theme={PNSPS_BUTTON_THEME}> | |||
| <Grid item sx={{ mr: 3 }}> | |||
| <Button | |||
| variant="contained" | |||
| type="submit" | |||
| disabled={onGridReady} | |||
| > | |||
| Search | |||
| </Button> | |||
| </Grid> | |||
| </ThemeProvider> | |||
| {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) ? | |||
| <ThemeProvider theme={PNSPS_BUTTON_THEME}> | |||
| <Grid item sx={{ mb: 3, mr: 3 }}> | |||
| <Grid item sx={{ mr: 3 }}> | |||
| <Button | |||
| color="delete" | |||
| variant="contained" | |||
| @@ -123,40 +135,6 @@ const SearchHolidayForm = ({ applySearch, comboData, searchCriteria, onGridReady | |||
| </ThemeProvider> | |||
| : null | |||
| } | |||
| <Grid item xs={9} s={6} md={4} lg={4} sx={{ ml: 3, mr: 3, mb: 3 }}> | |||
| {/* <TextField | |||
| fullWidth | |||
| InputLabelProps={{ | |||
| shrink: true | |||
| }} | |||
| {...register("dateTo")} | |||
| InputProps={{ inputProps: { min: minDate } }} | |||
| onChange={(newValue) => { | |||
| setMaxDate(DateUtils.dateValue(newValue)); | |||
| }} | |||
| id="dateTo" | |||
| type="date" | |||
| label="To" | |||
| defaultValue={searchCriteria.dateTo} | |||
| /> */} | |||
| </Grid> | |||
| {/* <Grid item xs={9} s={6} md={4} lg={3}> | |||
| </Grid> */} | |||
| </Grid> | |||
| <Grid container justifyContent="flex-end" direction="row" alignItems="center" spacing={3}> | |||
| <ThemeProvider theme={PNSPS_BUTTON_THEME}> | |||
| <Grid item sx={{ ml: 3, mb: 3, }} > | |||
| <Button | |||
| variant="contained" | |||
| type="submit" | |||
| disabled={onGridReady} | |||
| > | |||
| Search | |||
| </Button> | |||
| </Grid> | |||
| </ThemeProvider> | |||
| </Grid> | |||
| </Grid> | |||
| </form> | |||
| @@ -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 = () => { | |||
| <Grid item xs={12} md={12} lg={6} width="100%"> | |||
| <Stack direction="row" justifyContent="flex-start" alignItems="center" spacing={2} sx={{ ml: 2, mt: 1 }} > | |||
| <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}> | |||
| <ThemeProvider theme={PNSPS_BUTTON_THEME}> | |||
| <Button | |||
| variant="contained" | |||
| size="large" | |||
| disabled={waitDownload} | |||
| onClick={doExport} | |||
| aria-label={intl.formatMessage({ id: 'ariaExportHolidayTemplate' })} | |||
| > | |||
| <Typography variant="h5">Export</Typography> | |||
| Export | |||
| </Button> | |||
| </ThemeProvider> | |||
| {isGrantedAny(["MAINTAIN_GAZETTE_ISSUE"]) ? | |||
| <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}> | |||
| <ThemeProvider theme={PNSPS_BUTTON_THEME}> | |||
| <Button | |||
| variant="contained" | |||
| size="large" | |||
| disabled={waitImport} | |||
| type="button" | |||
| onClick={() => { | |||
| @@ -253,7 +251,7 @@ const Index = () => { | |||
| } | |||
| }} | |||
| > | |||
| <Typography variant="h5">Upload Files</Typography> | |||
| Upload Holiday | |||
| </Button> | |||
| <input | |||
| id="uploadFileBtn" | |||
| @@ -307,7 +307,7 @@ const FormPanel = ({ formData }) => { | |||
| } | |||
| }} | |||
| > | |||
| <Typography variant="h5">Upload Files</Typography> | |||
| <Typography variant="h5">Upload File</Typography> | |||
| </Button> | |||
| <input | |||
| id="uploadFileBtn" | |||
| @@ -164,6 +164,7 @@ export const GET_ISSUE_LIST = apiPath+'/gazette-issue/export';//GET | |||
| export const POST_ISSUE_FILE = apiPath+'/gazette-issue/import';//POST | |||
| export const GET_ISSUE = apiPath+'/gazette-issue/list'; //GET | |||
| export const GET_ISSUE_YEAR_COMBO = apiPath+'/gazette-issue/combo-year'; //GET | |||
| export const DELETE_ISSUE_YEAR = apiPath+'/gazette-issue/year'; //DELETE /{year} | |||
| export const CHECK_CREATE_PROOF = apiPath+'/proof/check-create';//GET | |||
| export const LIST_PROOF = apiPath+'/proof/list';//GET | |||