changed in resumitted
This commit is contained in:
parent
601e967c01
commit
8c708f9bd7
@ -138,36 +138,34 @@ const EstablishmentInfo = ({
|
||||
}, []);
|
||||
|
||||
const [surveyData, setSurveyData] = React.useState(() => {
|
||||
// Initialize from location state if available, otherwise use defaults
|
||||
// For resubmission, use the quarter/year from the submission data
|
||||
if (location.state?.fromResubmit && data?.quarter && data?.year) {
|
||||
const surveyPeriod = {
|
||||
quarter: data.quarter,
|
||||
year: data.year,
|
||||
endDate: data.end_date || ''
|
||||
};
|
||||
localStorage.setItem('currentSurveyPeriod', JSON.stringify(surveyPeriod));
|
||||
return surveyPeriod;
|
||||
}
|
||||
|
||||
// For new survey, use the quarter/year from location state if available
|
||||
if (location.state?.survey) {
|
||||
const { quarter, year, endDate } = location.state.survey;
|
||||
|
||||
// Save to localStorage
|
||||
const surveyPeriod = { quarter, year, endDate };
|
||||
localStorage.setItem('currentSurveyPeriod', JSON.stringify(surveyPeriod));
|
||||
|
||||
return {
|
||||
quarter: quarter || '',
|
||||
year: year || '',
|
||||
endDate: endDate || ''
|
||||
};
|
||||
return surveyPeriod;
|
||||
}
|
||||
// Or use current quarter/year as fallback
|
||||
const current = getCurrentQuarterAndYear();
|
||||
|
||||
// Save to localStorage
|
||||
// Fallback to current quarter/year
|
||||
const current = getCurrentQuarterAndYear();
|
||||
const surveyPeriod = {
|
||||
quarter: current.quarter,
|
||||
year: current.year,
|
||||
endDate: current.endDate
|
||||
};
|
||||
localStorage.setItem('currentSurveyPeriod', JSON.stringify(surveyPeriod));
|
||||
|
||||
return {
|
||||
quarter: current.quarter,
|
||||
year: current.year,
|
||||
endDate: current.endDate
|
||||
};
|
||||
return surveyPeriod;
|
||||
});
|
||||
|
||||
// Log when surveyData changes
|
||||
@ -179,9 +177,38 @@ const EstablishmentInfo = ({
|
||||
surveyDataRef.current = surveyData;
|
||||
}, [surveyData]);
|
||||
|
||||
// Use a ref to track if we've already set the initial survey data
|
||||
const hasInitialized = React.useRef(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
// Only update if we don't already have survey data
|
||||
if (!surveyDataRef.current?.quarter && location.state?.survey) {
|
||||
// Skip if we've already initialized or if we don't have the necessary data yet
|
||||
if (hasInitialized.current) return;
|
||||
|
||||
// For resubmission, ensure we use the submission's quarter/year
|
||||
if (location.state?.fromResubmit && data?.quarter && data?.year) {
|
||||
const newSurveyData = {
|
||||
quarter: data.quarter,
|
||||
year: data.year,
|
||||
endDate: data.end_date || ''
|
||||
};
|
||||
|
||||
// Only update if the values have changed
|
||||
if (JSON.stringify(surveyData) !== JSON.stringify(newSurveyData)) {
|
||||
setSurveyData(newSurveyData);
|
||||
|
||||
// Update the parent component with the survey data
|
||||
onChange({
|
||||
...data,
|
||||
quarter: newSurveyData.quarter,
|
||||
year: newSurveyData.year,
|
||||
end_date: newSurveyData.endDate
|
||||
});
|
||||
}
|
||||
|
||||
hasInitialized.current = true;
|
||||
}
|
||||
// For new survey, use the quarter/year from location state if available
|
||||
else if (location.state?.survey && !surveyData.quarter) {
|
||||
const { quarter, year, endDate } = location.state.survey;
|
||||
const newSurveyData = {
|
||||
quarter: quarter || '',
|
||||
@ -189,18 +216,22 @@ const EstablishmentInfo = ({
|
||||
endDate: endDate || ''
|
||||
};
|
||||
|
||||
setSurveyData(newSurveyData);
|
||||
// Only update if the values have changed
|
||||
if (JSON.stringify(surveyData) !== JSON.stringify(newSurveyData)) {
|
||||
setSurveyData(newSurveyData);
|
||||
|
||||
// Update the parent component with the survey data
|
||||
onChange({
|
||||
...data,
|
||||
quarter: newSurveyData.quarter,
|
||||
year: newSurveyData.year,
|
||||
end_date: newSurveyData.endDate
|
||||
});
|
||||
// Update the parent component with the survey data
|
||||
onChange({
|
||||
...data,
|
||||
quarter: newSurveyData.quarter,
|
||||
year: newSurveyData.year,
|
||||
end_date: newSurveyData.endDate
|
||||
});
|
||||
}
|
||||
|
||||
hasInitialized.current = true;
|
||||
}
|
||||
// Only run this effect when the component mounts or location.state changes
|
||||
}, [location.state, data, onChange]);
|
||||
}, [location.state, data, onChange, surveyData]);
|
||||
|
||||
const handleCloseInfo = () => {
|
||||
setShowInfoCard(false);
|
||||
|
||||
@ -333,7 +333,15 @@ const SectionBox = ({ title, children, badgeBg = 'bg-white', badgeText = 'text-g
|
||||
<div className="rounded-md ring-1 ring-gray-200 bg-white">
|
||||
<div className="p-5">
|
||||
<div className="font-medium mb-2">
|
||||
<span className={`inline-flex items-center rounded text-sm font-medium px-2 py-1 ${badgeBg} ${badgeText}`}>
|
||||
<span
|
||||
className="inline-flex items-center rounded text-sm font-medium px-2 py-1"
|
||||
style={{
|
||||
backgroundColor: badgeBg.startsWith('#') ? badgeBg : undefined,
|
||||
color: badgeText.startsWith('#') ? badgeText : undefined,
|
||||
...(badgeBg.startsWith('#') ? {} : { backgroundColor: badgeBg }),
|
||||
...(badgeText.startsWith('#') ? {} : { color: badgeText })
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</span>
|
||||
</div>
|
||||
@ -400,15 +408,30 @@ const ProductData = ({
|
||||
useEffect(() => {
|
||||
const fetchQuarterPeriods = async () => {
|
||||
try {
|
||||
// Try to get survey period from localStorage
|
||||
const savedSurveyPeriod = localStorage.getItem('currentSurveyPeriod');
|
||||
let periodYear = year;
|
||||
let periodQuarter = quarter;
|
||||
|
||||
if (savedSurveyPeriod) {
|
||||
const { quarter: savedQuarter, year: savedYear } = JSON.parse(savedSurveyPeriod);
|
||||
periodYear = savedYear || year;
|
||||
periodQuarter = savedQuarter || quarter;
|
||||
// For resubmission, use the submission's quarter/year
|
||||
if (location.state?.fromResubmit && quarter && year) {
|
||||
periodYear = year;
|
||||
periodQuarter = quarter;
|
||||
}
|
||||
// For new survey, use the quarter/year from location state if available
|
||||
else if (location.state?.survey) {
|
||||
const { quarter: surveyQuarter, year: surveyYear } = location.state.survey;
|
||||
if (surveyQuarter && surveyYear) {
|
||||
periodQuarter = surveyQuarter;
|
||||
periodYear = surveyYear;
|
||||
}
|
||||
}
|
||||
// Fallback to localStorage or props
|
||||
else {
|
||||
const savedSurveyPeriod = localStorage.getItem('currentSurveyPeriod');
|
||||
if (savedSurveyPeriod) {
|
||||
const { quarter: savedQuarter, year: savedYear } = JSON.parse(savedSurveyPeriod);
|
||||
periodYear = savedYear || year;
|
||||
periodQuarter = savedQuarter || quarter;
|
||||
}
|
||||
}
|
||||
|
||||
if (!periodQuarter || !periodYear) {
|
||||
@ -417,7 +440,7 @@ const ProductData = ({
|
||||
}
|
||||
|
||||
setIsLoadingPeriods(true);
|
||||
const quarterNumber = periodQuarter.replace('Q', ''); // Convert 'Q3' to '3'
|
||||
const quarterNumber = periodQuarter.startsWith('Q') ? periodQuarter.replace('Q', '') : periodQuarter;
|
||||
const response = await getQuarterPeriods(parseInt(periodYear), `Q${quarterNumber}`);
|
||||
setQuarterPeriods(response.data);
|
||||
} catch (error) {
|
||||
@ -1108,6 +1131,28 @@ const location = useLocation();
|
||||
displayYear = savedYear || year;
|
||||
}
|
||||
|
||||
// For resubmission, use the submission's quarter/year
|
||||
if (location.state?.fromResubmit && quarter && year) {
|
||||
return (
|
||||
<div className="text-sm font-medium text-gray-600">
|
||||
Quarter: <span className="text-[#92722A]">{quarter}-{year}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// For new survey, use the quarter/year from location state if available
|
||||
if (location.state?.survey) {
|
||||
const { quarter: surveyQuarter, year: surveyYear } = location.state.survey;
|
||||
if (surveyQuarter && surveyYear) {
|
||||
return (
|
||||
<div className="text-sm font-medium text-gray-600">
|
||||
Quarter: <span className="text-[#92722A]">{surveyQuarter}-{surveyYear}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to the values from props or local storage
|
||||
return (displayQuarter || displayYear) ? (
|
||||
<div className="text-sm font-medium text-gray-600">
|
||||
Quarter: <span className="text-[#92722A]">{displayQuarter}-{displayYear}</span>
|
||||
@ -1550,8 +1595,8 @@ const location = useLocation();
|
||||
|
||||
<SectionBox
|
||||
title={quarterPeriods ? `CURRENT QUARTER (${quarterPeriods.current_quarter} ${quarterPeriods.current_year})` : `CURRENT QUARTER (${quarter}-${year})`}
|
||||
badgeBg="#F3FAF4"
|
||||
badgeText="#2F663C"
|
||||
badgeBg="#F0FDF4"
|
||||
badgeText="#166534"
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-end space-x-4">
|
||||
|
||||
@ -2025,7 +2025,7 @@ const displayedRows = sortedProfiles.map((item) => {
|
||||
emirate: establishmentEmirateName,
|
||||
isicCode: item?.isic_code ?? '',
|
||||
industryCodeBusiness: item?.industry_code,
|
||||
industryCodeProduction: item?.industry_code_production,
|
||||
industryCodeProduction: item?.isic_code,
|
||||
industryCodeCurrent: item?.industryCodeCurrent,
|
||||
industryCodeMismatchRemarks: item?.industry_code_mismatch_remarks ?? '',
|
||||
industryDescription: item?.description ?? base.industryDescription,
|
||||
|
||||
@ -42,8 +42,8 @@ const mapApiEstablishmentToProfile = (apiData) => {
|
||||
userProfileEmail: data.users?.[0]?.email || '',
|
||||
permanentFactoryCode: data.permanent_factory_code || '',
|
||||
uniqueLicenseNumber: data.license_number || '',
|
||||
industryCodeBusiness: data.industry_code_production || '',
|
||||
industryCodeCurrent: data.industry_code || '',
|
||||
industryCodeBusiness: data.industry_code || '',
|
||||
industryCodeCurrent: data.isic_code || '',
|
||||
industryCodeMismatchRemarks: data.industry_code_mismatch_remarks || '',
|
||||
contactName: data.factory_name || '',
|
||||
contactAddress: data.establishment_address || '',
|
||||
@ -197,7 +197,13 @@ const EditCompanyProfile = () => {
|
||||
if (field === 'userProfileConfirmPassword') {
|
||||
setConfirmError("");
|
||||
}
|
||||
}, []);
|
||||
if (field === 'industryCodeMismatchRemarks') {
|
||||
setForm(prev => ({
|
||||
...prev,
|
||||
industryCodeMismatchRemarks: value
|
||||
}));
|
||||
}
|
||||
}, [fieldErrors]);
|
||||
|
||||
const handleNext = useCallback(() => {
|
||||
if (validateStepFields(activeStep)) {
|
||||
@ -581,6 +587,7 @@ const EditCompanyProfile = () => {
|
||||
industry_code: form.industryCodeBusiness || "",
|
||||
license_number: form.uniqueLicenseNumber || "",
|
||||
industry_code_production: form.industryCodeCurrent || "",
|
||||
industry_code_mismatch_remarks: form.industryCodeMismatchRemarks || null,
|
||||
description: form.industryDescription || "",
|
||||
establishment_address: form.contactAddress || "",
|
||||
establishment_city_town_id: selectedCity ? Number(selectedCity.value) : null,
|
||||
@ -730,7 +737,7 @@ const EditCompanyProfile = () => {
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
{form.industryCodeCurrent && form.industryCodeBusiness !== form.industryCodeCurrent && (
|
||||
{form.industryCodeBusiness && form.industryCodeBusiness !== form.industryCodeCurrent && (
|
||||
<div className="col-span-full">
|
||||
<TextField
|
||||
label="Remarks"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user