diff --git a/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx b/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx index 6163d9a..c8eb7dd 100644 --- a/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx +++ b/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx @@ -1,4 +1,5 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; +import { getQuarterPeriods, getPreviousForecastData } from '@/services/submissions/submissionService'; import { fetchVariationReasons, fetchZeroTargetReasons, @@ -12,9 +13,17 @@ const calendarIcon = '/assets/images/Duedate.svg'; const nextIcon = '/assets/images/mdi_page-next-outline.svg'; const trashActiveSrc = '/assets/images/Trash - active.svg'; -const Input = ({ placeholder = '', type = 'text', value = '', onChange = () => {}, required = false }) => { +const Input = ({ placeholder = '', type = 'text', value = '', onChange = () => {}, required = false, error = false }) => { const [isFocused, setIsFocused] = React.useState(false); - const borderColor = value || isFocused ? 'border-[#92722A]' : 'border-[#CBA344]'; + let borderColor = 'border-[#CBA344]'; + let bgColor = 'bg-white'; + + if (error) { + borderColor = 'border-red-500'; + bgColor = 'bg-red-50'; + } else if (value || isFocused) { + borderColor = 'border-[#92722A]'; + } return (
@@ -26,7 +35,7 @@ const Input = ({ placeholder = '', type = 'text', value = '', onChange = () => { onFocus={() => setIsFocused(true)} onBlur={() => setIsFocused(false)} required={required} - className={`block w-full h-10 rounded-md border-2 ${borderColor} focus:ring-0 px-4 text-sm bg-white transition-colors [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`} + className={`block w-full h-10 rounded-md border-2 ${borderColor} focus:ring-0 px-4 text-sm ${bgColor} transition-colors [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`} />
); @@ -38,24 +47,32 @@ const Select = ({ value = '', onChange, loading = false, - disabled = false + disabled = false, + error = false, + className = '' }) => { const [isFocused, setIsFocused] = React.useState(false); + let borderColor = 'border-[#CBA344]'; + let bgColor = 'bg-white'; + + if (error) { + borderColor = 'border-red-500'; + bgColor = 'bg-red-50'; + } else if (value || isFocused) { + borderColor = 'border-[#92722A]'; + } + return (
updateProductField(p.id, 'product', e.target.value, productOptions)} - /> +
+ updateProductField(p.id, 'previousQuantity', e.target.value)} + value={p.octQuantity || ''} + onChange={(e) => updateProductField(p.id, 'octQuantity', e.target.value)} />
- +
- +
-
-
+
- +
- +
- + - +
- + updateProductField(p.id, 'janQuantity', e.target.value)} /> + {formErrors[`janQuantity_${idx}`] && ( +

{formErrors[`janQuantity_${idx}`]}

+ )}
- + updateProductField(p.id, 'febQuantity', e.target.value)} /> + {formErrors[`febQuantity_${idx}`] && ( +

{formErrors[`febQuantity_${idx}`]}

+ )}
- + updateProductField(p.id, 'marQuantity', e.target.value)} /> + {formErrors[`marQuantity_${idx}`] && ( +

{formErrors[`marQuantity_${idx}`]}

+ )}
- + updateProductField(p.id, 'janCost', e.target.value)} /> + {formErrors[`janCost_${idx}`] && ( +

{formErrors[`janCost_${idx}`]}

+ )}
- + updateProductField(p.id, 'febCost', e.target.value)} /> + {formErrors[`febCost_${idx}`] && ( +

{formErrors[`febCost_${idx}`]}

+ )}
- + updateProductField(p.id, 'marCost', e.target.value)} /> + {formErrors[`marCost_${idx}`] && ( +

{formErrors[`marCost_${idx}`]}

+ )} +
@@ -686,77 +1069,116 @@ const ProductData = ({
- +
- + updateProductField(p.id, 'aprQuantity', e.target.value)} /> + {formErrors[`aprQuantity_${idx}`] && ( +

{formErrors[`aprQuantity_${idx}`]}

+ )}
- + updateProductField(p.id, 'mayQuantity', e.target.value)} /> + {formErrors[`mayQuantity_${idx}`] && ( +

{formErrors[`mayQuantity_${idx}`]}

+ )}
- -
- +
+ updateProductField(p.id, 'junQuantity', e.target.value)} /> + {formErrors[`junQuantity_${idx}`] && ( +

{formErrors[`junQuantity_${idx}`]}

+ )}
- + updateProductField(p.id, 'aprCost', e.target.value)} /> + {formErrors[`aprCost_${idx}`] && ( +

{formErrors[`aprCost_${idx}`]}

+ )}
- + updateProductField(p.id, 'mayCost', e.target.value)} /> + {formErrors[`mayCost_${idx}`] && ( +

{formErrors[`mayCost_${idx}`]}

+ )}
- + updateProductField(p.id, 'junCost', e.target.value)} /> + {formErrors[`junCost_${idx}`] && ( +

{formErrors[`junCost_${idx}`]}

+ )}
@@ -806,7 +1228,7 @@ const ProductData = ({ Back
+ + {/* Success Popup - Moved to root level */} + {showSuccessPopup && ( +
+
+
+ {/* Green Check Icon */} +
+ + + +
+ + {/* Title */} +

+ Submission successful +

+ + {/* Message */} +

+ Thank you. Your IP Quarterly Survey for {establishmentData?.quarter} {establishmentData?.year} has been submitted. +

+ + {/* Button */} + +
+
+
+ )}
); }; diff --git a/ipi-survey-platform/src/services/submissions/submissionService.js b/ipi-survey-platform/src/services/submissions/submissionService.js index 1d68eb1..9c929a5 100644 --- a/ipi-survey-platform/src/services/submissions/submissionService.js +++ b/ipi-survey-platform/src/services/submissions/submissionService.js @@ -2,6 +2,7 @@ import { getRequest, postRequest } from '@/services/api/CommonService'; import resolveEstablishmentId from '@/services/utils/establishment'; const endpoint = '/submissions'; +const QUARTER_PERIODS_ENDPOINT = 'https://ipi.venbait.in/api/getQuarterPeriods'; // Add this new function to fetch submissions with pagination export const getSubmissions = async (page = 1, limit = 100, config = {}) => { @@ -51,9 +52,46 @@ export const fetchSubmissionDetail = async (submissionId, config = {}) => { }; // Add the new function to the default export +export const getQuarterPeriods = async (currentYear, currentQuarter) => { + try { + const response = await postRequest(QUARTER_PERIODS_ENDPOINT, { + current_year: currentYear, + current_quarter: currentQuarter + }); + return response.data; + } catch (error) { + console.error('Error fetching quarter periods:', error); + throw error; + } +}; + +export const getPreviousForecastData = async (establishmentId, quarter, year, productId) => { + try { + const response = await getRequest( + `https://ipi.venbait.in/api/submissions/getPreviousForecastData`, + { + params: { + establishment_id: establishmentId, + quarter: quarter, + year: year, + product_id: productId + } + } + ); + // Check if response has data property and return it, otherwise return the response as is + return response.data || response; + } catch (error) { + console.error('Error fetching previous forecast data:', error); + // Instead of throwing, return null to handle the error gracefully + return null; + } +}; + export default { - getSubmissions, // Add this line + getSubmissions, submitSurvey, fetchSubmissionHistory, fetchSubmissionDetail, + getQuarterPeriods, + getPreviousForecastData }; \ No newline at end of file