diff --git a/pmp-revamp-ui/src/pages/admin/authenticationServices/AdminApiKeysList.js b/pmp-revamp-ui/src/pages/admin/authenticationServices/AdminApiKeysList.js index 6e3adb69..35e0c061 100644 --- a/pmp-revamp-ui/src/pages/admin/authenticationServices/AdminApiKeysList.js +++ b/pmp-revamp-ui/src/pages/admin/authenticationServices/AdminApiKeysList.js @@ -43,6 +43,8 @@ function AdminApiKeysList () { const [totalRecords, setTotalRecords] = useState(0); const [resetPageNo, setResetPageNo] = useState(false); const [applyFilter, setApplyFilter] = useState(false); + const [initialRender, setInitialRender] = useState(true); + const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false); const [showDeactivatePopup, setShowDeactivatePopup] = useState(false); const [deactivateRequest, setDeactivateRequest] = useState({}); const [filterAttributes, setFilterAttributes] = useState({ @@ -70,55 +72,61 @@ function AdminApiKeysList () { handleMouseClickForDropdown(submenuRef, () => setActionId(-1)); }, [submenuRef]); - useEffect(() => { - const fetch = async () => { - const queryParams = new URLSearchParams(); - queryParams.append('sortFieldName', sortFieldName); - queryParams.append('sortType', sortType); - queryParams.append('pageSize', pageSize); + const fetchApiKeysListData = async () => { + const queryParams = new URLSearchParams(); + queryParams.append('sortFieldName', sortFieldName); + queryParams.append('sortType', sortType); + queryParams.append('pageSize', pageSize); - //reset page number to 0 if filter applied or page number is out of bounds - const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); - queryParams.append('pageNo', effectivePageNo); - setResetPageNo(false); + //reset page number to 0 if filter applied or page number is out of bounds + const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); + queryParams.append('pageNo', effectivePageNo); + setResetPageNo(false); - if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); - if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); - if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName); - if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName); - if (filterAttributes.apiKeyLabel) queryParams.append('apiKeyLabel', filterAttributes.apiKeyLabel); - if (filterAttributes.status) queryParams.append('status', filterAttributes.status); + if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); + if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); + if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName); + if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName); + if (filterAttributes.apiKeyLabel) queryParams.append('apiKeyLabel', filterAttributes.apiKeyLabel); + if (filterAttributes.status) queryParams.append('status', filterAttributes.status); - const url = `${getPartnerManagerUrl('/partners/apikey/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; - try { - fetchData ? setTableDataLoaded(false) : setDataLoaded(false); - const response = await HttpService.get(url); - if (response) { - const responseData = response.data; - if (responseData && responseData.response) { - const resData = responseData.response.data; - setTotalRecords(responseData.response.totalResults); - setApiKeysList(resData); - } else { - handleServiceErrors(responseData, setErrorCode, setErrorMsg); - } + const url = `${getPartnerManagerUrl('/partners/apikey/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; + try { + fetchData ? setTableDataLoaded(false) : setDataLoaded(false); + const response = await HttpService.get(url); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response.data; + setTotalRecords(responseData.response.totalResults); + setApiKeysList(resData); } else { - setErrorMsg(t('apiKeysList.errorInApiKeysList')); + handleServiceErrors(responseData, setErrorCode, setErrorMsg); } - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - setFetchData(false); - } catch (err) { - setFetchData(false); - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - console.error('Error fetching data:', err); - setErrorMsg(err); + } else { + setErrorMsg(t('apiKeysList.errorInApiKeysList')); } + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + setFetchData(false); + } catch (err) { + setFetchData(false); + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + console.error('Error fetching data:', err); + setErrorMsg(err); + } + } + + useEffect(() => { + + if (isApplyFilterClicked || initialRender) { + fetchApiKeysListData(); + setInitialRender(false); + setIsApplyFilterClicked(false); } - fetch(); - }, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]); + }, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]); const onApplyFilter = (updatedfilters) => { - onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes); + onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked); }; const getPaginationValues = (recordsPerPage, pageIndex) => { diff --git a/pmp-revamp-ui/src/pages/admin/authenticationServices/AdminOidcClientsList.js b/pmp-revamp-ui/src/pages/admin/authenticationServices/AdminOidcClientsList.js index df522736..77ad127a 100644 --- a/pmp-revamp-ui/src/pages/admin/authenticationServices/AdminOidcClientsList.js +++ b/pmp-revamp-ui/src/pages/admin/authenticationServices/AdminOidcClientsList.js @@ -48,6 +48,8 @@ function AdminOidcClientsList () { const [totalRecords, setTotalRecords] = useState(0); const [resetPageNo, setResetPageNo] = useState(false); const [applyFilter, setApplyFilter] = useState(false); + const [initialRender, setInitialRender] = useState(true); + const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false); const [showClientIdPopup, setShowClientIdPopup] = useState(false); const [currentClient, setCurrentClient] = useState(null); const [showDeactivatePopup, setShowDeactivatePopup] = useState(false); @@ -78,56 +80,62 @@ function AdminOidcClientsList () { { id: "action", headerNameKey: 'oidcClientsList.action' } ]; - useEffect(() => { - const fetch = async () => { - const queryParams = new URLSearchParams(); - queryParams.append('sortFieldName', sortFieldName); - queryParams.append('sortType', sortType); - queryParams.append('pageSize', pageSize); + const fetchOidcClientsListData = async () => { + const queryParams = new URLSearchParams(); + queryParams.append('sortFieldName', sortFieldName); + queryParams.append('sortType', sortType); + queryParams.append('pageSize', pageSize); - //reset page number to 0 if filter applied or page number is out of bounds - const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); - queryParams.append('pageNo', effectivePageNo); - setResetPageNo(false); + //reset page number to 0 if filter applied or page number is out of bounds + const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); + queryParams.append('pageNo', effectivePageNo); + setResetPageNo(false); - if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); - if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); - if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName); - if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName); - if (filterAttributes.clientNameEng) queryParams.append('clientName', filterAttributes.clientNameEng); - if (filterAttributes.status) queryParams.append('status', filterAttributes.status); + if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); + if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); + if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName); + if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName); + if (filterAttributes.clientNameEng) queryParams.append('clientName', filterAttributes.clientNameEng); + if (filterAttributes.status) queryParams.append('status', filterAttributes.status); - const url = `${getPartnerManagerUrl('/oauth/partners/clients', process.env.NODE_ENV)}?${queryParams.toString()}`; - try { - fetchData ? setTableDataLoaded(false) : setDataLoaded(false); - const response = await HttpService.get(url); - if (response) { - const responseData = response.data; - if (responseData && responseData.response) { - const resData = responseData.response.data; - const populatedData = populateClientNames(resData); - setTotalRecords(responseData.response.totalResults); - setOidcClientsList(populatedData); - } else { - handleServiceErrors(responseData, setErrorCode, setErrorMsg); - } + const url = `${getPartnerManagerUrl('/oauth/partners/clients', process.env.NODE_ENV)}?${queryParams.toString()}`; + try { + fetchData ? setTableDataLoaded(false) : setDataLoaded(false); + const response = await HttpService.get(url); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response.data; + const populatedData = populateClientNames(resData); + setTotalRecords(responseData.response.totalResults); + setOidcClientsList(populatedData); } else { - setErrorMsg(t('oidcClientsList.errorInOidcClientsList')); + handleServiceErrors(responseData, setErrorCode, setErrorMsg); } - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - setFetchData(false); - } catch (err) { - setFetchData(false); - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - console.error('Error fetching data:', err); - setErrorMsg(err); + } else { + setErrorMsg(t('oidcClientsList.errorInOidcClientsList')); } + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + setFetchData(false); + } catch (err) { + setFetchData(false); + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + console.error('Error fetching data:', err); + setErrorMsg(err); + } + } + + useEffect(() => { + + if (isApplyFilterClicked || initialRender) { + fetchOidcClientsListData(); + setInitialRender(false); + setIsApplyFilterClicked(false); } - fetch(); - }, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]); + }, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]); const onApplyFilter = (updatedfilters) => { - onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes); + onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked); }; const getPaginationValues = (recordsPerPage, pageIndex) => { diff --git a/pmp-revamp-ui/src/pages/admin/deviceProviderServices/AdminDevicesList.js b/pmp-revamp-ui/src/pages/admin/deviceProviderServices/AdminDevicesList.js index 8da282b8..b4a7a11e 100644 --- a/pmp-revamp-ui/src/pages/admin/deviceProviderServices/AdminDevicesList.js +++ b/pmp-revamp-ui/src/pages/admin/deviceProviderServices/AdminDevicesList.js @@ -43,6 +43,8 @@ function AdminDevicesList() { const [totalRecords, setTotalRecords] = useState(0); const [resetPageNo, setResetPageNo] = useState(false); const [applyFilter, setApplyFilter] = useState(false); + const [initialRender, setInitialRender] = useState(true); + const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false); const [showDeviceDetailApproveRejectPopup, setShowDeviceDetailApproveRejectPopup] = useState(false); const [deactivateRequest, setDeactivateRequest] = useState({}); const [showDeactivatePopup, setShowDeactivatePopup] = useState(false); @@ -79,59 +81,65 @@ function AdminDevicesList() { handleMouseClickForDropdown(submenuRef, () => setActionId(-1)); }, [submenuRef]); - useEffect(() => { - const fetch = async () => { - const queryParams = new URLSearchParams(); - queryParams.append('sortFieldName', sortFieldName); - queryParams.append('sortType', sortType); - queryParams.append('pageSize', pageSize); + const fetchDeviceDetails = async () => { + const queryParams = new URLSearchParams(); + queryParams.append('sortFieldName', sortFieldName); + queryParams.append('sortType', sortType); + queryParams.append('pageSize', pageSize); - //reset page number to 0 if filter applied or page number is out of bounds - const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); - queryParams.append('pageNo', effectivePageNo); - setResetPageNo(false); + //reset page number to 0 if filter applied or page number is out of bounds + const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); + queryParams.append('pageNo', effectivePageNo); + setResetPageNo(false); - if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); - if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); - if (filterAttributes.make) queryParams.append('make', filterAttributes.make); - if (filterAttributes.model) queryParams.append('model', filterAttributes.model); - if (filterAttributes.status) queryParams.append('status', filterAttributes.status); - if (filterAttributes.deviceType) queryParams.append('deviceType', filterAttributes.deviceType); - if (filterAttributes.deviceSubType) queryParams.append('deviceSubType', filterAttributes.deviceSubType); - if (filterAttributes.deviceId) queryParams.append('deviceId', filterAttributes.deviceId); - if (filterAttributes.sbiId) queryParams.append('sbiId', filterAttributes.sbiId); - if (filterAttributes.sbiVersion) queryParams.append('sbiVersion', filterAttributes.sbiVersion); + if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); + if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); + if (filterAttributes.make) queryParams.append('make', filterAttributes.make); + if (filterAttributes.model) queryParams.append('model', filterAttributes.model); + if (filterAttributes.status) queryParams.append('status', filterAttributes.status); + if (filterAttributes.deviceType) queryParams.append('deviceType', filterAttributes.deviceType); + if (filterAttributes.deviceSubType) queryParams.append('deviceSubType', filterAttributes.deviceSubType); + if (filterAttributes.deviceId) queryParams.append('deviceId', filterAttributes.deviceId); + if (filterAttributes.sbiId) queryParams.append('sbiId', filterAttributes.sbiId); + if (filterAttributes.sbiVersion) queryParams.append('sbiVersion', filterAttributes.sbiVersion); - const url = `${getPartnerManagerUrl('/devicedetail/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; - try { - fetchData ? setTableDataLoaded(false) : setDataLoaded(false); - const response = await HttpService.get(url); - if (response) { - const responseData = response.data; - if (responseData && responseData.response) { - const resData = responseData.response.data; - setTotalRecords(responseData.response.totalResults); - setDevicesList(resData); - } else { - handleServiceErrors(responseData, setErrorCode, setErrorMsg); - } + const url = `${getPartnerManagerUrl('/devicedetail/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; + try { + fetchData ? setTableDataLoaded(false) : setDataLoaded(false); + const response = await HttpService.get(url); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response.data; + setTotalRecords(responseData.response.totalResults); + setDevicesList(resData); } else { - setErrorMsg(t('adminDeviceDetailsList.errorInAdminDeviceDetailsList')); + handleServiceErrors(responseData, setErrorCode, setErrorMsg); } - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - setFetchData(false); - } catch (err) { - setFetchData(false); - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - console.error('Error fetching data:', err); - setErrorMsg(err); + } else { + setErrorMsg(t('adminDeviceDetailsList.errorInAdminDeviceDetailsList')); } + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + setFetchData(false); + } catch (err) { + setFetchData(false); + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + console.error('Error fetching data:', err); + setErrorMsg(err); + } + } + + useEffect(() => { + + if (isApplyFilterClicked || initialRender) { + fetchDeviceDetails(); + setInitialRender(false); + setIsApplyFilterClicked(false); } - fetch(); - }, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]); + }, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]); const onApplyFilter = (filters) => { - onClickApplyFilter(filters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes); + onClickApplyFilter(filters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked); }; const getPaginationValues = (recordsPerPage, pageIndex) => { diff --git a/pmp-revamp-ui/src/pages/admin/deviceProviderServices/AdminSbiList.js b/pmp-revamp-ui/src/pages/admin/deviceProviderServices/AdminSbiList.js index 8bb252e7..48669977 100644 --- a/pmp-revamp-ui/src/pages/admin/deviceProviderServices/AdminSbiList.js +++ b/pmp-revamp-ui/src/pages/admin/deviceProviderServices/AdminSbiList.js @@ -46,6 +46,8 @@ function AdminSbiList() { const [totalRecords, setTotalRecords] = useState(0); const [resetPageNo, setResetPageNo] = useState(false); const [applyFilter, setApplyFilter] = useState(false); + const [initialRender, setInitialRender] = useState(true); + const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false); const [showDeactivatePopup, setShowDeactivatePopup] = useState(false); const [deactivateRequest, setDeactivateRequest] = useState({}); const [filterAttributes, setFilterAttributes] = useState({ @@ -74,54 +76,60 @@ function AdminSbiList() { { id: "action", headerNameKey: "sbiList.action" } ]; - useEffect(() => { - const fetch = async () => { - const queryParams = new URLSearchParams(); - queryParams.append('sortFieldName', sortFieldName); - queryParams.append('sortType', sortType); - queryParams.append('pageSize', pageSize); + const fetchSbiListData = async () => { + const queryParams = new URLSearchParams(); + queryParams.append('sortFieldName', sortFieldName); + queryParams.append('sortType', sortType); + queryParams.append('pageSize', pageSize); - //reset page number to 0 if filter applied or page number is out of bounds - const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); - queryParams.append('pageNo', effectivePageNo); - setResetPageNo(false); + //reset page number to 0 if filter applied or page number is out of bounds + const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); + queryParams.append('pageNo', effectivePageNo); + setResetPageNo(false); - if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); - if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); - if (filterAttributes.sbiVersion) queryParams.append('sbiVersion', filterAttributes.sbiVersion); - if (filterAttributes.status) queryParams.append('status', filterAttributes.status); - if (filterAttributes.sbiExpiryStatus) queryParams.append('sbiExpiryStatus', filterAttributes.sbiExpiryStatus); + if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); + if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); + if (filterAttributes.sbiVersion) queryParams.append('sbiVersion', filterAttributes.sbiVersion); + if (filterAttributes.status) queryParams.append('status', filterAttributes.status); + if (filterAttributes.sbiExpiryStatus) queryParams.append('sbiExpiryStatus', filterAttributes.sbiExpiryStatus); - const url = `${getPartnerManagerUrl('/securebiometricinterface/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; - try { - fetchData ? setTableDataLoaded(false) : setDataLoaded(false); - const response = await HttpService.get(url); - if (response) { - const responseData = response.data; - if (responseData && responseData.response) { - const resData = responseData.response.data; - setTotalRecords(responseData.response.totalResults); - setSbiList(resData); - } else { - handleServiceErrors(responseData, setErrorCode, setErrorMsg); - } + const url = `${getPartnerManagerUrl('/securebiometricinterface/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; + try { + fetchData ? setTableDataLoaded(false) : setDataLoaded(false); + const response = await HttpService.get(url); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response.data; + setTotalRecords(responseData.response.totalResults); + setSbiList(resData); } else { - setErrorMsg(t('sbiList.errorInSbiList')); + handleServiceErrors(responseData, setErrorCode, setErrorMsg); } - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - setFetchData(false); - } catch (err) { - setFetchData(false); - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - console.error('Error fetching data:', err); - setErrorMsg(err); + } else { + setErrorMsg(t('sbiList.errorInSbiList')); } + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + setFetchData(false); + } catch (err) { + setFetchData(false); + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + console.error('Error fetching data:', err); + setErrorMsg(err); + } + } + + useEffect(() => { + + if (isApplyFilterClicked || initialRender) { + fetchSbiListData(); + setInitialRender(false); + setIsApplyFilterClicked(false); } - fetch(); - }, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]); + }, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]); const onApplyFilter = (updatedfilters) => { - onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes); + onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked); }; const getPaginationValues = (recordsPerPage, pageIndex) => { diff --git a/pmp-revamp-ui/src/pages/admin/ftmProviderServices/AdminFtmList.js b/pmp-revamp-ui/src/pages/admin/ftmProviderServices/AdminFtmList.js index a6827a8a..d7337756 100644 --- a/pmp-revamp-ui/src/pages/admin/ftmProviderServices/AdminFtmList.js +++ b/pmp-revamp-ui/src/pages/admin/ftmProviderServices/AdminFtmList.js @@ -42,6 +42,8 @@ function AdminFtmList() { const [totalRecords, setTotalRecords] = useState(0); const [resetPageNo, setResetPageNo] = useState(false); const [applyFilter, setApplyFilter] = useState(false); + const [initialRender, setInitialRender] = useState(true); + const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false); const [showFtmApproveRejectPopup, setShowFtmApproveRejectPopup] = useState(false); const [deactivateRequest, setDeactivateRequest] = useState({}); const [showDeactivatePopup, setShowDeactivatePopup] = useState(false); @@ -69,54 +71,60 @@ function AdminFtmList() { { id: "action", headerNameKey: 'ftmList.action' } ]; - useEffect(() => { - const fetch = async () => { - const queryParams = new URLSearchParams(); - queryParams.append('sortFieldName', sortFieldName); - queryParams.append('sortType', sortType); - queryParams.append('pageSize', pageSize); + const fetchFtmListData = async () => { + const queryParams = new URLSearchParams(); + queryParams.append('sortFieldName', sortFieldName); + queryParams.append('sortType', sortType); + queryParams.append('pageSize', pageSize); - //reset page number to 0 if filter applied or page number is out of bounds - const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); - queryParams.append('pageNo', effectivePageNo); - setResetPageNo(false); + //reset page number to 0 if filter applied or page number is out of bounds + const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); + queryParams.append('pageNo', effectivePageNo); + setResetPageNo(false); - if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); - if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); - if (filterAttributes.make) queryParams.append('make', filterAttributes.make); - if (filterAttributes.model) queryParams.append('model', filterAttributes.model); - if (filterAttributes.status) queryParams.append('status', filterAttributes.status); + if (filterAttributes.partnerId) queryParams.append('partnerId', filterAttributes.partnerId); + if (filterAttributes.orgName) queryParams.append('orgName', filterAttributes.orgName); + if (filterAttributes.make) queryParams.append('make', filterAttributes.make); + if (filterAttributes.model) queryParams.append('model', filterAttributes.model); + if (filterAttributes.status) queryParams.append('status', filterAttributes.status); - const url = `${getPartnerManagerUrl('/ftpchipdetail/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; - try { - fetchData ? setTableDataLoaded(false) : setDataLoaded(false); - const response = await HttpService.get(url); - if (response) { - const responseData = response.data; - if (responseData && responseData.response) { - const resData = responseData.response.data; - setTotalRecords(responseData.response.totalResults); - setFtmList(resData); - } else { - handleServiceErrors(responseData, setErrorCode, setErrorMsg); - } + const url = `${getPartnerManagerUrl('/ftpchipdetail/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; + try { + fetchData ? setTableDataLoaded(false) : setDataLoaded(false); + const response = await HttpService.get(url); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response.data; + setTotalRecords(responseData.response.totalResults); + setFtmList(resData); } else { - setErrorMsg(t('ftmList.errorInFtmList')); + handleServiceErrors(responseData, setErrorCode, setErrorMsg); } - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - setFetchData(false); - } catch (err) { - setFetchData(false); - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - console.error('Error fetching data:', err); - setErrorMsg(err); + } else { + setErrorMsg(t('ftmList.errorInFtmList')); } + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + setFetchData(false); + } catch (err) { + setFetchData(false); + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + console.error('Error fetching data:', err); + setErrorMsg(err); + } + } + + useEffect(() => { + + if (isApplyFilterClicked || initialRender) { + fetchFtmListData(); + setInitialRender(false); + setIsApplyFilterClicked(false); } - fetch(); - }, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]); + }, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]); const onApplyFilter = (filters) => { - onClickApplyFilter(filters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes); + onClickApplyFilter(filters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked); }; const getPaginationValues = (recordsPerPage, pageIndex) => { diff --git a/pmp-revamp-ui/src/pages/admin/partners/PartnersList.js b/pmp-revamp-ui/src/pages/admin/partners/PartnersList.js index 333834e5..cf5e8a5d 100644 --- a/pmp-revamp-ui/src/pages/admin/partners/PartnersList.js +++ b/pmp-revamp-ui/src/pages/admin/partners/PartnersList.js @@ -48,6 +48,8 @@ function PartnersList() { const [tableDataLoaded, setTableDataLoaded] = useState(true); const [showDeactivatePopup, setShowDeactivatePopup] = useState(false); const [deactivateRequest, setDeactivateRequest] = useState({}); + const [initialRender, setInitialRender] = useState(true); + const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false); const [isFilterApplied, setIsFilterApplied ] = useState(false); const [resetPageNo, setResetPageNo] = useState(false); const [filters, setFilters] = useState({ @@ -76,60 +78,66 @@ function PartnersList() { { id: "action", headerNameKey: "partnerList.action" }, ]; - useEffect(() => { - const fetchData = async () => { - const queryParams = new URLSearchParams(); - queryParams.append('sortFieldName', sortFieldName); - queryParams.append('sortType', sortType); - queryParams.append('pageSize', pageSize); + const fetchPartnersData = async () => { + const queryParams = new URLSearchParams(); + queryParams.append('sortFieldName', sortFieldName); + queryParams.append('sortType', sortType); + queryParams.append('pageSize', pageSize); - //reset page number to 0 if filter applied or page number is out of bounds - const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); - queryParams.append('pageNo', effectivePageNo); - setResetPageNo(false); - - if (filters.partnerId) queryParams.append('partnerId', filters.partnerId); - if (filters.partnerType) queryParams.append('partnerType', filters.partnerType); - if (filters.orgName) queryParams.append('orgName', filters.orgName); - if (filters.emailAddress) queryParams.append('emailAddress', filters.emailAddress); - if (filters.certificateUploadStatus) queryParams.append('certificateUploadStatus', filters.certificateUploadStatus); - if (filters.policyGroupName) queryParams.append('policyGroupName', filters.policyGroupName); - - // Check filters.status - if (filters.status !== null) { - if (filters.status === 'active') queryParams.append('isActive', true); - else if (filters.status === 'deactivated') queryParams.append('isActive', false); - } + //reset page number to 0 if filter applied or page number is out of bounds + const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); + queryParams.append('pageNo', effectivePageNo); + setResetPageNo(false); + + if (filters.partnerId) queryParams.append('partnerId', filters.partnerId); + if (filters.partnerType) queryParams.append('partnerType', filters.partnerType); + if (filters.orgName) queryParams.append('orgName', filters.orgName); + if (filters.emailAddress) queryParams.append('emailAddress', filters.emailAddress); + if (filters.certificateUploadStatus) queryParams.append('certificateUploadStatus', filters.certificateUploadStatus); + if (filters.policyGroupName) queryParams.append('policyGroupName', filters.policyGroupName); + + // Check filters.status + if (filters.status !== null) { + if (filters.status === 'active') queryParams.append('isActive', true); + else if (filters.status === 'deactivated') queryParams.append('isActive', false); + } - const url = `${getPartnerManagerUrl('/partners/v3', process.env.NODE_ENV)}?${queryParams.toString()}`; - try { - triggerServerMethod ? setTableDataLoaded(false) : setDataLoaded(false); - const response = await HttpService.get(url); - if (response) { - const responseData = response.data; - if (responseData && responseData.response) { - const resData = responseData.response.data; - setTotalRecords(responseData.response.totalResults); - setPartnersData(resData); - } else { - handleServiceErrors(responseData, setErrorCode, setErrorMsg); - } + const url = `${getPartnerManagerUrl('/partners/v3', process.env.NODE_ENV)}?${queryParams.toString()}`; + try { + triggerServerMethod ? setTableDataLoaded(false) : setDataLoaded(false); + const response = await HttpService.get(url); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response.data; + setTotalRecords(responseData.response.totalResults); + setPartnersData(resData); } else { - setErrorMsg(t('partnerList.errorInPartnersList')); + handleServiceErrors(responseData, setErrorCode, setErrorMsg); } - triggerServerMethod ? setTableDataLoaded(true) : setDataLoaded(true); - setTriggerServerMethod(false); - } catch (err) { - triggerServerMethod ? setTableDataLoaded(true) : setDataLoaded(true); - console.error('Error fetching data:', err); - setErrorMsg(err); + } else { + setErrorMsg(t('partnerList.errorInPartnersList')); } + triggerServerMethod ? setTableDataLoaded(true) : setDataLoaded(true); + setTriggerServerMethod(false); + } catch (err) { + triggerServerMethod ? setTableDataLoaded(true) : setDataLoaded(true); + console.error('Error fetching data:', err); + setErrorMsg(err); + } + } + + useEffect(() => { + + if (isApplyFilterClicked || initialRender) { + fetchPartnersData(); + setInitialRender(false); + setIsApplyFilterClicked(false); } - fetchData(); - }, [sortFieldName, sortType, pageNo, pageSize, filters]); +}, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]); const onApplyFilter = (filters) => { - onClickApplyFilter(filters, setIsFilterApplied, setResetPageNo, setTriggerServerMethod, setFilters); + onClickApplyFilter(filters, setIsFilterApplied, setResetPageNo, setTriggerServerMethod, setFilters, setIsApplyFilterClicked); }; const getPaginationValues = (recordsPerPage, pageIndex) => { diff --git a/pmp-revamp-ui/src/pages/admin/policyManager/PoliciesList.js b/pmp-revamp-ui/src/pages/admin/policyManager/PoliciesList.js index bfb2f00a..dcfbec21 100644 --- a/pmp-revamp-ui/src/pages/admin/policyManager/PoliciesList.js +++ b/pmp-revamp-ui/src/pages/admin/policyManager/PoliciesList.js @@ -48,6 +48,8 @@ function PoliciesList({ policyType, createPolicyButtonName, createPolicy, subTit const [totalRecords, setTotalRecords] = useState(0); const [resetPageNo, setResetPageNo] = useState(false); const [applyFilter, setApplyFilter] = useState(false); + const [initialRender, setInitialRender] = useState(true); + const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false); const [showDeactivatePopup, setShowDeactivatePopup] = useState(false); const [deactivatePolicyHeader, setDeactivatePolicyHeader] = useState(); const [deactivatePolicyDescription, setDeactivatePolicyDescription] = useState(); @@ -76,65 +78,71 @@ function PoliciesList({ policyType, createPolicyButtonName, createPolicy, subTit { id: "action", headerNameKey: "policiesList.action" }, ]; - useEffect(() => { - localStorage.setItem('activeTab', policyType); - const fetch = async () => { - const queryParams = new URLSearchParams(); - queryParams.append('sortFieldName', sortFieldName); - queryParams.append('sortType', sortType); - queryParams.append('pageSize', pageSize); + + const fetchPoliciesListData = async () => { + const queryParams = new URLSearchParams(); + queryParams.append('sortFieldName', sortFieldName); + queryParams.append('sortType', sortType); + queryParams.append('pageSize', pageSize); - //reset page number to 0 if filter applied or page number is out of bounds - const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); - queryParams.append('pageNo', effectivePageNo); - setResetPageNo(false); + //reset page number to 0 if filter applied or page number is out of bounds + const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); + queryParams.append('pageNo', effectivePageNo); + setResetPageNo(false); - queryParams.append('policyType', policyType); - if (filterAttributes.policyId) queryParams.append('policyId', filterAttributes.policyId); - if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName); - if (filterAttributes.policyDescription) queryParams.append('policyDescription', filterAttributes.policyDescription); - if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName); - if (filterAttributes.status) queryParams.append('status', filterAttributes.status); + queryParams.append('policyType', policyType); + if (filterAttributes.policyId) queryParams.append('policyId', filterAttributes.policyId); + if (filterAttributes.policyName) queryParams.append('policyName', filterAttributes.policyName); + if (filterAttributes.policyDescription) queryParams.append('policyDescription', filterAttributes.policyDescription); + if (filterAttributes.policyGroupName) queryParams.append('policyGroupName', filterAttributes.policyGroupName); + if (filterAttributes.status) queryParams.append('status', filterAttributes.status); - const url = `${getPolicyManagerUrl('/policies/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; - try { - fetchData ? setTableDataLoaded(false) : setDataLoaded(false); - const response = await HttpService({ - url: url, - method: 'get', - baseURL: process.env.NODE_ENV !== 'production' ? '' : window._env_.REACT_APP_POLICY_MANAGER_API_BASE_URL - }); - if (response) { - const responseData = response.data; - if (responseData && responseData.response) { - const resData = responseData.response.data; - setTotalRecords(responseData.response.totalResults); - if (resData !== null) { - setPoliciesList(resData) - } - else { - setPoliciesList([]); - } - } else { - handleServiceErrors(responseData, setErrorCode, setErrorMsg); + const url = `${getPolicyManagerUrl('/policies/search/v2', process.env.NODE_ENV)}?${queryParams.toString()}`; + try { + fetchData ? setTableDataLoaded(false) : setDataLoaded(false); + const response = await HttpService({ + url: url, + method: 'get', + baseURL: process.env.NODE_ENV !== 'production' ? '' : window._env_.REACT_APP_POLICY_MANAGER_API_BASE_URL + }); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response.data; + setTotalRecords(responseData.response.totalResults); + if (resData !== null) { + setPoliciesList(resData) + } + else { + setPoliciesList([]); } } else { - setErrorMsg(t(fetchDataErrorMessage)); + handleServiceErrors(responseData, setErrorCode, setErrorMsg); } - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - setFetchData(false); - } catch (err) { - setFetchData(false); - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - console.error('Error fetching data:', err); - setErrorMsg(err); + } else { + setErrorMsg(t(fetchDataErrorMessage)); } + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + setFetchData(false); + } catch (err) { + setFetchData(false); + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + console.error('Error fetching data:', err); + setErrorMsg(err); + } + } + + useEffect(() => { + + if (isApplyFilterClicked || initialRender) { + fetchPoliciesListData(); + setInitialRender(false); + setIsApplyFilterClicked(false); } - fetch(); - }, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]); + }, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]); const onApplyFilter = (updatedfilters) => { - onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes); + onClickApplyFilter(updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked); }; const getPaginationValues = (recordsPerPage, pageIndex) => { diff --git a/pmp-revamp-ui/src/pages/admin/policyManager/PolicyGroupList.js b/pmp-revamp-ui/src/pages/admin/policyManager/PolicyGroupList.js index 6ac3c7d6..ce6ce4bd 100644 --- a/pmp-revamp-ui/src/pages/admin/policyManager/PolicyGroupList.js +++ b/pmp-revamp-ui/src/pages/admin/policyManager/PolicyGroupList.js @@ -44,6 +44,8 @@ function PolicyGroupList() { const [totalRecords, setTotalRecords] = useState(0); const [resetPageNo, setResetPageNo] = useState(false); const [applyFilter, setApplyFilter] = useState(false); + const [initialRender, setInitialRender] = useState(true); + const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false); const [filterAttributes, setFilterAttributes] = useState({ id: null, name: null, @@ -66,56 +68,61 @@ function PolicyGroupList() { { id: "action", headerNameKey: "policyGroupList.action" }, ]; - useEffect(() => { - localStorage.setItem('activeTab', 'policyGroup'); - const fetch = async () => { - //reset page number to 0 if filter applied or page number is out of bounds - const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); - setResetPageNo(false); + const fetchPolicyGroupListData = async () => { + //reset page number to 0 if filter applied or page number is out of bounds + const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); + setResetPageNo(false); - // filter - let filterRequest = getFiltersRequest(); + // filter + let filterRequest = getFiltersRequest(); - const request = createRequest({ - filters: filterRequest, - sort: [{ sortField: sortFieldName, sortType: sortType }], - pagination: { - pageStart: effectivePageNo, - pageFetch: pageSize - } + const request = createRequest({ + filters: filterRequest, + sort: [{ sortField: sortFieldName, sortType: sortType }], + pagination: { + pageStart: effectivePageNo, + pageFetch: pageSize + } + }); + try { + fetchData ? setTableDataLoaded(false) : setDataLoaded(false); + const response = await HttpService({ + url: getPolicyManagerUrl('/policies/group/search', process.env.NODE_ENV), + method: 'post', + baseURL: process.env.NODE_ENV !== 'production' ? '' : window._env_.REACT_APP_POLICY_MANAGER_API_BASE_URL, + data: request }); - try { - fetchData ? setTableDataLoaded(false) : setDataLoaded(false); - const response = await HttpService({ - url: getPolicyManagerUrl('/policies/group/search', process.env.NODE_ENV), - method: 'post', - baseURL: process.env.NODE_ENV !== 'production' ? '' : window._env_.REACT_APP_POLICY_MANAGER_API_BASE_URL, - data: request - }); - if (response) { - const responseData = response.data; - if (responseData && responseData.response) { - const resData = responseData.response.data; - setTotalRecords(responseData.response.totalRecord); - if (resData !== null) setPolicyGroupList(resData); - else setPolicyGroupList([]); - } else { - handleServiceErrors(responseData, setErrorCode, setErrorMsg); - } + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response.data; + setTotalRecords(responseData.response.totalRecord); + if (resData !== null) setPolicyGroupList(resData); + else setPolicyGroupList([]); } else { - setErrorMsg(t('policyGroupList.errorInPolicyGroupList')); + handleServiceErrors(responseData, setErrorCode, setErrorMsg); } - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - setFetchData(false); - } catch (err) { - fetchData ? setTableDataLoaded(true) : setDataLoaded(true); - setFetchData(false); - console.error('Error fetching data:', err); - setErrorMsg(err); + } else { + setErrorMsg(t('policyGroupList.errorInPolicyGroupList')); } + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + setFetchData(false); + } catch (err) { + fetchData ? setTableDataLoaded(true) : setDataLoaded(true); + setFetchData(false); + console.error('Error fetching data:', err); + setErrorMsg(err); + } + } + + useEffect(() => { + + if (isApplyFilterClicked || initialRender) { + fetchPolicyGroupListData(); + setInitialRender(false); + setIsApplyFilterClicked(false); } - fetch(); - }, [sortFieldName, sortType, pageNo, pageSize, filterAttributes]); + }, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]); const getFiltersRequest = () => { let filtersArr = []; @@ -164,7 +171,7 @@ function PolicyGroupList() { }; const onApplyFilter = (filters) => { - onClickApplyFilter(filters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes); + onClickApplyFilter(filters, setApplyFilter, setResetPageNo, setFetchData, setFilterAttributes, setIsApplyFilterClicked); }; const getPaginationValues = (recordsPerPage, pageIndex) => { diff --git a/pmp-revamp-ui/src/pages/admin/policyRequests/PolicyRequestsList.js b/pmp-revamp-ui/src/pages/admin/policyRequests/PolicyRequestsList.js index 5a33b6a5..4ef56754 100644 --- a/pmp-revamp-ui/src/pages/admin/policyRequests/PolicyRequestsList.js +++ b/pmp-revamp-ui/src/pages/admin/policyRequests/PolicyRequestsList.js @@ -51,6 +51,8 @@ function PolicyRequestsList() { const [triggerServerMethod, setTriggerServerMethod] = useState(false); const [totalRecords, setTotalRecords] = useState(0); const [tableDataLoaded, setTableDataLoaded] = useState(true); + const [initialRender, setInitialRender] = useState(true); + const [isApplyFilterClicked, setIsApplyFilterClicked] = useState(false); const [isFilterApplied, setIsFilterApplied] = useState(false); const [showPopup, setShowPopup] = useState(false); const [resetPageNo, setResetPageNo] = useState(false); @@ -81,55 +83,61 @@ function PolicyRequestsList() { { id: "action", headerNameKey: "partnerPolicyMappingRequestList.action" }, ]; - useEffect(() => { - const fetchData = async () => { - const queryParams = new URLSearchParams(); - queryParams.append('sortFieldName', sortFieldName); - queryParams.append('sortType', sortType); - queryParams.append('pageSize', pageSize); + const fetchPolicyRequestsListData = async () => { + const queryParams = new URLSearchParams(); + queryParams.append('sortFieldName', sortFieldName); + queryParams.append('sortType', sortType); + queryParams.append('pageSize', pageSize); - //reset page number to 0 if filter applied or page number is out of bounds - const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); - queryParams.append('pageNo', effectivePageNo); - setResetPageNo(false); + //reset page number to 0 if filter applied or page number is out of bounds + const effectivePageNo = resetPageNumber(totalRecords, pageNo, pageSize, resetPageNo); + queryParams.append('pageNo', effectivePageNo); + setResetPageNo(false); - if (filters.partnerId) queryParams.append('partnerId', filters.partnerId); - if (filters.partnerType) queryParams.append('partnerTypeCode', filters.partnerType); - if (filters.orgName) queryParams.append('orgName', filters.orgName); - if (filters.policyGroupName) queryParams.append('policyGroupName', filters.policyGroupName); - if (filters.policyId) queryParams.append('policyId', filters.policyId); - if (filters.policyName) queryParams.append('policyName', filters.policyName); - if (filters.status) queryParams.append('status', filters.status); + if (filters.partnerId) queryParams.append('partnerId', filters.partnerId); + if (filters.partnerType) queryParams.append('partnerTypeCode', filters.partnerType); + if (filters.orgName) queryParams.append('orgName', filters.orgName); + if (filters.policyGroupName) queryParams.append('policyGroupName', filters.policyGroupName); + if (filters.policyId) queryParams.append('policyId', filters.policyId); + if (filters.policyName) queryParams.append('policyName', filters.policyName); + if (filters.status) queryParams.append('status', filters.status); - const url = `${getPartnerManagerUrl('/partners/partner-policy-requests', process.env.NODE_ENV)}?${queryParams.toString()}`; - try { - triggerServerMethod ? setTableDataLoaded(false) : setDataLoaded(false); - const response = await HttpService.get(url); - if (response) { - const responseData = response.data; - if (responseData && responseData.response) { - const resData = responseData.response.data; - setTotalRecords(responseData.response.totalResults); - setPolicyRequestsData(resData); - } else { - handleServiceErrors(responseData, setErrorCode, setErrorMsg); - } + const url = `${getPartnerManagerUrl('/partners/partner-policy-requests', process.env.NODE_ENV)}?${queryParams.toString()}`; + try { + triggerServerMethod ? setTableDataLoaded(false) : setDataLoaded(false); + const response = await HttpService.get(url); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response.data; + setTotalRecords(responseData.response.totalResults); + setPolicyRequestsData(resData); } else { - setErrorMsg(t('partnerPolicyMappingRequestList.errorInpartnerPolicyMappingRequestList')); + handleServiceErrors(responseData, setErrorCode, setErrorMsg); } - triggerServerMethod ? setTableDataLoaded(true) : setDataLoaded(true); - setTriggerServerMethod(false); - } catch (err) { - triggerServerMethod ? setTableDataLoaded(true) : setDataLoaded(true); - console.error('Error fetching data:', err); - setErrorMsg(err); + } else { + setErrorMsg(t('partnerPolicyMappingRequestList.errorInpartnerPolicyMappingRequestList')); } + triggerServerMethod ? setTableDataLoaded(true) : setDataLoaded(true); + setTriggerServerMethod(false); + } catch (err) { + triggerServerMethod ? setTableDataLoaded(true) : setDataLoaded(true); + console.error('Error fetching data:', err); + setErrorMsg(err); + } + } + + useEffect(() => { + + if (isApplyFilterClicked || initialRender) { + fetchPolicyRequestsListData(); + setInitialRender(false); + setIsApplyFilterClicked(false); } - fetchData(); - }, [sortFieldName, sortType, pageNo, pageSize, filters]); +}, [sortFieldName, sortType, pageNo, pageSize, isApplyFilterClicked]); const onApplyFilter = (filters) => { - onClickApplyFilter(filters, setIsFilterApplied, setResetPageNo, setTriggerServerMethod, setFilters); + onClickApplyFilter(filters, setIsFilterApplied, setResetPageNo, setTriggerServerMethod, setFilters, setIsApplyFilterClicked); }; const getPaginationValues = (recordsPerPage, pageIndex) => { diff --git a/pmp-revamp-ui/src/utils/AppUtils.js b/pmp-revamp-ui/src/utils/AppUtils.js index 5952bc85..eabbfaa1 100644 --- a/pmp-revamp-ui/src/utils/AppUtils.js +++ b/pmp-revamp-ui/src/utils/AppUtils.js @@ -450,12 +450,12 @@ export const resetPageNumber = (totalRecords, pageNo, pageSize, resetPageNo) => return effectivePageNo; }; -export const onClickApplyFilter = (updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilters) => { - // console.log(filters) +export const onClickApplyFilter = (updatedfilters, setApplyFilter, setResetPageNo, setFetchData, setFilters, setIsApplyFilterClicked) => { setApplyFilter(true); setResetPageNo(true); setFetchData(true); setFilters(updatedfilters); + setIsApplyFilterClicked(true); }; export const setPageNumberAndPageSize = (recordsPerPage, pageIndex, pageNo, setPageNo, pageSize, setPageSize, setFetchData) => {