import React from 'react'; import { FormattedMessage as T } from 'components'; import intl from 'react-intl-universal'; import { Intent, Alert } from '@blueprintjs/core'; import { AppToaster } from 'components'; import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; import withAlertActions from 'containers/Alert/withAlertActions'; import { usePublishExpense } from 'hooks/query'; import { compose } from 'utils'; /** * Expense publish alert. */ function ExpensePublishAlert({ closeAlert, // #withAlertStoreConnect name, payload: { expenseId }, isOpen, }) { const { mutateAsync: publishExpenseMutate, isLoading } = usePublishExpense(); const handleCancelPublishExpense = () => { closeAlert('expense-publish'); }; // Handle publish expense confirm. const handleConfirmPublishExpense = () => { publishExpenseMutate(expenseId) .then(() => { AppToaster.show({ message: intl.get('the_expense_has_been_published'), intent: Intent.SUCCESS, }); closeAlert(name) }) .catch((error) => { closeAlert(name) }); }; return ( } confirmButtonText={} intent={Intent.WARNING} isOpen={isOpen} onCancel={handleCancelPublishExpense} onConfirm={handleConfirmPublishExpense} loading={isLoading} >

); } export default compose( withAlertStoreConnect(), withAlertActions, )(ExpensePublishAlert);