trigger data button
This commit is contained in:
parent
4f969341a2
commit
755352d37c
@ -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 = [
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user