refactor: items alert.

This commit is contained in:
elforjani3
2021-01-27 13:20:15 +02:00
parent 62fcbf7c02
commit 0e95c5cce1
9 changed files with 59 additions and 38 deletions

View File

@@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@babel/core": "7.8.4",
"@blueprintjs/core": "^3.23.1",
"@blueprintjs/core": "^3.38.1",
"@blueprintjs/datetime": "^3.15.2",
"@blueprintjs/select": "^3.11.2",
"@blueprintjs/table": "^3.8.3",

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import {
FormattedMessage as T,
FormattedHTMLMessage,
@@ -30,6 +30,7 @@ function InventoryAdjustmentDeleteAlert({
closeAlert,
}) {
const { formatMessage } = useIntl();
const [isLoading, setLoading] = useState(false);
// handle cancel delete alert.
const handleCancelInventoryAdjustmentDelete = () => {
@@ -37,9 +38,9 @@ function InventoryAdjustmentDeleteAlert({
};
const handleConfirmInventoryAdjustmentDelete = () => {
setLoading(true);
requestDeleteInventoryAdjustment(inventoryId)
.then(() => {
closeAlert(name);
AppToaster.show({
message: formatMessage({
id: 'the_adjustment_has_been_deleted_successfully',
@@ -48,7 +49,9 @@ function InventoryAdjustmentDeleteAlert({
});
queryCache.invalidateQueries('inventory-adjustment-list');
})
.catch((errors) => {
.catch((errors) => {})
.finally(() => {
setLoading(false);
closeAlert(name);
});
};
@@ -62,6 +65,7 @@ function InventoryAdjustmentDeleteAlert({
isOpen={isOpen}
onCancel={handleCancelInventoryAdjustmentDelete}
onConfirm={handleConfirmInventoryAdjustmentDelete}
loading={isLoading}
>
<p>
<FormattedHTMLMessage

View File

@@ -1,8 +1,5 @@
import React from 'react';
import {
FormattedMessage as T,
useIntl,
} from 'react-intl';
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';
@@ -30,7 +27,8 @@ function ItemActivateAlert({
closeAlert,
}) {
const { formatMessage } = useIntl();
const [isLoading, setLoading] = useState(false);
// Handle activate item alert cancel.
const handleCancelActivateItem = () => {
closeAlert(name);
@@ -38,9 +36,9 @@ function ItemActivateAlert({
// Handle confirm item activated.
const handleConfirmItemActivate = () => {
setLoading(true);
requestActivateItem(itemId)
.then(() => {
closeAlert(name);
AppToaster.show({
message: formatMessage({
id: 'the_item_has_been_activated_successfully',
@@ -49,8 +47,10 @@ function ItemActivateAlert({
});
queryCache.invalidateQueries('items-table');
})
.catch((error) => {
.catch((error) => {})
.finally(() => {
closeAlert(name);
setLoading(false);
});
};
@@ -62,6 +62,7 @@ function ItemActivateAlert({
isOpen={isOpen}
onCancel={handleCancelActivateItem}
onConfirm={handleConfirmItemActivate}
loading={isLoading}
>
<p>
<T id={'are_sure_to_activate_this_item'} />

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { FormattedMessage as T, useIntl } from 'react-intl';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster } from 'components';
@@ -26,16 +26,16 @@ function ItemBulkDeleteAlert({
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(() => {
closeAlert(name);
AppToaster.show({
message: formatMessage({
id: 'the_items_has_been_deleted_successfully',
@@ -43,7 +43,9 @@ function ItemBulkDeleteAlert({
intent: Intent.SUCCESS,
});
})
.catch((errors) => {
.catch((errors) => {})
.finally(() => {
setLoading(false);
closeAlert(name);
});
};

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import {
FormattedMessage as T,
FormattedHTMLMessage,
@@ -30,6 +30,7 @@ function ItemCategoryBulkDeleteAlert({
closeAlert,
}) {
const { formatMessage } = useIntl();
const [isLoading, setLoading] = useState(false);
// handle cancel bulk delete alert.
const handleCancelBulkDelete = () => {
@@ -38,9 +39,9 @@ function ItemCategoryBulkDeleteAlert({
// handle confirm itemCategories bulk delete.
const handleConfirmBulkDelete = () => {
setLoading(true);
requestDeleteBulkItemCategories(itemCategoriesIds)
.then(() => {
closeAlert(name);
AppToaster.show({
message: formatMessage({
id: 'the_item_categories_has_been_deleted_successfully',
@@ -48,8 +49,10 @@ function ItemCategoryBulkDeleteAlert({
intent: Intent.SUCCESS,
});
})
.catch((errors) => {
.catch((errors) => {})
.finally(() => {
closeAlert(name);
setLoading(false);
});
};
return (
@@ -63,6 +66,7 @@ function ItemCategoryBulkDeleteAlert({
isOpen={isOpen}
onCancel={handleCancelBulkDelete}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<FormattedHTMLMessage

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import {
FormattedMessage as T,
FormattedHTMLMessage,
@@ -31,6 +31,7 @@ function ItemCategoryDeleteAlert({
closeAlert,
}) {
const { formatMessage } = useIntl();
const [isLoading, setLoading] = useState(false);
// handle cancel delete item category alert.
const handleCancelItemCategoryDelete = () => {
@@ -39,9 +40,9 @@ function ItemCategoryDeleteAlert({
// Handle alert confirm delete item category.
const handleConfirmItemDelete = () => {
setLoading(true);
requestDeleteItemCategory(itemCategoryId)
.then(() => {
closeAlert(name);
AppToaster.show({
message: formatMessage({
id: 'the_item_category_has_been_deleted_successfully',
@@ -50,7 +51,9 @@ function ItemCategoryDeleteAlert({
});
queryCache.invalidateQueries('items-categories-list');
})
.catch(() => {
.catch(() => {})
.finally(() => {
setLoading(false);
closeAlert(name);
});
};
@@ -64,6 +67,7 @@ function ItemCategoryDeleteAlert({
isOpen={isOpen}
onCancel={handleCancelItemCategoryDelete}
onConfirm={handleConfirmItemDelete}
loading={isLoading}
>
<p>
<FormattedHTMLMessage

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import {
FormattedMessage as T,
FormattedHTMLMessage,
@@ -33,6 +33,7 @@ function ItemDeleteAlert({
closeAlert,
}) {
const { formatMessage } = useIntl();
const [isLoading, setLoading] = useState(false);
// handle cancel delete item alert.
const handleCancelItemDelete = () => {
@@ -40,9 +41,9 @@ function ItemDeleteAlert({
};
const handleConfirmDeleteItem = () => {
setLoading(true);
requestDeleteItem(itemId)
.then(() => {
closeAlert(name);
AppToaster.show({
message: formatMessage({
id: 'the_item_has_been_deleted_successfully',
@@ -53,7 +54,10 @@ function ItemDeleteAlert({
})
.catch(({ errors }) => {
handleDeleteErrors(errors);
})
.finally(() => {
closeAlert(name);
setLoading(false);
});
};
@@ -66,6 +70,7 @@ function ItemDeleteAlert({
isOpen={isOpen}
onCancel={handleCancelItemDelete}
onConfirm={handleConfirmDeleteItem}
loading={isLoading}
>
<p>
<FormattedHTMLMessage

View File

@@ -1,8 +1,5 @@
import React from 'react';
import {
FormattedMessage as T,
useIntl,
} from 'react-intl';
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';
@@ -30,6 +27,7 @@ function ItemInactivateAlert({
closeAlert,
}) {
const { formatMessage } = useIntl();
const [isLoading, setLoading] = useState(false);
// handle cancel inactivate alert.
const handleCancelInactivateItem = () => {
@@ -38,9 +36,9 @@ function ItemInactivateAlert({
// Handle confirm item Inactive.
const handleConfirmItemInactive = () => {
setLoading(true);
requestInactiveItem(itemId)
.then(() => {
closeAlert(name);
AppToaster.show({
message: formatMessage({
id: 'the_item_has_been_inactivated_successfully',
@@ -49,7 +47,9 @@ function ItemInactivateAlert({
});
queryCache.invalidateQueries('items-table');
})
.catch((error) => {
.catch((error) => {})
.finally(() => {
setLoading(false);
closeAlert(name);
});
};
@@ -62,6 +62,7 @@ function ItemInactivateAlert({
isOpen={isOpen}
onCancel={handleCancelInactivateItem}
onConfirm={handleConfirmItemInactive}
loading={isLoading}
>
<p>
<T id={'are_sure_to_inactive_this_item'} />

View File

@@ -1,11 +1,11 @@
import React from 'react';
import ItemDeleteAlert from 'containers/Alerts/Item/ItemDeleteAlert';
import ItemInactivateAlert from 'containers/Alerts/Item/ItemInactivateAlert';
import ItemActivateAlert from 'containers/Alerts/Item/ItemActivateAlert';
import ItemBulkDeleteAlert from 'containers/Alerts/Item/ItemBulkDeleteAlert';
import ItemCategoryDeleteAlert from 'containers/Alerts/Item/ItemCategoryDeleteAlert';
import ItemCategoryBulkDeleteAlert from 'containers/Alerts/Item/ItemCategoryBulkDeleteAlert';
import InventoryAdjustmentDeleteAlert from 'containers/Alerts/Item/InventoryAdjustmentDeleteAlert';
import ItemDeleteAlert from 'containers/Alerts/Items/ItemDeleteAlert';
import ItemInactivateAlert from 'containers/Alerts/Items/ItemInactivateAlert';
import ItemActivateAlert from 'containers/Alerts/Items/ItemActivateAlert';
import ItemBulkDeleteAlert from 'containers/Alerts/Items/ItemBulkDeleteAlert';
import ItemCategoryDeleteAlert from 'containers/Alerts/Items/ItemCategoryDeleteAlert';
import ItemCategoryBulkDeleteAlert from 'containers/Alerts/Items/ItemCategoryBulkDeleteAlert';
import InventoryAdjustmentDeleteAlert from 'containers/Alerts/Items/InventoryAdjustmentDeleteAlert';
/**
* Items alert.