From 8a873414c6b0a26ed55707f81410fadd34d9eff6 Mon Sep 17 00:00:00 2001 From: Alex Cheung Date: Mon, 30 Jun 2025 02:45:19 +0800 Subject: [PATCH] update download btn disable --- src/components/FileList.js | 10 +++++++++ src/pages/AuditLog/AuditLogSearchForm.js | 21 ++++++++----------- src/pages/DemandNote/Search/DataGrid.js | 10 ++++++++- .../SearchPage/OrganizationSearchForm.js | 11 +++++++++- .../Payment/Details_GLD/PaymentDetails.js | 12 ++++------- .../Payment/Details_Public/PaymentDetails.js | 16 ++++++-------- .../Proof/Reply_GLD/ApplicationDetails.js | 12 +++++++++-- .../Details_GLD/ApplicationDetailCard.js | 12 +++++++++-- .../Details_Public/ApplicationDetailCard.js | 11 +++++++++- 9 files changed, 78 insertions(+), 37 deletions(-) diff --git a/src/components/FileList.js b/src/components/FileList.js index bd142ea..412649f 100644 --- a/src/components/FileList.js +++ b/src/components/FileList.js @@ -19,6 +19,7 @@ export default function FileList({ refType, refId, allowDelete, sx, dateHideable const theme = useTheme(); const isMdOrLg = useMediaQuery(theme.breakpoints.up('md')); const intl = useIntl(); + const [onDownload, setOnDownload] = React.useState(false); React.useEffect(() => { loadData(); @@ -41,10 +42,17 @@ export default function FileList({ refType, refId, allowDelete, sx, dateHideable }; const onDownloadClick = (fileId, skey, filename) => () => { + setOnDownload(true) HttpUtils.fileDownload({ fileId: fileId, skey: skey, filename: filename, + onResponse:()=>{ + setOnDownload(false) + }, + onError:()=>{ + setOnDownload(false) + } }); }; @@ -91,6 +99,7 @@ export default function FileList({ refType, refId, allowDelete, sx, dateHideable className="textPrimary" onClick={onDownloadClick(params.id, params.row.skey, params.row.filename)} color="primary" + disabled={onDownload} />] }, }, @@ -139,6 +148,7 @@ export default function FileList({ refType, refId, allowDelete, sx, dateHideable className="textPrimary" onClick={onDownloadClick(params.id, params.row.skey, params.row.filename)} color="primary" + disabled={onDownload} />] }, }, diff --git a/src/pages/AuditLog/AuditLogSearchForm.js b/src/pages/AuditLog/AuditLogSearchForm.js index 722ed7b..034e861 100644 --- a/src/pages/AuditLog/AuditLogSearchForm.js +++ b/src/pages/AuditLog/AuditLogSearchForm.js @@ -21,8 +21,8 @@ import {ThemeProvider} from "@emotion/react"; import * as DateUtils from "utils/DateUtils"; import * as UrlUtils from "utils/ApiPathConst"; import * as HttpUtils from "utils/HttpUtils"; -import Loadable from 'components/Loadable'; -const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); +// import Loadable from 'components/Loadable'; +// const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); import {DatePicker} from "@mui/x-date-pickers/DatePicker"; import dayjs from "dayjs"; @@ -190,16 +190,13 @@ const AuditLogSearchForm = ({ applySearch, searchCriteria, onGridReady}) => { {isGranted("MAINTAIN_SETTING") ? - {onDownload? - - : - - } + : null } diff --git a/src/pages/DemandNote/Search/DataGrid.js b/src/pages/DemandNote/Search/DataGrid.js index 2ceb8d8..fc2afda 100644 --- a/src/pages/DemandNote/Search/DataGrid.js +++ b/src/pages/DemandNote/Search/DataGrid.js @@ -41,6 +41,7 @@ export default function SearchDemandNote({ applySearch, searchCriteria, applyGri const [_searchCriteria, set_searchCriteria] = useState({}); const [selectedRowItems, setSelectedRowItems] = useState([]); const navigate = useNavigate() + const [onDownload, setOnDownload] = useState(false); useEffect(() => { set_searchCriteria(searchCriteria); @@ -86,10 +87,17 @@ export default function SearchDemandNote({ applySearch, searchCriteria, applyGri } const onDownloadClick = (params) => () => { + setOnDownload(true) HttpUtils.fileDownload({ fileId: params.row.fileId, skey: params.row.skey, filename: params.row.filename, + onResponse:()=>{ + setOnDownload(false) + }, + onError:()=>{ + setOnDownload(false) + } }); }; @@ -282,7 +290,7 @@ export default function SearchDemandNote({ applySearch, searchCriteria, applyGri ), width: 280, renderCell: (params) => { - return ; + return ; }, }, { diff --git a/src/pages/Organization/SearchPage/OrganizationSearchForm.js b/src/pages/Organization/SearchPage/OrganizationSearchForm.js index 32e16bc..5e3f609 100644 --- a/src/pages/Organization/SearchPage/OrganizationSearchForm.js +++ b/src/pages/Organization/SearchPage/OrganizationSearchForm.js @@ -24,6 +24,7 @@ const OrganizationSearchForm = ({ applySearch, onGridReady, searchCriteria }) => const [type, setType] = useState([]); const [creditorSelected, setCreditorSelected] = React.useState(ComboData.CreditorStatus[0]); const { reset, register, handleSubmit } = useForm() + const [onDownload, setOnDownload] = React.useState(false); useEffect(() => { if(searchCriteria.creditor!=undefined){ @@ -65,8 +66,15 @@ const OrganizationSearchForm = ({ applySearch, onGridReady, searchCriteria }) => } const doExport=()=>{ + setOnDownload(true) HttpUtils.fileDownload({ - url: UrlUtils.GET_ORG_EXPORT + url: UrlUtils.GET_ORG_EXPORT, + onResponse:()=>{ + setOnDownload(false) + }, + onError:()=>{ + setOnDownload(false) + } }); } @@ -164,6 +172,7 @@ const OrganizationSearchForm = ({ applySearch, onGridReady, searchCriteria }) => diff --git a/src/pages/Payment/Details_GLD/PaymentDetails.js b/src/pages/Payment/Details_GLD/PaymentDetails.js index 80c979a..0e9f69e 100644 --- a/src/pages/Payment/Details_GLD/PaymentDetails.js +++ b/src/pages/Payment/Details_GLD/PaymentDetails.js @@ -165,14 +165,10 @@ const PaymentDetails = ({ formData,doPrint,onDownload }) => { - {onDownload? - - : - - } + diff --git a/src/pages/Payment/Details_Public/PaymentDetails.js b/src/pages/Payment/Details_Public/PaymentDetails.js index 98cef4a..3dc13e5 100644 --- a/src/pages/Payment/Details_Public/PaymentDetails.js +++ b/src/pages/Payment/Details_Public/PaymentDetails.js @@ -208,16 +208,12 @@ const PaymentDetails = ({ formData,doPrint,onDownload }) => { - {onDownload? - - : - - } + diff --git a/src/pages/Proof/Reply_GLD/ApplicationDetails.js b/src/pages/Proof/Reply_GLD/ApplicationDetails.js index 239d5ff..85b35ef 100644 --- a/src/pages/Proof/Reply_GLD/ApplicationDetails.js +++ b/src/pages/Proof/Reply_GLD/ApplicationDetails.js @@ -34,6 +34,7 @@ const ApplicationDetailCard = ({ const [data, setData] = useState({}); const [cancelPopUp, setCancelPopUp] = useState(false); + const [onDownload, setOnDownload] = useState(false); useEffect(() => { if (formData) { @@ -108,8 +109,15 @@ const ApplicationDetailCard = ({ } const genProof = () => { + setOnDownload(true) HttpUtils.fileDownload({ - url: UrlUtils.GEN_GAZETTE_PROOF + "/" + params.id + url: UrlUtils.GEN_GAZETTE_PROOF + "/" + params.id, + onResponse:()=>{ + setOnDownload(false) + }, + onError:()=>{ + setOnDownload(false) + } }); } @@ -130,7 +138,7 @@ const ApplicationDetailCard = ({ component="span" variant="contained" size="large" - disabled={!showProofBtn} + disabled={!showProofBtn||onDownload} onClick={genProof} > Proof Slip diff --git a/src/pages/PublicNotice/Details_GLD/ApplicationDetailCard.js b/src/pages/PublicNotice/Details_GLD/ApplicationDetailCard.js index b3a2ab1..dfbce06 100644 --- a/src/pages/PublicNotice/Details_GLD/ApplicationDetailCard.js +++ b/src/pages/PublicNotice/Details_GLD/ApplicationDetailCard.js @@ -56,6 +56,7 @@ const ApplicationDetailCard = ( const [warningText, setWarningText] = useState(""); const [remarksPopUp, setRemarksPopUp] = useState(false); + const [onDownload, setOnDownload] = useState(false); useEffect(() => { //if user data from parent are not null @@ -84,12 +85,19 @@ const ApplicationDetailCard = ( } const onDownloadClick = () => () => { + setOnDownload(true) HttpUtils.fileDownload({ fileId: fileDetail?.id, skey: fileDetail?.skey, filename: fileDetail?.filename, + onResponse:()=>{ + setOnDownload(false) + notifyDownloadSuccess() + }, + onError:()=>{ + setOnDownload(false) + } }); - notifyDownloadSuccess() setUploadStatus(true) }; @@ -680,7 +688,7 @@ const ApplicationDetailCard = ( size="small" variant="contained" onClick={onDownloadClick()} - disabled={!fileDetail?.filename} + disabled={!fileDetail?.filename||onDownload} sx={{ textTransform: 'capitalize', alignItems: 'end', diff --git a/src/pages/PublicNotice/Details_Public/ApplicationDetailCard.js b/src/pages/PublicNotice/Details_Public/ApplicationDetailCard.js index 26bb9b5..ae4c712 100644 --- a/src/pages/PublicNotice/Details_Public/ApplicationDetailCard.js +++ b/src/pages/PublicNotice/Details_Public/ApplicationDetailCard.js @@ -61,6 +61,8 @@ const ApplicationDetailCard = ( const [onReady, setOnReady] = useState(false); const [issueNum, setIssueNum] = useState(""); const [issueDate, setIssueDate] = useState(""); + const [onDownload, setOnDownload] = useState(false); + const { register, // getValues } = useForm(); @@ -89,10 +91,17 @@ const ApplicationDetailCard = ( }, [currentApplicationDetailData]); const onDownloadClick = () => () => { + setOnDownload(true) HttpUtils.fileDownload({ fileId: fileDetail?.id, skey: fileDetail?.skey, filename: fileDetail?.filename, + onResponse:()=>{ + setOnDownload(false) + }, + onError:()=>{ + setOnDownload(false) + } }); }; @@ -646,7 +655,7 @@ const ApplicationDetailCard = ( aria-label={intl.formatMessage({ id: 'download' })} title={intl.formatMessage({ id: 'download' })} color="save" - disabled={!fileDetail?.filename} + disabled={!fileDetail?.filename||onDownload} startIcon={} >