fix: Unicité des fees + utilisation de l'establishmentID [#44]

This commit is contained in:
N3WT DE COMPET
2025-05-01 14:46:17 +02:00
parent 24069b894e
commit d37e6c384d
5 changed files with 25 additions and 15 deletions

View File

@ -5,8 +5,8 @@ import Popup from '@/components/Popup';
import CheckBox from '@/components/CheckBox';
import InputText from '@/components/InputText';
import logger from '@/utils/logger';
import { ESTABLISHMENT_ID } from '@/utils/Url';
import SectionHeader from '@/components/SectionHeader';
import { useEstablishment } from '@/context/EstablishmentContext';
const DiscountsSection = ({
discounts,
@ -29,6 +29,8 @@ const DiscountsSection = ({
const [removePopupMessage, setRemovePopupMessage] = useState('');
const [removePopupOnConfirm, setRemovePopupOnConfirm] = useState(() => {});
const { selectedEstablishmentId } = useEstablishment();
const handleAddDiscount = () => {
setNewDiscount({
id: Date.now(),
@ -37,7 +39,7 @@ const DiscountsSection = ({
description: '',
discount_type: 0,
type: type,
establishment: ESTABLISHMENT_ID,
establishment: selectedEstablishmentId,
});
};
@ -55,7 +57,11 @@ const DiscountsSection = ({
const handleSaveNewDiscount = () => {
if (newDiscount.name && newDiscount.amount) {
handleCreate(newDiscount)
const discountData = {
...newDiscount,
establishment: selectedEstablishmentId,
};
handleCreate(discountData)
.then((createdDiscount) => {
setDiscounts([createdDiscount, ...discounts]);
setNewDiscount(null);