removed console
This commit is contained in:
parent
a5915b8a41
commit
df35fdcc50
@ -508,8 +508,6 @@ useEffect(() => {
|
|||||||
const parsedData = JSON.parse(resubmissionData);
|
const parsedData = JSON.parse(resubmissionData);
|
||||||
|
|
||||||
if (parsedData.products && Array.isArray(parsedData.products) && parsedData.products.length > 0) {
|
if (parsedData.products && Array.isArray(parsedData.products) && parsedData.products.length > 0) {
|
||||||
console.log('Loading resubmission products:', parsedData.products);
|
|
||||||
|
|
||||||
// Wait for product options to be loaded
|
// Wait for product options to be loaded
|
||||||
if (productOptions.length === 0) {
|
if (productOptions.length === 0) {
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
@ -576,9 +574,6 @@ useEffect(() => {
|
|||||||
originalData: product
|
originalData: product
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log('Mapped products for resubmission:', mappedProducts);
|
|
||||||
|
|
||||||
// Update the products state with the mapped products
|
// Update the products state with the mapped products
|
||||||
if (mappedProducts.length > 0) {
|
if (mappedProducts.length > 0) {
|
||||||
onProductsChange(mappedProducts);
|
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) ||
|
||||||
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 {
|
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,
|
||||||
|
|||||||
@ -1,5 +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 CustomToast from '@/components/common/CustomToast';
|
||||||
import { getQuarterPeriods , submitSurvey, 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';
|
||||||
@ -343,7 +344,6 @@ const ReviewSubmit = ({
|
|||||||
products = [],
|
products = [],
|
||||||
onBack = () => {},
|
onBack = () => {},
|
||||||
onSubmit = () => {},
|
onSubmit = () => {},
|
||||||
toast = null,
|
|
||||||
onToastClose = () => {},
|
onToastClose = () => {},
|
||||||
isSubmitting = false,
|
isSubmitting = false,
|
||||||
hasSubmitted = false,
|
hasSubmitted = false,
|
||||||
@ -362,7 +362,18 @@ const ReviewSubmit = ({
|
|||||||
const [variationReasons, setVariationReasons] = useState([]);
|
const [variationReasons, setVariationReasons] = useState([]);
|
||||||
const [zeroTargetReasons, setZeroTargetReasons] = useState([]);
|
const [zeroTargetReasons, setZeroTargetReasons] = useState([]);
|
||||||
const [isSavingDraft, setIsSavingDraft] = React.useState(false);
|
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 [productOptions, setProductOptions] = React.useState([]);
|
||||||
|
const [remarks, setRemarks] = React.useState(() => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
return localStorage.getItem('surveyRemarks') || '';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchEmiratesData = async () => {
|
const fetchEmiratesData = async () => {
|
||||||
@ -439,12 +450,6 @@ const ReviewSubmit = ({
|
|||||||
|
|
||||||
fetchReasons();
|
fetchReasons();
|
||||||
}, []);
|
}, []);
|
||||||
const [remarks, setRemarks] = React.useState(() => {
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
return localStorage.getItem('surveyRemarks') || '';
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSaveDraft = async () => {
|
const handleSaveDraft = async () => {
|
||||||
try {
|
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) ||
|
||||||
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 {
|
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,
|
||||||
@ -599,7 +596,11 @@ console.log('Existing product match:', {
|
|||||||
if (submissionId) {
|
if (submissionId) {
|
||||||
// Update existing submission
|
// Update existing submission
|
||||||
response = await resubmitSurvey(submissionId, payload);
|
response = await resubmitSurvey(submissionId, payload);
|
||||||
alert('Draft updated successfully')
|
setToast({
|
||||||
|
show: true,
|
||||||
|
message: 'Draft updated successfully',
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// Create new submission
|
// Create new submission
|
||||||
response = await submitSurvey(payload);
|
response = await submitSurvey(payload);
|
||||||
@ -609,14 +610,19 @@ console.log('Existing product match:', {
|
|||||||
localStorage.setItem('currentSubmission', JSON.stringify(response.submission_data));
|
localStorage.setItem('currentSubmission', JSON.stringify(response.submission_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
alert('Draft saved successfully')
|
setToast({
|
||||||
}
|
show: true,
|
||||||
// Add this debug log
|
message: 'Draft saved successfully',
|
||||||
console.log('API Response:', {
|
type: 'success'
|
||||||
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) {
|
} catch (error) {
|
||||||
console.error('Error details:', {
|
console.error('Error details:', {
|
||||||
@ -629,7 +635,12 @@ console.log('Existing product match:', {
|
|||||||
data: error.config?.data
|
data: error.config?.data
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
alert(error.message || 'Failed to save draft');
|
|
||||||
|
setToast({
|
||||||
|
show: true,
|
||||||
|
message: error.message || 'Failed to save draft',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setIsSavingDraft(false);
|
setIsSavingDraft(false);
|
||||||
}
|
}
|
||||||
@ -670,6 +681,13 @@ console.log('Existing product match:', {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-5">
|
<div className="space-y-5">
|
||||||
|
{toast.show && (
|
||||||
|
<CustomToast
|
||||||
|
message={toast.message}
|
||||||
|
type={toast.type}
|
||||||
|
onClose={() => setToast(prev => ({ ...prev, show: false }))}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{toast && (
|
{toast && (
|
||||||
<div
|
<div
|
||||||
className={`flex items-start justify-between gap-3 rounded-md border px-4 py-3 text-sm ${
|
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