import React, { useState, useEffect } from 'react'; import { Check } from 'lucide-react'; import Popup from '@/components/Popup'; const DateTab = ({ dates, activeTab, handleDateChange, handleEdit, type, paymentPlanId, resetModifiedDates }) => { const [popupVisible, setPopupVisible] = useState(false); const [popupMessage, setPopupMessage] = useState(""); const [modifiedDates, setModifiedDates] = useState({}); useEffect(() => { if (resetModifiedDates) { setModifiedDates({}); } }, [resetModifiedDates]); const submit = (updatedData) => { const dataWithType = { ...updatedData, type: type }; handleEdit(paymentPlanId, dataWithType) .then(() => { setPopupMessage(`Mise à jour de la date d'échéance effectuée avec succès`); setPopupVisible(true); setModifiedDates({}); }) .catch(error => { console.error(error); }); }; const handleDateChangeWithModification = (tab, index, value) => { handleDateChange(tab, index, value); setModifiedDates(prev => ({ ...prev, [`${tab}-${index}`]: true })); }; return (
{dates[activeTab]?.map((date, index) => (
Échéance {index + 1} handleDateChangeWithModification(activeTab, index, e.target.value)} className="p-2 border border-emerald-300 rounded focus:outline-none focus:ring-2 focus:ring-emerald-500 cursor-pointer" /> {modifiedDates[`${activeTab}-${index}`] && ( )}
))}
{popupVisible && ( setPopupVisible(false)} onCancel={() => setPopupVisible(false)} uniqueConfirmButton={true} /> )}
); }; export default DateTab;