issue fixed
This commit is contained in:
parent
106ceca31c
commit
0f279bbded
@ -287,9 +287,17 @@ const handleDeleteDraft = async (e, submission) => {
|
|||||||
<button
|
<button
|
||||||
onClick={() => handleViewDetails(item)}
|
onClick={() => handleViewDetails(item)}
|
||||||
className="text-[#9E792B] hover:text-[#7b5f22] font-medium"
|
className="text-[#9E792B] hover:text-[#7b5f22] font-medium"
|
||||||
|
title="View Details"
|
||||||
>
|
>
|
||||||
View Details
|
<img
|
||||||
</button>
|
src="/assets/images/Eye.svg"
|
||||||
|
alt="View Details"
|
||||||
|
className="w-5 h-5 text-[#92722A] opacity-60 hover:opacity-100 transition-opacity"
|
||||||
|
style={{ filter: 'invert(36%) sepia(49%) saturate(680%) hue-rotate(1deg) brightness(89%) contrast(91%)' }}
|
||||||
|
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
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 , resubmitSurvey } from '@/services/submissions/submissionService';
|
import { getQuarterPeriods , submitSurvey, resubmitSurvey } from '@/services/submissions/submissionService';
|
||||||
import { getEmirates, fetchVariationReasons, fetchZeroTargetReasons } from '@/services/masters/masterService';
|
import { getEmirates, fetchVariationReasons, fetchZeroTargetReasons } 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';
|
||||||
@ -523,10 +523,19 @@ if (!establishment) {
|
|||||||
const formattedProducts = products.map(product => {
|
const formattedProducts = products.map(product => {
|
||||||
// Get the selected product option to access product_id
|
// Get the selected product option to access product_id
|
||||||
const selectedProduct = productOptions.find(p => p.value === product.product);
|
const selectedProduct = productOptions.find(p => p.value === product.product);
|
||||||
const existingProduct = currentSubmission.products?.find(p =>
|
const existingProduct = currentSubmission.products?.find(p =>
|
||||||
p.product_id === product.product_id ||
|
p.product_id === (selectedProduct?.product_id || product.product_id) ||
|
||||||
p.product?.id === product.product_id
|
p.product?.id === (selectedProduct?.product_id || product.product_id)
|
||||||
);
|
);
|
||||||
|
console.log('Existing product match:', {
|
||||||
|
productId: product.id,
|
||||||
|
productProductId: product.product_id,
|
||||||
|
selectedProductId: selectedProduct?.product_id,
|
||||||
|
foundExistingProduct: !!existingProduct,
|
||||||
|
existingProductId: existingProduct?.id,
|
||||||
|
existingProductProductId: existingProduct?.product_id,
|
||||||
|
allExistingProductIds: currentSubmission.products?.map(p => p.id) || []
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
id: existingProduct?.id || 0,
|
id: existingProduct?.id || 0,
|
||||||
product_id: selectedProduct?.product_id || product.product_id || null,
|
product_id: selectedProduct?.product_id || product.product_id || null,
|
||||||
@ -589,23 +598,36 @@ if (!establishment) {
|
|||||||
if (submissionId) {
|
if (submissionId) {
|
||||||
// Update existing submission
|
// Update existing submission
|
||||||
response = await resubmitSurvey(submissionId, payload);
|
response = await resubmitSurvey(submissionId, payload);
|
||||||
alert('Draft updated successfully');
|
alert('Draft updated successfully')
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Create new submission
|
// Create new submission
|
||||||
response = await submitSurvey(payload);
|
response = await submitSurvey(payload);
|
||||||
|
|
||||||
// Update local storage with the new submission ID if this was a create operation
|
// Update local storage with the new submission ID if this was a create operation
|
||||||
if (response && response.id) {
|
if (response && response.submission_data) {
|
||||||
const updatedSubmission = { ...currentSubmission, id: response.id };
|
localStorage.setItem('currentSubmission', JSON.stringify(response.submission_data));
|
||||||
localStorage.setItem('currentSubmission', JSON.stringify(updatedSubmission));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
alert('Draft saved successfully')
|
alert('Draft saved successfully')
|
||||||
}
|
}
|
||||||
|
// Add this debug log
|
||||||
|
console.log('API Response:', {
|
||||||
|
status: response?.status,
|
||||||
|
data: response?.data,
|
||||||
|
submissionId: submissionId
|
||||||
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error saving draft:', error);
|
console.error('Error details:', {
|
||||||
|
message: error.message,
|
||||||
|
response: error.response?.data,
|
||||||
|
status: error.response?.status,
|
||||||
|
config: {
|
||||||
|
url: error.config?.url,
|
||||||
|
method: error.config?.method,
|
||||||
|
data: error.config?.data
|
||||||
|
}
|
||||||
|
});
|
||||||
alert(error.message || 'Failed to save draft');
|
alert(error.message || 'Failed to save draft');
|
||||||
} finally {
|
} finally {
|
||||||
setIsSavingDraft(false);
|
setIsSavingDraft(false);
|
||||||
|
|||||||
@ -182,7 +182,13 @@ const handleDeleteDraft = async (e, record) => {
|
|||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : 'View Details',
|
) :
|
||||||
|
<img
|
||||||
|
src="/assets/images/Eye.svg"
|
||||||
|
alt="View Details"
|
||||||
|
className="w-5 h-5 text-[#92722A] opacity-60 hover:opacity-100 transition-opacity"
|
||||||
|
style={{ filter: 'invert(36%) sepia(49%) saturate(680%) hue-rotate(1deg) brightness(89%) contrast(91%)' }}
|
||||||
|
/>
|
||||||
]);
|
]);
|
||||||
}, [filteredRows, uae_currency]);
|
}, [filteredRows, uae_currency]);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user