Files
bigcapital/client/src/containers/Alerts/PaymentReceives/PaymentReceiveDeleteAlert.js

82 lines
1.9 KiB
JavaScript

import React from 'react';
import {
FormattedMessage as T,
FormattedHTMLMessage,
useIntl,
} from 'react-intl';
import { Intent, Alert } from '@blueprintjs/core';
import { useDeletePaymentReceive } from 'hooks/query';
import { AppToaster } from 'components';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import { compose } from 'utils';
/**
* Payment receive delete alert.
*/
function PaymentReceiveDeleteAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { paymentReceiveId },
// #withAlertActions
closeAlert,
}) {
const { formatMessage } = useIntl();
const {
mutateAsync: deletePaymentReceiveMutate,
isLoading,
} = useDeletePaymentReceive();
// Handle cancel payment Receive.
const handleCancelDeleteAlert = () => {
closeAlert(name);
};
// Handle confirm delete payment receive.
const handleConfirmPaymentReceiveDelete = () => {
deletePaymentReceiveMutate(paymentReceiveId)
.then(() => {
AppToaster.show({
message: formatMessage({
id: 'the_payment_receive_has_been_deleted_successfully',
}),
intent: Intent.SUCCESS,
});
})
.catch(() => {})
.finally(() => {
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'delete'} />}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancelDeleteAlert}
onConfirm={handleConfirmPaymentReceiveDelete}
loading={isLoading}
>
<p>
<FormattedHTMLMessage
id={'once_delete_this_payment_receive_you_will_able_to_restore_it'}
/>
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(PaymentReceiveDeleteAlert);