issue fixed
This commit is contained in:
parent
d93689735e
commit
5d7c5a1a82
@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState , useEffect} from 'react';
|
||||
import { Link, useNavigate, useParams, useLocation } from 'react-router-dom';
|
||||
import AdminHeader from '@/components/admin/AdminHeader';
|
||||
import { getSubmissionById } from '@/services/admin/submission';
|
||||
@ -7,6 +7,7 @@ import { getBeforePreviousData, getQuarterPeriods } from '@/services/submissions
|
||||
import { getProductSubmissionHistory } from '@/services/submissions/submissionService';
|
||||
import { Line } from 'react-chartjs-2';
|
||||
import { IoIosArrowBack } from "react-icons/io";
|
||||
import { getEmirates } from '@/services/masters/masterService';
|
||||
|
||||
|
||||
// Helper function to get months for quarter
|
||||
@ -26,6 +27,8 @@ const ProductChart = ({ product, establishmentId }) => {
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
const [error, setError] = React.useState(null);
|
||||
|
||||
|
||||
|
||||
React.useEffect(() => {
|
||||
const fetchProductHistory = async () => {
|
||||
if (!establishmentId || !product?.product?.id) return;
|
||||
@ -353,6 +356,9 @@ const femaleEmployeesIconSrc = '/assets/images/femaleemployess.svg';
|
||||
const uaeIconSrc = '/assets/images/uae.svg';
|
||||
const nonUaeIconSrc = '/assets/images/nonuae.svg';
|
||||
|
||||
|
||||
|
||||
|
||||
const employmentIcons = {
|
||||
'Total Employees': totalEmployeesIconSrc,
|
||||
'Male Employees': maleEmployeesIconSrc,
|
||||
@ -385,6 +391,7 @@ const ValidationReview = () => {
|
||||
const [additionalForecastQuarter, setAdditionalForecastQuarter] = React.useState('');
|
||||
const [additionalForecastYear, setAdditionalForecastYear] = React.useState('');
|
||||
const [additionalForecastMonths, setAdditionalForecastMonths] = React.useState(['', '', '']);
|
||||
const [emirates, setEmirates] = useState([]);
|
||||
|
||||
React.useEffect(() => {
|
||||
const fetchSubmission = async () => {
|
||||
@ -446,6 +453,20 @@ const ValidationReview = () => {
|
||||
fetchSubmission();
|
||||
}, [id]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchEmirates = async () => {
|
||||
try {
|
||||
const response = await getEmirates();
|
||||
if (response?.data) {
|
||||
setEmirates(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching emirates:', error);
|
||||
}
|
||||
};
|
||||
fetchEmirates();
|
||||
}, []);
|
||||
|
||||
// Function to generate year labels for each quarter
|
||||
const generateYearLabels = (quarterPeriods) => {
|
||||
if (!quarterPeriods) return null;
|
||||
@ -686,6 +707,7 @@ setAdditionalForecastMonths([
|
||||
navigate('/admin/validations', {
|
||||
state: {
|
||||
showSuccessToast: true,
|
||||
toastType: 'error',
|
||||
successMessage: `${establishmentName} has been rejected successfully.`
|
||||
}
|
||||
});
|
||||
@ -892,7 +914,8 @@ setAdditionalForecastMonths([
|
||||
},
|
||||
{
|
||||
label: 'Emirate',
|
||||
value: establishment.establishment_address || '—'
|
||||
value: emirates.find(e => e.id === establishment.establishment_emirate_id)?.name || '—'
|
||||
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@ -294,7 +294,7 @@ React.useEffect(() => {
|
||||
|
||||
React.useEffect(() => {
|
||||
if (location.state?.showSuccessToast && location.state?.successMessage) {
|
||||
showToast('success', location.state.successMessage);
|
||||
showToast(location.state.toastType || 'success', location.state.successMessage);
|
||||
window.history.replaceState({}, document.title);
|
||||
}
|
||||
}, [location.state, showToast]);
|
||||
|
||||
@ -32,7 +32,7 @@ export const fetchCsrfToken = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
apiClient.interceptors.request.use((config) => {
|
||||
apiClient.interceptors.request.use(async (config) => {
|
||||
config.headers = config.headers ?? {};
|
||||
|
||||
// Skip auth for CSRF token endpoint
|
||||
@ -41,8 +41,25 @@ apiClient.interceptors.request.use((config) => {
|
||||
}
|
||||
|
||||
// Add CSRF token for write operations
|
||||
if (csrfToken && ['post', 'put', 'patch', 'delete'].includes(config.method?.toLowerCase())) {
|
||||
config.headers['X-CSRF-Token'] = csrfToken;
|
||||
const isWriteOperation = ['post', 'put', 'patch', 'delete'].includes(config.method?.toLowerCase());
|
||||
|
||||
if (isWriteOperation) {
|
||||
// Ensure we have a CSRF token before making write requests
|
||||
if (!csrfToken) {
|
||||
try {
|
||||
await fetchCsrfToken();
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch CSRF token:', error);
|
||||
return Promise.reject('Failed to fetch CSRF token');
|
||||
}
|
||||
}
|
||||
|
||||
if (csrfToken) {
|
||||
config.headers['X-CSRF-Token'] = csrfToken;
|
||||
} else {
|
||||
console.error('No CSRF token available for write operation');
|
||||
return Promise.reject('No CSRF token available');
|
||||
}
|
||||
}
|
||||
|
||||
if (config.skipAuth) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user