fix: Ajout du % ou € en mode édition de réduction

This commit is contained in:
N3WT DE COMPET
2025-02-07 17:55:53 +01:00
parent 7f35527649
commit f2628bb45a

View File

@ -86,6 +86,20 @@ const DiscountsSection = ({ discounts, setDiscounts, handleCreate, handleEdit, h
}); });
}; };
const handleToggleDiscountTypeEdition = (id) => {
if (editingDiscount) {
setFormData((prevData) => ({
...prevData,
discount_type: prevData.discount_type === 0 ? 1 : 0,
}));
} else if (newDiscount) {
setNewDiscount((prevData) => ({
...prevData,
discount_type: prevData.discount_type === 0 ? 1 : 0,
}));
}
};
const handleChange = (e) => { const handleChange = (e) => {
const { name, value } = e.target; const { name, value } = e.target;
if (editingDiscount) { if (editingDiscount) {
@ -124,7 +138,19 @@ const DiscountsSection = ({ discounts, setDiscounts, handleCreate, handleEdit, h
case 'LIBELLE': case 'LIBELLE':
return renderInputField('name', currentData.name, handleChange, 'Libellé de la réduction'); return renderInputField('name', currentData.name, handleChange, 'Libellé de la réduction');
case 'REMISE': case 'REMISE':
return renderInputField('amount', currentData.amount, handleChange,'Montant'); return (
<div className="flex items-center space-x-2">
{renderInputField('amount', currentData.amount, handleChange,'Montant')}
<button
type="button"
onClick={() => handleToggleDiscountTypeEdition(discount.id)}
className="flex justify-center items-center text-emerald-500 hover:text-emerald-700 ml-2"
>
{currentData.discount_type === 0 ? <EuroIcon className="w-5 h-5" /> : <Percent className="w-5 h-5" />}
</button>
</div>
);
case 'DESCRIPTION': case 'DESCRIPTION':
return renderInputField('description', currentData.description, handleChange, 'Description'); return renderInputField('description', currentData.description, handleChange, 'Description');
case 'ACTIONS': case 'ACTIONS':