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