diff --git a/ipi-survey-platform/src/pages/ManufacturingIndex/ManufacturingIndex.jsx b/ipi-survey-platform/src/pages/ManufacturingIndex/ManufacturingIndex.jsx index dfec044..bac3f2b 100644 --- a/ipi-survey-platform/src/pages/ManufacturingIndex/ManufacturingIndex.jsx +++ b/ipi-survey-platform/src/pages/ManufacturingIndex/ManufacturingIndex.jsx @@ -326,41 +326,34 @@ const ManufacturingIndex = () => { setQuarter(selectedQuarter); }; - const handleTriggerData = () => { + const handleTriggerData = async () => { setError(null); - setRefreshKey(prev => prev + 1); + setSurveySubmitStatus(''); + setSurveySubmitError(null); + + if (year === 'All' || !quarter) { + setSurveySubmitError('Please select a valid year and quarter.'); + return; + } + + setSurveySubmitLoading(true); + + try { + const response = await autoSubmitSurvey(parseInt(year, 10), quarter); + + setSurveySubmitStatus( + response?.data?.message || 'Survey auto-submit request sent successfully.' + ); + setRefreshKey(prev => prev + 1); + } catch (error) { + setSurveySubmitError( + error?.response?.data?.message || error.message || 'Survey auto-submit failed.' + ); + } finally { + setSurveySubmitLoading(false); + } }; - useEffect(() => { - const submitSurvey = async () => { - if (year === 'All' || !quarter) { - setSurveySubmitStatus(''); - setSurveySubmitError(null); - return; - } - - try { - setSurveySubmitLoading(true); - setSurveySubmitStatus(''); - setSurveySubmitError(null); - - const response = await autoSubmitSurvey(parseInt(year, 10), quarter); - - setSurveySubmitStatus( - response?.data?.message || 'Survey auto-submit request sent successfully.' - ); - } catch (error) { - setSurveySubmitError( - error?.response?.data?.message || error.message || 'Survey auto-submit failed.' - ); - } finally { - setSurveySubmitLoading(false); - } - }; - - submitSurvey(); - }, [year, quarter]); - const handleExportCSV = () => { const headers = ['Month', 'Quarter', 'Index', 'Total Weight', 'MoM Change', 'YoY Change', 'Generated On', 'Status']; const csvContent = [ diff --git a/ipi-survey-platform/src/services/manufacturingIndex/ManufacturingIndex.js b/ipi-survey-platform/src/services/manufacturingIndex/ManufacturingIndex.js index 4d46c51..b2608f4 100644 --- a/ipi-survey-platform/src/services/manufacturingIndex/ManufacturingIndex.js +++ b/ipi-survey-platform/src/services/manufacturingIndex/ManufacturingIndex.js @@ -36,10 +36,19 @@ export const getManufacturingMonthlyOverview = async (year, quarter) => { export const autoSubmitSurvey = async (year, quarter) => { try { - const response = await postRequest('/api/survey_auto_submit', { - year, - quarter, - }); + const response = await postRequest( + '/survey_auto_submit', + { + year, + quarter, + }, + { + headers: { + 'Cache-Control': 'no-cache', + Pragma: 'no-cache', + }, + } + ); return response; } catch (error) { console.error('Error auto-submitting survey:', error);