diff --git a/client/src/containers/Alerts/Items/InventoryAdjustmentPublishAlert.js b/client/src/containers/Alerts/Items/InventoryAdjustmentPublishAlert.js new file mode 100644 index 000000000..da9fecaf9 --- /dev/null +++ b/client/src/containers/Alerts/Items/InventoryAdjustmentPublishAlert.js @@ -0,0 +1,71 @@ +import React from 'react'; +import { Intent, Alert } from '@blueprintjs/core'; +import { FormattedMessage as T } from 'components'; +import intl from 'react-intl-universal'; +import { usePublishInventoryAdjustment } from 'hooks/query'; + +import { AppToaster } from 'components'; + +import withAlertActions from 'containers/Alert/withAlertActions'; +import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; + +import { compose } from 'utils'; + +/** + * Inventory Adjustment publish alert. + */ + +function InventoryAdjustmentPublishAlert({ + name, + + // #withAlertStoreConnect + isOpen, + payload: { inventoryId }, + + // #withAlertActions + closeAlert, +}) { + const { mutateAsync: publishInventoryAdjustmentMutate, isLoading } = + usePublishInventoryAdjustment(); + + // Handle cancel inventory adjustment alert. + const handleCancelPublish = () => { + closeAlert(name); + }; + + // Handle publish inventory adjustment confirm. + const handleConfirmPublish = () => { + publishInventoryAdjustmentMutate(inventoryId) + .then(() => { + AppToaster.show({ + message: intl.get('the_inventory_adjustment_has_been_published'), + intent: Intent.SUCCESS, + }); + closeAlert(name); + }) + .catch((error) => { + closeAlert(name); + }); + }; + + return ( + } + confirmButtonText={} + intent={Intent.WARNING} + isOpen={isOpen} + onCancel={handleCancelPublish} + onConfirm={handleConfirmPublish} + loading={isLoading} + > +

+ +

+
+ ); +} + +export default compose( + withAlertStoreConnect(), + withAlertActions, +)(InventoryAdjustmentPublishAlert); diff --git a/client/src/containers/InventoryAdjustments/InventoryAdjustmentTable.js b/client/src/containers/InventoryAdjustments/InventoryAdjustmentTable.js index 52cb0a08a..29662c98a 100644 --- a/client/src/containers/InventoryAdjustments/InventoryAdjustmentTable.js +++ b/client/src/containers/InventoryAdjustments/InventoryAdjustmentTable.js @@ -39,6 +39,11 @@ function InventoryAdjustmentDataTable({ openAlert('inventory-adjustment-delete', { inventoryId: id }); }; + // Handle the inventory adjustment publish action. + const handlePublishInventoryAdjustment = ({ id }) => { + openAlert('inventory-adjustment-publish', { inventoryId: id }); + }; + // Inventory adjustments columns. const columns = useInventoryAdjustmentsColumns(); @@ -72,6 +77,7 @@ function InventoryAdjustmentDataTable({ autoResetPage={false} payload={{ onDelete: handleDeleteAdjustment, + onPublish: handlePublishInventoryAdjustment, }} ContextMenu={ActionsMenu} noResults={intl.get('there_is_no_inventory_adjustments_transactions_yet')} diff --git a/client/src/containers/InventoryAdjustments/InventoryAdjustmentsAlerts.js b/client/src/containers/InventoryAdjustments/InventoryAdjustmentsAlerts.js index 87cb3f31f..cacdd8b36 100644 --- a/client/src/containers/InventoryAdjustments/InventoryAdjustmentsAlerts.js +++ b/client/src/containers/InventoryAdjustments/InventoryAdjustmentsAlerts.js @@ -1,10 +1,12 @@ import React from 'react'; import InventoryAdjustmentDeleteAlert from 'containers/Alerts/Items/InventoryAdjustmentDeleteAlert'; +import InventoryAdjustmentPublishAlert from 'containers/Alerts/Items/InventoryAdjustmentPublishAlert'; export default function InventoryAdjustmentsAlerts() { return (
+
); } diff --git a/client/src/containers/InventoryAdjustments/components.js b/client/src/containers/InventoryAdjustments/components.js index c21514ce0..d2aeee4e2 100644 --- a/client/src/containers/InventoryAdjustments/components.js +++ b/client/src/containers/InventoryAdjustments/components.js @@ -12,7 +12,7 @@ import { import intl from 'react-intl-universal'; import moment from 'moment'; -import { FormattedMessage as T } from 'components'; +import { FormattedMessage as T } from 'components'; import { isNumber } from 'lodash'; import { Icon, Money, If } from 'components'; import { isBlank, safeCallback } from 'utils'; @@ -93,7 +93,7 @@ export const ItemTypeAccessor = (row) => { export const ActionsMenu = ({ row: { original }, - payload: { onDelete }, + payload: { onDelete, onPublish }, }) => { return ( @@ -102,6 +102,13 @@ export const ActionsMenu = ({ text={intl.get('view_details')} /> + + } + text={intl.get('publish_expense')} + onClick={safeCallback(onPublish, original)} + /> + { - return (} - position={Position.RIGHT_BOTTOM} - > -