import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { FabButton } from '../../base/fab-button'; import { FabModal } from '../../base/fab-modal'; import { Price } from '../../../models/price'; import PriceAPI from '../../../api/price'; interface DeleteExtendedPriceProps { onSuccess: (message: string) => void, onError: (message: string) => void, price: Price, } /** * This component shows a button. * When clicked, we show a modal dialog to ask the user for confirmation about the deletion of the provided extended price. */ export const DeleteExtendedPrice: React.FC = ({ onSuccess, onError, price }) => { const { t } = useTranslation('admin'); const [deletionModal, setDeletionModal] = useState(false); /** * Opens/closes the deletion modal */ const toggleDeletionModal = (): void => { setDeletionModal(!deletionModal); }; /** * The deletion has been confirmed by the user. * Call the API to trigger the deletion of the temporary set extended price */ const onDeleteConfirmed = (): void => { PriceAPI.destroy(price.id).then(() => { onSuccess(t('app.admin.delete_extended_price.extended_price_deleted')); }).catch((error) => { onError(t('app.admin.delete_extended_price.unable_to_delete') + error); }); toggleDeletionModal(); }; return (
} onClick={toggleDeletionModal} /> {t('app.admin.delete_extended_price.delete_confirmation')}
); };