changed in resumitted
This commit is contained in:
parent
601e967c01
commit
8c708f9bd7
@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState, useMemo } from 'react';
|
||||
|
||||
|
||||
// Get and encode establishment ID for URL
|
||||
const getSafeEstablishmentId = () => {
|
||||
const establishmentId = localStorage.getItem('establishment_id') || '';
|
||||
@ -8,7 +8,7 @@ const getSafeEstablishmentId = () => {
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
import { getEstablishmentProducts } from '../../../services/submissions/submissionService';
|
||||
import Table from '@/components/common/Table';
|
||||
|
||||
|
||||
const caretDownSrc = '/assets/images/CaretDown.svg';
|
||||
const backVectorSrc = '/assets/images/BackVector.svg';
|
||||
const mailIconSrc = '/assets/images/material-symbols_mail-outline.svg';
|
||||
@ -16,7 +16,7 @@ const phoneIconSrc = '/assets/images/line-md_phone.svg';
|
||||
const calendarIcon = '/assets/images/Duedate.svg';
|
||||
const clockIcon = '/assets/images/mingcute_time-line.svg';
|
||||
const nextIcon = '/assets/images/mdi_page-next-outline.svg';
|
||||
|
||||
|
||||
const Field = ({ label, placeholder = '', type = 'text', value = '', onChange = () => {}, disabled = true }) => (
|
||||
<div>
|
||||
<label className={`block text-sm font-medium ${disabled ? 'text-[#9EA2A9]' : 'text-gray-700'} mb-1`}>
|
||||
@ -32,7 +32,7 @@ const Field = ({ label, placeholder = '', type = 'text', value = '', onChange =
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
const Select = ({ label, options = [], value = '', placeholder = 'Select option', onChange = () => {}, disabled = true }) => (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">{label}</label>
|
||||
@ -61,7 +61,7 @@ const Select = ({ label, options = [], value = '', placeholder = 'Select option'
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
const Card = ({ children }) => (
|
||||
<div className="bg-white rounded-md shadow-sm ring-1 ring-gray-200">
|
||||
<div className="p-5">
|
||||
@ -69,7 +69,7 @@ const Card = ({ children }) => (
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
const defaultEmployeeInfo = {
|
||||
emiratiMale: '',
|
||||
nonEmiratiMale: '',
|
||||
@ -78,22 +78,22 @@ const defaultEmployeeInfo = {
|
||||
totalEmployees: '',
|
||||
totalEmirati: '',
|
||||
};
|
||||
|
||||
|
||||
const getCurrentQuarterAndYear = () => {
|
||||
const now = new Date();
|
||||
const currentQuarter = Math.ceil((now.getMonth() + 1) / 3);
|
||||
const currentYear = now.getFullYear();
|
||||
|
||||
|
||||
// Calculate end of quarter date
|
||||
const endOfQuarter = new Date(currentYear, currentQuarter * 3, 0); // Last day of the last month in quarter
|
||||
|
||||
|
||||
return {
|
||||
quarter: `Q${currentQuarter}`,
|
||||
year: currentYear,
|
||||
endDate: endOfQuarter.toISOString() // Return as ISO string for consistency
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const EstablishmentInfo = ({
|
||||
data = {},
|
||||
onChange = () => {},
|
||||
@ -111,13 +111,13 @@ const EstablishmentInfo = ({
|
||||
const location = useLocation();
|
||||
// Use a ref to persist the survey data across re-renders
|
||||
const surveyDataRef = React.useRef(null);
|
||||
|
||||
|
||||
// Fetch establishment products
|
||||
React.useEffect(() => {
|
||||
const fetchProducts = async () => {
|
||||
const establishmentId = localStorage.getItem('establishment_id');
|
||||
if (!establishmentId) return;
|
||||
|
||||
|
||||
setLoadingProducts(true);
|
||||
try {
|
||||
const response = await getEstablishmentProducts(establishmentId);
|
||||
@ -133,89 +133,120 @@ const EstablishmentInfo = ({
|
||||
setLoadingProducts(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
fetchProducts();
|
||||
}, []);
|
||||
|
||||
|
||||
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
|
||||
|
||||
// Fallback to current quarter/year
|
||||
const current = getCurrentQuarterAndYear();
|
||||
|
||||
// Save to localStorage
|
||||
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
|
||||
React.useEffect(() => {
|
||||
}, [surveyData]);
|
||||
|
||||
|
||||
// Update the ref whenever surveyData changes
|
||||
React.useEffect(() => {
|
||||
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 || '',
|
||||
year: year || '',
|
||||
endDate: endDate || ''
|
||||
};
|
||||
|
||||
setSurveyData(newSurveyData);
|
||||
|
||||
// Update the parent component with the survey data
|
||||
onChange({
|
||||
...data,
|
||||
quarter: newSurveyData.quarter,
|
||||
year: newSurveyData.year,
|
||||
end_date: newSurveyData.endDate
|
||||
});
|
||||
|
||||
// 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;
|
||||
}
|
||||
// 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);
|
||||
};
|
||||
|
||||
|
||||
// Store establishment data in localStorage during resubmission
|
||||
React.useEffect(() => {
|
||||
// Check if this is a resubmission
|
||||
const isResubmit = location.state?.fromResubmit;
|
||||
|
||||
|
||||
if (isResubmit && data) {
|
||||
try {
|
||||
// Get existing resubmission data if it exists
|
||||
const existingData = JSON.parse(localStorage.getItem('resubmissionData') || '{}');
|
||||
|
||||
|
||||
// Update with establishment data
|
||||
const updatedData = {
|
||||
...existingData,
|
||||
@ -234,7 +265,7 @@ const EstablishmentInfo = ({
|
||||
quarter: data.quarter || surveyData.quarter,
|
||||
year: data.year || surveyData.year
|
||||
};
|
||||
|
||||
|
||||
// Save back to localStorage
|
||||
localStorage.setItem('resubmissionData', JSON.stringify(updatedData));
|
||||
} catch (error) {
|
||||
@ -242,7 +273,7 @@ const EstablishmentInfo = ({
|
||||
}
|
||||
}
|
||||
}, [data, location.state?.fromResubmit, surveyData.quarter, surveyData.year]);
|
||||
|
||||
|
||||
const info = React.useMemo(
|
||||
() => ({
|
||||
quarter: surveyData.quarter || '',
|
||||
@ -262,23 +293,23 @@ const EstablishmentInfo = ({
|
||||
}),
|
||||
[data, surveyData.quarter, surveyData.year]
|
||||
);
|
||||
|
||||
|
||||
const handleFieldChange = (field) => (event) => {
|
||||
onChange({
|
||||
...info,
|
||||
[field]: event.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// const handleEditProfile = (e) => {
|
||||
// e.preventDefault();
|
||||
|
||||
|
||||
// const establishmentId = sessionStorage.getItem('establishment_id');
|
||||
// if (!establishmentId) {
|
||||
// alert('No establishment ID found in session');
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
// localStorage.setItem('returnTo', window.location.pathname);
|
||||
// sessionStorage.setItem('edit_profile_from', 'EstablishmentUser');
|
||||
// // navigate(`/profile/edit/${establishmentId}`);
|
||||
@ -306,7 +337,7 @@ const EstablishmentInfo = ({
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div className="space-y-6 relative">
|
||||
{loading && (
|
||||
@ -317,7 +348,7 @@ const EstablishmentInfo = ({
|
||||
<h2 className="text-xl font-semibold text-[#232528] mb-2">
|
||||
IIP (Index of Industrial Production): {surveyData.quarter} {surveyData.year}
|
||||
</h2>
|
||||
|
||||
|
||||
{/* Survey Information */}
|
||||
{!showInfoCard && (
|
||||
<button
|
||||
@ -332,7 +363,7 @@ const EstablishmentInfo = ({
|
||||
)}
|
||||
{showInfoCard && (
|
||||
<div className="bg-[#F2ECCF] p-5 rounded-md shadow-sm ring-1 ring-gray-200 relative mb-6">
|
||||
<button
|
||||
<button
|
||||
onClick={handleCloseInfo}
|
||||
className="absolute right-4 top-4 text-gray-500 hover:text-gray-700 focus:outline-none"
|
||||
aria-label="Close information"
|
||||
@ -341,12 +372,12 @@ const EstablishmentInfo = ({
|
||||
<path fillRule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clipRule="evenodd" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-[#6C4527] mb-4">
|
||||
You're completing the <b>IIP Quarterly Survey</b> for <b>{surveyData.quarter} {surveyData.year}</b>. This step shows establishment details already registered with us. <b>Step 1 is read-only.</b> To make corrections, update them in <b>Profile → Edit Profile</b>, then return to this survey.
|
||||
</p>
|
||||
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
@ -400,13 +431,13 @@ const EstablishmentInfo = ({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<h2 className="text-lg font-semibold text-[#232528]">Step 1: Review Establishment Information</h2>
|
||||
{isComplete && (
|
||||
<img
|
||||
src="/assets/images/CircleFrame.svg"
|
||||
alt="Completed"
|
||||
<img
|
||||
src="/assets/images/CircleFrame.svg"
|
||||
alt="Completed"
|
||||
className="w-5 h-5"
|
||||
/>
|
||||
)}
|
||||
@ -431,10 +462,10 @@ const EstablishmentInfo = ({
|
||||
<option key={quarter} value={quarter}>{quarter}</option>
|
||||
))}
|
||||
</select>
|
||||
<img
|
||||
src={caretDownSrc}
|
||||
alt="open"
|
||||
className="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4"
|
||||
<img
|
||||
src={caretDownSrc}
|
||||
alt="open"
|
||||
className="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@ -445,7 +476,7 @@ const EstablishmentInfo = ({
|
||||
value={surveyData.year}
|
||||
onChange={handleFieldChange('year')}
|
||||
disabled={true}
|
||||
|
||||
|
||||
className="block w-full h-10 rounded-md border-2 border-[#E6D7A2] focus:border-[#92722A] focus:ring-0 px-4 pr-10 text-sm bg-white text-[#9EA2A9] appearance-none cursor-not-allowed"
|
||||
>
|
||||
<option value="" disabled>Select year</option>
|
||||
@ -453,17 +484,17 @@ const EstablishmentInfo = ({
|
||||
<option key={year} value={year}>{year}</option>
|
||||
))}
|
||||
</select>
|
||||
<img
|
||||
src={caretDownSrc}
|
||||
alt="open"
|
||||
className="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4"
|
||||
<img
|
||||
src={caretDownSrc}
|
||||
alt="open"
|
||||
className="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Establishment Information Form */}
|
||||
<Card>
|
||||
<h3 className="text-sm font-semibold text-gray-900 mb-4">Establishment Information</h3>
|
||||
@ -474,7 +505,7 @@ const EstablishmentInfo = ({
|
||||
value={info.establishmentName}
|
||||
onChange={handleFieldChange('establishmentName')}
|
||||
disabled={true}
|
||||
|
||||
|
||||
/>
|
||||
<Field
|
||||
label="Permanent Factory Code(PFC)"
|
||||
@ -482,7 +513,7 @@ const EstablishmentInfo = ({
|
||||
value={info.permanentFactoryCode}
|
||||
onChange={handleFieldChange('permanentFactoryCode')}
|
||||
disabled={true}
|
||||
|
||||
|
||||
/>
|
||||
<Field
|
||||
label="Business Register Industry Code"
|
||||
@ -490,7 +521,7 @@ const EstablishmentInfo = ({
|
||||
value={info.industryCode}
|
||||
onChange={handleFieldChange('industryCode')}
|
||||
disabled={true}
|
||||
|
||||
|
||||
/>
|
||||
<Field
|
||||
label="License Number"
|
||||
@ -498,7 +529,7 @@ const EstablishmentInfo = ({
|
||||
value={info.licenseNumber}
|
||||
onChange={handleFieldChange('licenseNumber')}
|
||||
disabled={true}
|
||||
|
||||
|
||||
/>
|
||||
{/* Email field is hidden but data remains in form state */}
|
||||
<Field
|
||||
@ -507,7 +538,7 @@ const EstablishmentInfo = ({
|
||||
value={info.isicCode}
|
||||
onChange={handleFieldChange('isicCode')}
|
||||
disabled={true}
|
||||
|
||||
|
||||
/>
|
||||
<Field
|
||||
label="Emirate"
|
||||
@ -515,11 +546,11 @@ const EstablishmentInfo = ({
|
||||
value={info.emirate}
|
||||
onChange={handleFieldChange('emirate')}
|
||||
disabled={true}
|
||||
|
||||
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
|
||||
<Card className="mt-10">
|
||||
<h3 className="text-sm font-semibold text-gray-900 mb-4">Products</h3>
|
||||
{loadingProducts ? (
|
||||
@ -544,7 +575,7 @@ const EstablishmentInfo = ({
|
||||
<div className="text-gray-500 text-sm py-2">No products found for this establishment.</div>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
|
||||
<div className="mt-6">
|
||||
{/* Employee Information */}
|
||||
<Card>
|
||||
@ -600,7 +631,7 @@ const EstablishmentInfo = ({
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
|
||||
{/* <Card className="mt-10">
|
||||
<h3 className="text-sm font-semibold text-gray-900 mb-4">Products</h3>
|
||||
{loadingProducts ? (
|
||||
@ -653,8 +684,8 @@ const EstablishmentInfo = ({
|
||||
)}
|
||||
</Card> */}
|
||||
{/* Products Table */}
|
||||
|
||||
|
||||
|
||||
|
||||
{/* Blue Info Box */}
|
||||
<div className="bg-[#E8F3FF] border border-[#2F80ED] text-[#0B4DA2] px-4 py-2 rounded-md mt-3 flex items-center gap-2 text-sm">
|
||||
<svg
|
||||
@ -684,7 +715,7 @@ const EstablishmentInfo = ({
|
||||
href={`/admin/configuration/profile/edit=${sessionStorage.getItem('establishment_id') || ''}`}
|
||||
className="underline font-medium text-[#043DFF] hover:text-[#063B82]"
|
||||
onClick={handleEditProfile}
|
||||
|
||||
|
||||
>
|
||||
Edit Profile
|
||||
</a>
|
||||
@ -699,11 +730,11 @@ const EstablishmentInfo = ({
|
||||
>
|
||||
Edit Profile
|
||||
</a>
|
||||
|
||||
|
||||
. Changes saved there will appear here.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Footer actions */}
|
||||
<div className="mt-8 flex flex-col sm:flex-row justify-between gap-3">
|
||||
<button
|
||||
@ -724,7 +755,7 @@ const EstablishmentInfo = ({
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
{(loading || error) && (
|
||||
<div className="mt-3">
|
||||
{loading && <p className="text-sm text-[#5F646D]">Loading establishment information…</p>}
|
||||
@ -735,5 +766,5 @@ const EstablishmentInfo = ({
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default EstablishmentInfo;
|
||||
|
||||
export default EstablishmentInfo;
|
||||
@ -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,9 +42,9 @@ 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 || '',
|
||||
industryCodeMismatchRemarks: data.industry_code_mismatch_remarks || '',
|
||||
industryCodeBusiness: data.industry_code || '',
|
||||
industryCodeCurrent: data.isic_code || '',
|
||||
industryCodeMismatchRemarks: data.industry_code_mismatch_remarks || '',
|
||||
contactName: data.factory_name || '',
|
||||
contactAddress: data.establishment_address || '',
|
||||
contactCityTown: data.establishment_city?.name || '',
|
||||
@ -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