removed console
This commit is contained in:
parent
a5915b8a41
commit
df35fdcc50
@ -507,9 +507,7 @@ useEffect(() => {
|
||||
if (resubmissionData) {
|
||||
const parsedData = JSON.parse(resubmissionData);
|
||||
|
||||
if (parsedData.products && Array.isArray(parsedData.products) && parsedData.products.length > 0) {
|
||||
console.log('Loading resubmission products:', parsedData.products);
|
||||
|
||||
if (parsedData.products && Array.isArray(parsedData.products) && parsedData.products.length > 0) {
|
||||
// Wait for product options to be loaded
|
||||
if (productOptions.length === 0) {
|
||||
await new Promise(resolve => {
|
||||
@ -575,10 +573,7 @@ useEffect(() => {
|
||||
isResubmitted: true,
|
||||
originalData: product
|
||||
};
|
||||
}));
|
||||
|
||||
console.log('Mapped products for resubmission:', mappedProducts);
|
||||
|
||||
}));
|
||||
// Update the products state with the mapped products
|
||||
if (mappedProducts.length > 0) {
|
||||
onProductsChange(mappedProducts);
|
||||
@ -688,15 +683,6 @@ const existingProduct = currentSubmission.products?.find(p =>
|
||||
p.product_id === (selectedProduct?.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 {
|
||||
id: existingProduct?.id || 0,
|
||||
product_id: selectedProduct?.product_id || product.product_id || null,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import Table from '@/components/common/Table';
|
||||
import CustomToast from '@/components/common/CustomToast';
|
||||
import { getQuarterPeriods , submitSurvey, resubmitSurvey } from '@/services/submissions/submissionService';
|
||||
import { getEmirates, fetchVariationReasons, fetchZeroTargetReasons } from '@/services/masters/masterService';
|
||||
const caretUpSrc = '/assets/images/caret-up.svg';
|
||||
@ -343,7 +344,6 @@ const ReviewSubmit = ({
|
||||
products = [],
|
||||
onBack = () => {},
|
||||
onSubmit = () => {},
|
||||
toast = null,
|
||||
onToastClose = () => {},
|
||||
isSubmitting = false,
|
||||
hasSubmitted = false,
|
||||
@ -362,8 +362,19 @@ const ReviewSubmit = ({
|
||||
const [variationReasons, setVariationReasons] = useState([]);
|
||||
const [zeroTargetReasons, setZeroTargetReasons] = useState([]);
|
||||
const [isSavingDraft, setIsSavingDraft] = React.useState(false);
|
||||
const [toast, setToast] = React.useState({
|
||||
show: false,
|
||||
message: '',
|
||||
type: 'success' // 'success' or 'error'
|
||||
});
|
||||
const [productOptions, setProductOptions] = React.useState([]);
|
||||
|
||||
const [remarks, setRemarks] = React.useState(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
return localStorage.getItem('surveyRemarks') || '';
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const fetchEmiratesData = async () => {
|
||||
try {
|
||||
@ -439,12 +450,6 @@ const ReviewSubmit = ({
|
||||
|
||||
fetchReasons();
|
||||
}, []);
|
||||
const [remarks, setRemarks] = React.useState(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
return localStorage.getItem('surveyRemarks') || '';
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
const handleSaveDraft = async () => {
|
||||
try {
|
||||
@ -528,15 +533,7 @@ const existingProduct = currentSubmission.products?.find(p =>
|
||||
p.product_id === (selectedProduct?.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 {
|
||||
id: existingProduct?.id || 0,
|
||||
product_id: selectedProduct?.product_id || product.product_id || null,
|
||||
@ -599,7 +596,11 @@ console.log('Existing product match:', {
|
||||
if (submissionId) {
|
||||
// Update existing submission
|
||||
response = await resubmitSurvey(submissionId, payload);
|
||||
alert('Draft updated successfully')
|
||||
setToast({
|
||||
show: true,
|
||||
message: 'Draft updated successfully',
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
// Create new submission
|
||||
response = await submitSurvey(payload);
|
||||
@ -609,27 +610,37 @@ console.log('Existing product match:', {
|
||||
localStorage.setItem('currentSubmission', JSON.stringify(response.submission_data));
|
||||
}
|
||||
|
||||
alert('Draft saved successfully')
|
||||
setToast({
|
||||
show: true,
|
||||
message: 'Draft saved successfully',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
// Add this debug log
|
||||
console.log('API Response:', {
|
||||
status: response?.status,
|
||||
data: response?.data,
|
||||
submissionId: submissionId
|
||||
});
|
||||
|
||||
// Redirect to dashboard after a short delay to show the success message
|
||||
setTimeout(() => {
|
||||
window.location.href = '/dashboard';
|
||||
}, 1000);
|
||||
|
||||
|
||||
|
||||
} catch (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');
|
||||
message: error.message,
|
||||
response: error.response?.data,
|
||||
status: error.response?.status,
|
||||
config: {
|
||||
url: error.config?.url,
|
||||
method: error.config?.method,
|
||||
data: error.config?.data
|
||||
}
|
||||
});
|
||||
|
||||
setToast({
|
||||
show: true,
|
||||
message: error.message || 'Failed to save draft',
|
||||
type: 'error'
|
||||
});
|
||||
} finally {
|
||||
setIsSavingDraft(false);
|
||||
}
|
||||
@ -670,6 +681,13 @@ console.log('Existing product match:', {
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{toast.show && (
|
||||
<CustomToast
|
||||
message={toast.message}
|
||||
type={toast.type}
|
||||
onClose={() => setToast(prev => ({ ...prev, show: false }))}
|
||||
/>
|
||||
)}
|
||||
{toast && (
|
||||
<div
|
||||
className={`flex items-start justify-between gap-3 rounded-md border px-4 py-3 text-sm ${
|
||||
|
||||
Loading…
Reference in New Issue
Block a user