bug fixed
This commit is contained in:
parent
d616ba2f50
commit
67fe4e288b
@ -75,12 +75,18 @@ export const DetailedOverview = ({ submission, onBack }) => {
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
const response = await fetchSubmissionDetail(submission.id);
|
const response = await fetchSubmissionDetail(submission.id);
|
||||||
|
console.log('Submission Detail API Response:', response); // Add this line
|
||||||
if (response && response.data) {
|
if (response && response.data) {
|
||||||
setSubmissionData(response.data);
|
setSubmissionData(response.data);
|
||||||
setQuarterPeriods(response.quarter_periods);
|
setQuarterPeriods(response.quarter_periods);
|
||||||
|
|
||||||
// Log the products array to verify it's being set correctly
|
// Log the products array to verify it's being set correctly
|
||||||
|
// Store quarter_window.end_date in localStorage
|
||||||
|
if (response.quarter_window?.end_date) {
|
||||||
|
localStorage.setItem('quarterWindowEndDate', response.quarter_window.end_date);
|
||||||
|
console.log('Stored quarter_window.end_date in localStorage');
|
||||||
|
}
|
||||||
if (response.data.products) {
|
if (response.data.products) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ const getSafeEstablishmentId = () => {
|
|||||||
};
|
};
|
||||||
import { useNavigate, useLocation } from 'react-router-dom';
|
import { useNavigate, useLocation } from 'react-router-dom';
|
||||||
import { getEstablishmentProducts } from '../../../services/submissions/submissionService';
|
import { getEstablishmentProducts } from '../../../services/submissions/submissionService';
|
||||||
|
import { getEmirates } from '../../../services/masters/masterService';
|
||||||
import Table from '@/components/common/Table';
|
import Table from '@/components/common/Table';
|
||||||
|
|
||||||
const caretDownSrc = '/assets/images/CaretDown.svg';
|
const caretDownSrc = '/assets/images/CaretDown.svg';
|
||||||
@ -78,10 +79,8 @@ const defaultEmployeeInfo = {
|
|||||||
totalEmployees: '',
|
totalEmployees: '',
|
||||||
totalEmirati: '',
|
totalEmirati: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const getCurrentQuarterAndYear = () => {
|
const getCurrentQuarterAndYear = () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
@ -111,11 +110,42 @@ const EstablishmentInfo = ({
|
|||||||
const [products, setProducts] = React.useState([]);
|
const [products, setProducts] = React.useState([]);
|
||||||
const [loadingProducts, setLoadingProducts] = React.useState(false);
|
const [loadingProducts, setLoadingProducts] = React.useState(false);
|
||||||
const [productsError, setProductsError] = React.useState('');
|
const [productsError, setProductsError] = React.useState('');
|
||||||
|
const [emirates, setEmirates] = React.useState([]);
|
||||||
|
const [emirateName, setEmirateName] = React.useState('');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
// Use a ref to persist the survey data across re-renders
|
// Use a ref to persist the survey data across re-renders
|
||||||
const surveyDataRef = React.useRef(null);
|
const surveyDataRef = React.useRef(null);
|
||||||
|
|
||||||
|
// Fetch emirates on component mount
|
||||||
|
React.useEffect(() => {
|
||||||
|
const fetchEmiratesData = async () => {
|
||||||
|
try {
|
||||||
|
const response = await getEmirates();
|
||||||
|
if (response?.data) {
|
||||||
|
setEmirates(response.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching emirates:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchEmiratesData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Update emirate name when emirate ID or emirates list changes
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (data?.emirate && emirates.length > 0) {
|
||||||
|
const emirate = emirates.find(e => e.id === parseInt(data.emirate));
|
||||||
|
setEmirateName(emirate?.name || data.emirate);
|
||||||
|
} else if (data?.emirate) {
|
||||||
|
// If we have an emirate ID but no emirates list yet, keep the ID as fallback
|
||||||
|
setEmirateName(data.emirate);
|
||||||
|
} else {
|
||||||
|
setEmirateName('');
|
||||||
|
}
|
||||||
|
}, [data?.emirate, emirates]);
|
||||||
|
|
||||||
// Fetch establishment products
|
// Fetch establishment products
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const fetchProducts = async () => {
|
const fetchProducts = async () => {
|
||||||
@ -140,9 +170,9 @@ const EstablishmentInfo = ({
|
|||||||
|
|
||||||
fetchProducts();
|
fetchProducts();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const remarksresubmit = JSON.parse(localStorage.getItem('resubmissionData'))?.product?.remarks || '';
|
const remarksresubmit = JSON.parse(localStorage.getItem('resubmissionData'))?.product?.remarks || '';
|
||||||
localStorage.setItem('surveyRemarks', remarksresubmit)
|
localStorage.setItem('surveyRemarks', remarksresubmit)
|
||||||
|
|
||||||
const [surveyData, setSurveyData] = React.useState(() => {
|
const [surveyData, setSurveyData] = React.useState(() => {
|
||||||
// For resubmission, use the quarter/year from the submission data
|
// For resubmission, use the quarter/year from the submission data
|
||||||
@ -257,7 +287,7 @@ localStorage.setItem('surveyRemarks', remarksresubmit)
|
|||||||
try {
|
try {
|
||||||
// Get existing resubmission data if it exists
|
// Get existing resubmission data if it exists
|
||||||
const existingData = JSON.parse(localStorage.getItem('resubmissionData') || '{}');
|
const existingData = JSON.parse(localStorage.getItem('resubmissionData') || '{}');
|
||||||
|
console.log("existingData",existingData)
|
||||||
// Update with establishment data
|
// Update with establishment data
|
||||||
const updatedData = {
|
const updatedData = {
|
||||||
...existingData,
|
...existingData,
|
||||||
@ -276,6 +306,8 @@ localStorage.setItem('surveyRemarks', remarksresubmit)
|
|||||||
quarter: data.quarter || surveyData.quarter,
|
quarter: data.quarter || surveyData.quarter,
|
||||||
year: data.year || surveyData.year
|
year: data.year || surveyData.year
|
||||||
};
|
};
|
||||||
|
console.log("updatedData",updatedData)
|
||||||
|
|
||||||
|
|
||||||
// Save back to localStorage
|
// Save back to localStorage
|
||||||
localStorage.setItem('resubmissionData', JSON.stringify(updatedData));
|
localStorage.setItem('resubmissionData', JSON.stringify(updatedData));
|
||||||
@ -294,7 +326,7 @@ localStorage.setItem('surveyRemarks', remarksresubmit)
|
|||||||
industryCode: data.industryCode || '',
|
industryCode: data.industryCode || '',
|
||||||
licenseNumber: data.licenseNumber || '',
|
licenseNumber: data.licenseNumber || '',
|
||||||
isicCode: data.isicCode || '',
|
isicCode: data.isicCode || '',
|
||||||
emirate: data.emirate || '',
|
emirate: emirateName || '',
|
||||||
establishment_contact_email: data.establishment_contact_email || '',
|
establishment_contact_email: data.establishment_contact_email || '',
|
||||||
employeeInfo: {
|
employeeInfo: {
|
||||||
...defaultEmployeeInfo,
|
...defaultEmployeeInfo,
|
||||||
@ -302,7 +334,7 @@ localStorage.setItem('surveyRemarks', remarksresubmit)
|
|||||||
},
|
},
|
||||||
...data,
|
...data,
|
||||||
}),
|
}),
|
||||||
[data, surveyData.quarter, surveyData.year]
|
[data, surveyData.quarter, surveyData.year, emirateName]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleFieldChange = (field) => (event) => {
|
const handleFieldChange = (field) => (event) => {
|
||||||
@ -312,32 +344,19 @@ localStorage.setItem('surveyRemarks', remarksresubmit)
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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}`);
|
|
||||||
// };
|
|
||||||
const handleEditProfile = (e) => {
|
const handleEditProfile = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const establishmentId = localStorage.getItem('establishment_id');
|
const establishmentId = localStorage.getItem('establishment_id');
|
||||||
if (!establishmentId) {
|
if (!establishmentId) {
|
||||||
alert('No establishment ID found in session');
|
alert('No establishment ID found in session');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorage.setItem('returnTo', window.location.pathname);
|
localStorage.setItem('returnTo', window.location.pathname);
|
||||||
localStorage.setItem('edit_profile_from', 'EstablishmentUser');
|
localStorage.setItem('edit_profile_from', 'EstablishmentUser');
|
||||||
navigate(`/edit-profile/${establishmentId}`);
|
navigate(`/edit-profile/${establishmentId}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEmployeeChange = (field) => (event) => {
|
const handleEmployeeChange = (field) => (event) => {
|
||||||
onChange({
|
onChange({
|
||||||
@ -405,8 +424,19 @@ localStorage.setItem('surveyRemarks', remarksresubmit)
|
|||||||
day: 'numeric'
|
day: 'numeric'
|
||||||
})
|
})
|
||||||
) : (
|
) : (
|
||||||
<span className="#6C4527">Mar 31, 2026</span>
|
(() => {
|
||||||
)}
|
const endDate = localStorage.getItem('quarterWindowEndDate');
|
||||||
|
return endDate ? (
|
||||||
|
new Date(endDate).toLocaleDateString('en-US', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric'
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<span className="#6C4527">-</span>
|
||||||
|
);
|
||||||
|
})()
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
@ -554,10 +584,8 @@ localStorage.setItem('surveyRemarks', remarksresubmit)
|
|||||||
<Field
|
<Field
|
||||||
label="Emirate"
|
label="Emirate"
|
||||||
placeholder="Enter Emirate"
|
placeholder="Enter Emirate"
|
||||||
value={info.emirate}
|
value={emirateName}
|
||||||
onChange={handleFieldChange('emirate')}
|
|
||||||
disabled={true}
|
disabled={true}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@ -1194,26 +1194,28 @@ const location = useLocation();
|
|||||||
<div className="flex items-center space-x-1">
|
<div className="flex items-center space-x-1">
|
||||||
<img src={calendarIcon} alt="" className="h-4 w-4" />
|
<img src={calendarIcon} alt="" className="h-4 w-4" />
|
||||||
<span className="font-medium">Due:</span>
|
<span className="font-medium">Due:</span>
|
||||||
{(() => {
|
<span className="text-sm text-[#6C4527] whitespace-nowrap">
|
||||||
// Try to get endDate from localStorage first
|
{surveyData.endDate ? (
|
||||||
const savedSurveyPeriod = localStorage.getItem('currentSurveyPeriod');
|
new Date(surveyData.endDate).toLocaleDateString('en-US', {
|
||||||
let endDateToUse = surveyData.endDate;
|
year: 'numeric',
|
||||||
|
month: 'short',
|
||||||
if (savedSurveyPeriod) {
|
day: 'numeric'
|
||||||
const { endDate } = JSON.parse(savedSurveyPeriod);
|
})
|
||||||
endDateToUse = endDate || surveyData.endDate;
|
) : (
|
||||||
}
|
(() => {
|
||||||
|
const endDate = localStorage.getItem('quarterWindowEndDate');
|
||||||
return endDateToUse ? (
|
return endDate ? (
|
||||||
new Date(endDateToUse).toLocaleDateString('en-US', {
|
new Date(endDate).toLocaleDateString('en-US', {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: 'short',
|
month: 'short',
|
||||||
day: 'numeric'
|
day: 'numeric'
|
||||||
})
|
})
|
||||||
) : (
|
) : (
|
||||||
<span className="text-amber-600">-</span>
|
<span className="#6C4527">-</span>
|
||||||
);
|
);
|
||||||
})()}
|
})()
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center space-x-1">
|
<div className="flex items-center space-x-1">
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import Table from '@/components/common/Table';
|
import Table from '@/components/common/Table';
|
||||||
import { getQuarterPeriods } from '@/services/submissions/submissionService';
|
import { getQuarterPeriods } from '@/services/submissions/submissionService';
|
||||||
|
import { getEmirates } from '@/services/masters/masterService';
|
||||||
const caretUpSrc = '/assets/images/caret-up.svg';
|
const caretUpSrc = '/assets/images/caret-up.svg';
|
||||||
const caretDownSrc = '/assets/images/CaretDown-black.svg';
|
const caretDownSrc = '/assets/images/CaretDown-black.svg';
|
||||||
const establishmentIconSrc = '/assets/images/Establishment.svg';
|
const establishmentIconSrc = '/assets/images/Establishment.svg';
|
||||||
@ -56,13 +57,22 @@ const formatNumber = (value) => {
|
|||||||
return new Intl.NumberFormat('en-US').format(number);
|
return new Intl.NumberFormat('en-US').format(number);
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildEstablishmentDetails = (establishment) => {
|
const buildEstablishmentDetails = (establishment, emirateName) => {
|
||||||
if (!establishment) return [];
|
if (!establishment) return [];
|
||||||
|
let userEmail = '';
|
||||||
|
try {
|
||||||
|
const userProfile = JSON.parse(localStorage.getItem('user_profile'));
|
||||||
|
userEmail = userProfile?.email || '';
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error parsing user profile from localStorage:', e);
|
||||||
|
}
|
||||||
|
const email = establishment.establishment_contact_email || userEmail || '';
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{ icon: establishmentIconSrc, label: 'Establishment Name', value: establishment.establishmentName },
|
{ icon: establishmentIconSrc, label: 'Establishment Name', value: establishment.establishmentName },
|
||||||
{ icon: establishmentIdIconSrc, label: 'Establishment ID', value: establishment.licenseNumber },
|
{ icon: establishmentIdIconSrc, label: 'Establishment ID', value: establishment.licenseNumber },
|
||||||
{ icon: emailIconSrc, label: 'Email', value: establishment.establishment_contact_email },
|
{ icon: emailIconSrc, label: 'Email', value: email },
|
||||||
{ icon: emiratesIconSrc, label: 'Emirate', value: establishment.emirate },
|
{ icon: emiratesIconSrc, label: 'Emirate', value: emirateName || establishment.emirate },
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -346,6 +356,35 @@ const ReviewSubmit = ({
|
|||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
const [confirm, setConfirm] = React.useState(false);
|
const [confirm, setConfirm] = React.useState(false);
|
||||||
|
const [emirates, setEmirates] = useState([]);
|
||||||
|
const [emirateName, setEmirateName] = useState('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchEmiratesData = async () => {
|
||||||
|
try {
|
||||||
|
const response = await getEmirates();
|
||||||
|
if (response?.data) {
|
||||||
|
setEmirates(response.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching emirates:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchEmiratesData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (establishment?.emirate && emirates.length > 0) {
|
||||||
|
const emirate = emirates.find(e => e.id === parseInt(establishment.emirate));
|
||||||
|
setEmirateName(emirate?.name || establishment.emirate);
|
||||||
|
} else if (establishment?.emirate) {
|
||||||
|
// Fallback to ID if emirates list is not yet loaded
|
||||||
|
setEmirateName(establishment.emirate);
|
||||||
|
} else {
|
||||||
|
setEmirateName('');
|
||||||
|
}
|
||||||
|
}, [establishment?.emirate, emirates]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchQuarterPeriods = async () => {
|
const fetchQuarterPeriods = async () => {
|
||||||
@ -405,7 +444,7 @@ const ReviewSubmit = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const establishmentDetails = React.useMemo(() => buildEstablishmentDetails(establishment), [establishment]);
|
const establishmentDetails = React.useMemo(() => buildEstablishmentDetails(establishment, emirateName), [establishment, emirateName]);
|
||||||
const employmentDetails = React.useMemo(() => buildEmploymentDetails(establishment), [establishment]);
|
const employmentDetails = React.useMemo(() => buildEmploymentDetails(establishment), [establishment]);
|
||||||
const productRows = React.useMemo(() => buildProductRows(products), [products]);
|
const productRows = React.useMemo(() => buildProductRows(products), [products]);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user