mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
refactor: items alert.
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
FormattedMessage as T,
|
||||
FormattedHTMLMessage,
|
||||
useIntl,
|
||||
} from 'react-intl';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { queryCache } from 'react-query';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
import withInventoryAdjustmentActions from 'containers/Items/withInventoryAdjustmentActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Inventory Adjustment delete alerts.
|
||||
*/
|
||||
function InventoryAdjustmentDeleteAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { inventoryId },
|
||||
// #withInventoryAdjustmentActions
|
||||
requestDeleteInventoryAdjustment,
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
// handle cancel delete alert.
|
||||
const handleCancelInventoryAdjustmentDelete = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
const handleConfirmInventoryAdjustmentDelete = () => {
|
||||
setLoading(true);
|
||||
requestDeleteInventoryAdjustment(inventoryId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_adjustment_has_been_deleted_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('inventory-adjustment-list');
|
||||
})
|
||||
.catch((errors) => {})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'delete'} />}
|
||||
icon="trash"
|
||||
intent={Intent.DANGER}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelInventoryAdjustmentDelete}
|
||||
onConfirm={handleConfirmInventoryAdjustmentDelete}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<FormattedHTMLMessage
|
||||
id={
|
||||
'once_delete_this_inventory_a_adjustment_you_will_able_to_restore_it'
|
||||
}
|
||||
/>
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
withInventoryAdjustmentActions,
|
||||
)(InventoryAdjustmentDeleteAlert);
|
||||
78
client/src/containers/Alerts/Items/ItemActivateAlert.js
Normal file
78
client/src/containers/Alerts/Items/ItemActivateAlert.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import React, { useState } from 'react';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { queryCache } from 'react-query';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import withItemsActions from 'containers/Items/withItemsActions';
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Item activate alert.
|
||||
*/
|
||||
function ItemActivateAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { itemId },
|
||||
|
||||
// #withItemsActions
|
||||
requestActivateItem,
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
// Handle activate item alert cancel.
|
||||
const handleCancelActivateItem = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// Handle confirm item activated.
|
||||
const handleConfirmItemActivate = () => {
|
||||
setLoading(true);
|
||||
requestActivateItem(itemId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_item_has_been_activated_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('items-table');
|
||||
})
|
||||
.catch((error) => {})
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'activate'} />}
|
||||
intent={Intent.WARNING}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelActivateItem}
|
||||
onConfirm={handleConfirmItemActivate}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<T id={'are_sure_to_activate_this_item'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
withItemsActions,
|
||||
)(ItemActivateAlert);
|
||||
76
client/src/containers/Alerts/Items/ItemBulkDeleteAlert.js
Normal file
76
client/src/containers/Alerts/Items/ItemBulkDeleteAlert.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import React, { useState } from 'react';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import withItemsActions from 'containers/Items/withItemsActions';
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Item bulk delete alert.
|
||||
*/
|
||||
function ItemBulkDeleteAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { itemsIds },
|
||||
|
||||
// #withItemsActions
|
||||
requestDeleteBulkItems,
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
// handle cancel item bulk delete alert.
|
||||
const handleCancelBulkDelete = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
// Handle confirm items bulk delete.
|
||||
const handleConfirmBulkDelete = () => {
|
||||
setLoading(true);
|
||||
requestDeleteBulkItems(itemsIds)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_items_has_been_deleted_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
})
|
||||
.catch((errors) => {})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={
|
||||
<T id={'delete_count'} values={{ count: itemsIds.length }} />
|
||||
}
|
||||
icon="trash"
|
||||
intent={Intent.DANGER}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelBulkDelete}
|
||||
onConfirm={handleConfirmBulkDelete}
|
||||
>
|
||||
<p>
|
||||
<T id={'once_delete_these_items_you_will_not_able_restore_them'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
withItemsActions,
|
||||
)(ItemBulkDeleteAlert);
|
||||
@@ -0,0 +1,86 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
FormattedMessage as T,
|
||||
FormattedHTMLMessage,
|
||||
useIntl,
|
||||
} from 'react-intl';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import withItemCategoriesActions from 'containers/Items/withItemCategoriesActions';
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Item category bulk delete alerts.
|
||||
*/
|
||||
function ItemCategoryBulkDeleteAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { itemCategoriesIds },
|
||||
|
||||
// #withItemCategoriesActions
|
||||
requestDeleteBulkItemCategories,
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
// handle cancel bulk delete alert.
|
||||
const handleCancelBulkDelete = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// handle confirm itemCategories bulk delete.
|
||||
const handleConfirmBulkDelete = () => {
|
||||
setLoading(true);
|
||||
requestDeleteBulkItemCategories(itemCategoriesIds)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_item_categories_has_been_deleted_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
})
|
||||
.catch((errors) => {})
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={
|
||||
<T id={'delete_count'} values={{ count: itemCategoriesIds.length }} />
|
||||
}
|
||||
icon="trash"
|
||||
intent={Intent.DANGER}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelBulkDelete}
|
||||
onConfirm={handleConfirmBulkDelete}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<FormattedHTMLMessage
|
||||
id={
|
||||
'once_delete_these_item_categories_you_will_not_able_restore_them'
|
||||
}
|
||||
/>
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
withItemCategoriesActions,
|
||||
)(ItemCategoryBulkDeleteAlert);
|
||||
@@ -0,0 +1,85 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
FormattedMessage as T,
|
||||
FormattedHTMLMessage,
|
||||
useIntl,
|
||||
} from 'react-intl';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import withItemCategoriesActions from 'containers/Items/withItemCategoriesActions';
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Item Category delete alerts.
|
||||
*/
|
||||
function ItemCategoryDeleteAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { itemCategoryId },
|
||||
|
||||
// #withItemCategoriesActions
|
||||
requestDeleteItemCategory,
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
// handle cancel delete item category alert.
|
||||
const handleCancelItemCategoryDelete = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// Handle alert confirm delete item category.
|
||||
const handleConfirmItemDelete = () => {
|
||||
setLoading(true);
|
||||
requestDeleteItemCategory(itemCategoryId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_item_category_has_been_deleted_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('items-categories-list');
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'delete'} />}
|
||||
icon="trash"
|
||||
intent={Intent.DANGER}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelItemCategoryDelete}
|
||||
onConfirm={handleConfirmItemDelete}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<FormattedHTMLMessage
|
||||
id={'once_delete_this_item_category_you_will_able_to_restore_it'}
|
||||
/>
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
withItemCategoriesActions,
|
||||
)(ItemCategoryDeleteAlert);
|
||||
88
client/src/containers/Alerts/Items/ItemDeleteAlert.js
Normal file
88
client/src/containers/Alerts/Items/ItemDeleteAlert.js
Normal file
@@ -0,0 +1,88 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
FormattedMessage as T,
|
||||
FormattedHTMLMessage,
|
||||
useIntl,
|
||||
} from 'react-intl';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { queryCache } from 'react-query';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import { handleDeleteErrors } from 'containers/Items/utils';
|
||||
|
||||
import withItemsActions from 'containers/Items/withItemsActions';
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Item delete alerts.
|
||||
*/
|
||||
function ItemDeleteAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { itemId },
|
||||
|
||||
// #withItemsActions
|
||||
requestDeleteItem,
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
// handle cancel delete item alert.
|
||||
const handleCancelItemDelete = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
const handleConfirmDeleteItem = () => {
|
||||
setLoading(true);
|
||||
requestDeleteItem(itemId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_item_has_been_deleted_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('items-table');
|
||||
})
|
||||
.catch(({ errors }) => {
|
||||
handleDeleteErrors(errors);
|
||||
})
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'delete'} />}
|
||||
icon="trash"
|
||||
intent={Intent.DANGER}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelItemDelete}
|
||||
onConfirm={handleConfirmDeleteItem}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<FormattedHTMLMessage
|
||||
id={'once_delete_this_item_you_will_able_to_restore_it'}
|
||||
/>
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
withItemsActions,
|
||||
)(ItemDeleteAlert);
|
||||
78
client/src/containers/Alerts/Items/ItemInactivateAlert.js
Normal file
78
client/src/containers/Alerts/Items/ItemInactivateAlert.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import React, { useState } from 'react';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { queryCache } from 'react-query';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import withItemsActions from 'containers/Items/withItemsActions';
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Item inactivate alert.
|
||||
*/
|
||||
function ItemInactivateAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { itemId },
|
||||
|
||||
// #withItemsActions
|
||||
requestInactiveItem,
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
// handle cancel inactivate alert.
|
||||
const handleCancelInactivateItem = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// Handle confirm item Inactive.
|
||||
const handleConfirmItemInactive = () => {
|
||||
setLoading(true);
|
||||
requestInactiveItem(itemId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_item_has_been_inactivated_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('items-table');
|
||||
})
|
||||
.catch((error) => {})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'inactivate'} />}
|
||||
intent={Intent.WARNING}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelInactivateItem}
|
||||
onConfirm={handleConfirmItemInactive}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<T id={'are_sure_to_inactive_this_item'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
withItemsActions,
|
||||
)(ItemInactivateAlert);
|
||||
Reference in New Issue
Block a user