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 { Link, useNavigate, useParams, useLocation } from 'react-router-dom';
|
||||||
import AdminHeader from '@/components/admin/AdminHeader';
|
import AdminHeader from '@/components/admin/AdminHeader';
|
||||||
import { getSubmissionById } from '@/services/admin/submission';
|
import { getSubmissionById } from '@/services/admin/submission';
|
||||||
@ -7,6 +7,7 @@ import { getBeforePreviousData, getQuarterPeriods } from '@/services/submissions
|
|||||||
import { getProductSubmissionHistory } from '@/services/submissions/submissionService';
|
import { getProductSubmissionHistory } from '@/services/submissions/submissionService';
|
||||||
import { Line } from 'react-chartjs-2';
|
import { Line } from 'react-chartjs-2';
|
||||||
import { IoIosArrowBack } from "react-icons/io";
|
import { IoIosArrowBack } from "react-icons/io";
|
||||||
|
import { getEmirates } from '@/services/masters/masterService';
|
||||||
|
|
||||||
|
|
||||||
// Helper function to get months for quarter
|
// Helper function to get months for quarter
|
||||||
@ -26,6 +27,8 @@ const ProductChart = ({ product, establishmentId }) => {
|
|||||||
const [loading, setLoading] = React.useState(true);
|
const [loading, setLoading] = React.useState(true);
|
||||||
const [error, setError] = React.useState(null);
|
const [error, setError] = React.useState(null);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const fetchProductHistory = async () => {
|
const fetchProductHistory = async () => {
|
||||||
if (!establishmentId || !product?.product?.id) return;
|
if (!establishmentId || !product?.product?.id) return;
|
||||||
@ -353,6 +356,9 @@ const femaleEmployeesIconSrc = '/assets/images/femaleemployess.svg';
|
|||||||
const uaeIconSrc = '/assets/images/uae.svg';
|
const uaeIconSrc = '/assets/images/uae.svg';
|
||||||
const nonUaeIconSrc = '/assets/images/nonuae.svg';
|
const nonUaeIconSrc = '/assets/images/nonuae.svg';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const employmentIcons = {
|
const employmentIcons = {
|
||||||
'Total Employees': totalEmployeesIconSrc,
|
'Total Employees': totalEmployeesIconSrc,
|
||||||
'Male Employees': maleEmployeesIconSrc,
|
'Male Employees': maleEmployeesIconSrc,
|
||||||
@ -385,6 +391,7 @@ const ValidationReview = () => {
|
|||||||
const [additionalForecastQuarter, setAdditionalForecastQuarter] = React.useState('');
|
const [additionalForecastQuarter, setAdditionalForecastQuarter] = React.useState('');
|
||||||
const [additionalForecastYear, setAdditionalForecastYear] = React.useState('');
|
const [additionalForecastYear, setAdditionalForecastYear] = React.useState('');
|
||||||
const [additionalForecastMonths, setAdditionalForecastMonths] = React.useState(['', '', '']);
|
const [additionalForecastMonths, setAdditionalForecastMonths] = React.useState(['', '', '']);
|
||||||
|
const [emirates, setEmirates] = useState([]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const fetchSubmission = async () => {
|
const fetchSubmission = async () => {
|
||||||
@ -446,6 +453,20 @@ const ValidationReview = () => {
|
|||||||
fetchSubmission();
|
fetchSubmission();
|
||||||
}, [id]);
|
}, [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
|
// Function to generate year labels for each quarter
|
||||||
const generateYearLabels = (quarterPeriods) => {
|
const generateYearLabels = (quarterPeriods) => {
|
||||||
if (!quarterPeriods) return null;
|
if (!quarterPeriods) return null;
|
||||||
@ -686,6 +707,7 @@ setAdditionalForecastMonths([
|
|||||||
navigate('/admin/validations', {
|
navigate('/admin/validations', {
|
||||||
state: {
|
state: {
|
||||||
showSuccessToast: true,
|
showSuccessToast: true,
|
||||||
|
toastType: 'error',
|
||||||
successMessage: `${establishmentName} has been rejected successfully.`
|
successMessage: `${establishmentName} has been rejected successfully.`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -892,7 +914,8 @@ setAdditionalForecastMonths([
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Emirate',
|
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(() => {
|
React.useEffect(() => {
|
||||||
if (location.state?.showSuccessToast && location.state?.successMessage) {
|
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);
|
window.history.replaceState({}, document.title);
|
||||||
}
|
}
|
||||||
}, [location.state, showToast]);
|
}, [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 ?? {};
|
config.headers = config.headers ?? {};
|
||||||
|
|
||||||
// Skip auth for CSRF token endpoint
|
// Skip auth for CSRF token endpoint
|
||||||
@ -41,8 +41,25 @@ apiClient.interceptors.request.use((config) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add CSRF token for write operations
|
// Add CSRF token for write operations
|
||||||
if (csrfToken && ['post', 'put', 'patch', 'delete'].includes(config.method?.toLowerCase())) {
|
const isWriteOperation = ['post', 'put', 'patch', 'delete'].includes(config.method?.toLowerCase());
|
||||||
config.headers['X-CSRF-Token'] = csrfToken;
|
|
||||||
|
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) {
|
if (config.skipAuth) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user