import React from 'react'; import { FormattedMessage as T } from 'components'; import intl from 'react-intl-universal'; import { Intent, Alert } from '@blueprintjs/core'; import { useOpenVendorCredit } from 'hooks/query'; import { AppToaster } from 'components'; import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; import withAlertActions from 'containers/Alert/withAlertActions'; import { compose } from 'utils'; /** * Vendor credit opened alert. */ function VendorCreditOpenedAlert({ name, // #withAlertStoreConnect isOpen, payload: { vendorCreditId }, // #withAlertActions closeAlert, }) { const { mutateAsync: openVendorCreditMutate, isLoading } = useOpenVendorCredit(); // Handle cancel opened credit note alert. const handleAlertCancel = () => { closeAlert(name); }; // Handle confirm vendor credit as opened. const handleAlertConfirm = () => { openVendorCreditMutate(vendorCreditId) .then(() => { AppToaster.show({ message: intl.get('vendor_credit_opened.alert.success_message'), intent: Intent.SUCCESS, }); }) .catch((error) => {}) .finally(() => { closeAlert(name); }); }; return ( } confirmButtonText={} intent={Intent.WARNING} isOpen={isOpen} onCancel={handleAlertCancel} onConfirm={handleAlertConfirm} loading={isLoading} >

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