mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
feat: Inventory adjustment publish.
This commit is contained in:
@@ -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 (
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'publish'} />}
|
||||||
|
intent={Intent.WARNING}
|
||||||
|
isOpen={isOpen}
|
||||||
|
onCancel={handleCancelPublish}
|
||||||
|
onConfirm={handleConfirmPublish}
|
||||||
|
loading={isLoading}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<T id={'are_sure_to_publish_this_inventory_adjustment'} />
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withAlertStoreConnect(),
|
||||||
|
withAlertActions,
|
||||||
|
)(InventoryAdjustmentPublishAlert);
|
||||||
@@ -39,6 +39,11 @@ function InventoryAdjustmentDataTable({
|
|||||||
openAlert('inventory-adjustment-delete', { inventoryId: id });
|
openAlert('inventory-adjustment-delete', { inventoryId: id });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle the inventory adjustment publish action.
|
||||||
|
const handlePublishInventoryAdjustment = ({ id }) => {
|
||||||
|
openAlert('inventory-adjustment-publish', { inventoryId: id });
|
||||||
|
};
|
||||||
|
|
||||||
// Inventory adjustments columns.
|
// Inventory adjustments columns.
|
||||||
const columns = useInventoryAdjustmentsColumns();
|
const columns = useInventoryAdjustmentsColumns();
|
||||||
|
|
||||||
@@ -72,6 +77,7 @@ function InventoryAdjustmentDataTable({
|
|||||||
autoResetPage={false}
|
autoResetPage={false}
|
||||||
payload={{
|
payload={{
|
||||||
onDelete: handleDeleteAdjustment,
|
onDelete: handleDeleteAdjustment,
|
||||||
|
onPublish: handlePublishInventoryAdjustment,
|
||||||
}}
|
}}
|
||||||
ContextMenu={ActionsMenu}
|
ContextMenu={ActionsMenu}
|
||||||
noResults={intl.get('there_is_no_inventory_adjustments_transactions_yet')}
|
noResults={intl.get('there_is_no_inventory_adjustments_transactions_yet')}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import InventoryAdjustmentDeleteAlert from 'containers/Alerts/Items/InventoryAdjustmentDeleteAlert';
|
import InventoryAdjustmentDeleteAlert from 'containers/Alerts/Items/InventoryAdjustmentDeleteAlert';
|
||||||
|
import InventoryAdjustmentPublishAlert from 'containers/Alerts/Items/InventoryAdjustmentPublishAlert';
|
||||||
|
|
||||||
export default function InventoryAdjustmentsAlerts() {
|
export default function InventoryAdjustmentsAlerts() {
|
||||||
return (
|
return (
|
||||||
<div className={'inventory-adjustments-alert'}>
|
<div className={'inventory-adjustments-alert'}>
|
||||||
<InventoryAdjustmentDeleteAlert name={'inventory-adjustment-delete'} />
|
<InventoryAdjustmentDeleteAlert name={'inventory-adjustment-delete'} />
|
||||||
|
<InventoryAdjustmentPublishAlert name={'inventory-adjustment-publish'} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import { FormattedMessage as T } from 'components';
|
import { FormattedMessage as T } from 'components';
|
||||||
import { isNumber } from 'lodash';
|
import { isNumber } from 'lodash';
|
||||||
import { Icon, Money, If } from 'components';
|
import { Icon, Money, If } from 'components';
|
||||||
import { isBlank, safeCallback } from 'utils';
|
import { isBlank, safeCallback } from 'utils';
|
||||||
@@ -93,7 +93,7 @@ export const ItemTypeAccessor = (row) => {
|
|||||||
|
|
||||||
export const ActionsMenu = ({
|
export const ActionsMenu = ({
|
||||||
row: { original },
|
row: { original },
|
||||||
payload: { onDelete },
|
payload: { onDelete, onPublish },
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<Menu>
|
<Menu>
|
||||||
@@ -102,6 +102,13 @@ export const ActionsMenu = ({
|
|||||||
text={intl.get('view_details')}
|
text={intl.get('view_details')}
|
||||||
/>
|
/>
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
|
<If condition={!original.is_published}>
|
||||||
|
<MenuItem
|
||||||
|
icon={<Icon icon={'arrow-to-top'} size={16} />}
|
||||||
|
text={intl.get('publish_expense')}
|
||||||
|
onClick={safeCallback(onPublish, original)}
|
||||||
|
/>
|
||||||
|
</If>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={intl.get('delete_adjustment')}
|
text={intl.get('delete_adjustment')}
|
||||||
intent={Intent.DANGER}
|
intent={Intent.DANGER}
|
||||||
@@ -113,12 +120,13 @@ export const ActionsMenu = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ActionsCell = (props) => {
|
export const ActionsCell = (props) => {
|
||||||
return (<Popover
|
return (
|
||||||
content={<ActionsMenu {...props} />}
|
<Popover
|
||||||
position={Position.RIGHT_BOTTOM}
|
content={<ActionsMenu {...props} />}
|
||||||
>
|
position={Position.RIGHT_BOTTOM}
|
||||||
<Button icon={<Icon icon="more-h-16" iconSize={16} />} />
|
>
|
||||||
</Popover>
|
<Button icon={<Icon icon="more-h-16" iconSize={16} />} />
|
||||||
|
</Popover>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,8 +134,6 @@ export const ActionsCell = (props) => {
|
|||||||
* Retrieve inventory adjustments columns.
|
* Retrieve inventory adjustments columns.
|
||||||
*/
|
*/
|
||||||
export const useInventoryAdjustmentsColumns = () => {
|
export const useInventoryAdjustmentsColumns = () => {
|
||||||
|
|
||||||
|
|
||||||
return React.useMemo(
|
return React.useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -84,3 +84,24 @@ export function useInventoryAdjustments(query, props) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publishes the given inventory adjustment.
|
||||||
|
*/
|
||||||
|
export function usePublishInventoryAdjustment(props) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
|
return useMutation(
|
||||||
|
(id) => apiRequest.post(`inventory_adjustments/${id}/publish`),
|
||||||
|
{
|
||||||
|
onSuccess: (res, id) => {
|
||||||
|
// Invalidate specific inventory adjustment.
|
||||||
|
queryClient.invalidateQueries([t.INVENTORY_ADJUSTMENT, id]);
|
||||||
|
|
||||||
|
commonInvalidateQueries(queryClient);
|
||||||
|
},
|
||||||
|
...props,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ const SALE_RECEIPTS = {
|
|||||||
|
|
||||||
const INVENTORY_ADJUSTMENTS = {
|
const INVENTORY_ADJUSTMENTS = {
|
||||||
INVENTORY_ADJUSTMENTS: 'INVENTORY_ADJUSTMENTS',
|
INVENTORY_ADJUSTMENTS: 'INVENTORY_ADJUSTMENTS',
|
||||||
|
INVENTORY_ADJUSTMENT: 'INVENTORY_ADJUSTMENT',
|
||||||
};
|
};
|
||||||
|
|
||||||
const CURRENCIES = {
|
const CURRENCIES = {
|
||||||
|
|||||||
@@ -1185,5 +1185,8 @@
|
|||||||
"non-inventory":"Non-Inventory",
|
"non-inventory":"Non-Inventory",
|
||||||
"terms_conditions":"Terms conditions",
|
"terms_conditions":"Terms conditions",
|
||||||
"your_invoice_numbers_are_set_on_auto_increment_mod_are_you_sure_changing_this_setting":"Your invoice numbers are set on auto-increment mod. Are you sure changing this setting?",
|
"your_invoice_numbers_are_set_on_auto_increment_mod_are_you_sure_changing_this_setting":"Your invoice numbers are set on auto-increment mod. Are you sure changing this setting?",
|
||||||
"auto_incrementing_number":"Auto-incrementing number"
|
"auto_incrementing_number":"Auto-incrementing number",
|
||||||
|
"the_inventory_adjustment_has_been_published": "The Inventory adjustment has been published",
|
||||||
|
"are_sure_to_publish_this_inventory_adjustment": "Are you sure you want to publish this inventory?"
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user