mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
fix: itemCategories alert.
This commit is contained in:
@@ -0,0 +1,82 @@
|
|||||||
|
import React 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();
|
||||||
|
|
||||||
|
// handle cancel bulk delete alert.
|
||||||
|
const handleCancelBulkDelete = () => {
|
||||||
|
closeAlert(name);
|
||||||
|
};
|
||||||
|
|
||||||
|
// handle confirm itemCategories bulk delete.
|
||||||
|
const handleConfirmBulkDelete = () => {
|
||||||
|
requestDeleteBulkItemCategories(itemCategoriesIds)
|
||||||
|
.then(() => {
|
||||||
|
closeAlert(name);
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'the_item_categories_has_been_deleted_successfully',
|
||||||
|
}),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((errors) => {
|
||||||
|
closeAlert(name);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
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}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<FormattedHTMLMessage
|
||||||
|
id={
|
||||||
|
'once_delete_these_item_categories_you_will_not_able_restore_them'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withAlertStoreConnect(),
|
||||||
|
withAlertActions,
|
||||||
|
withItemCategoriesActions,
|
||||||
|
)(ItemCategoryBulkDeleteAlert);
|
||||||
81
client/src/containers/Alerts/Item/ItemCategoryDeleteAlert.js
Normal file
81
client/src/containers/Alerts/Item/ItemCategoryDeleteAlert.js
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import React 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();
|
||||||
|
|
||||||
|
// handle cancel delete item category alert.
|
||||||
|
const handleCancelItemCategoryDelete = () => {
|
||||||
|
closeAlert(name);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle alert confirm delete item category.
|
||||||
|
const handleConfirmItemDelete = () => {
|
||||||
|
requestDeleteItemCategory(itemCategoryId)
|
||||||
|
.then(() => {
|
||||||
|
closeAlert(name);
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'the_item_category_has_been_deleted_successfully',
|
||||||
|
}),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
queryCache.invalidateQueries('items-categories-list');
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
closeAlert(name);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'delete'} />}
|
||||||
|
icon="trash"
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
isOpen={isOpen}
|
||||||
|
onCancel={handleCancelItemCategoryDelete}
|
||||||
|
onConfirm={handleConfirmItemDelete}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<FormattedHTMLMessage
|
||||||
|
id={'once_delete_this_item_category_you_will_able_to_restore_it'}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withAlertStoreConnect(),
|
||||||
|
withAlertActions,
|
||||||
|
withItemCategoriesActions,
|
||||||
|
)(ItemCategoryDeleteAlert);
|
||||||
@@ -1,23 +1,20 @@
|
|||||||
import React, { useEffect, useState, useCallback, useMemo } from 'react';
|
import React, { useEffect, useCallback } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import { Alert, Intent } from '@blueprintjs/core';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import {
|
|
||||||
FormattedMessage as T,
|
|
||||||
FormattedHTMLMessage,
|
|
||||||
useIntl,
|
|
||||||
} from 'react-intl';
|
|
||||||
|
|
||||||
import AppToaster from 'components/AppToaster';
|
|
||||||
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
|
||||||
|
import ItemsAlerts from './ItemsAlerts';
|
||||||
import ItemCategoriesDataTable from 'containers/Items/ItemCategoriesTable';
|
import ItemCategoriesDataTable from 'containers/Items/ItemCategoriesTable';
|
||||||
import ItemsCategoryActionsBar from 'containers/Items/ItemsCategoryActionsBar';
|
import ItemsCategoryActionsBar from 'containers/Items/ItemsCategoryActionsBar';
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import withResourceActions from 'containers/Resources/withResourcesActions';
|
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
import withItemCategoriesActions from 'containers/Items/withItemCategoriesActions';
|
import withItemCategoriesActions from 'containers/Items/withItemCategoriesActions';
|
||||||
|
import withAlertsActions from 'containers/Alert/withAlertActions';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,15 +24,12 @@ const ItemCategoryList = ({
|
|||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
changePageTitle,
|
changePageTitle,
|
||||||
|
|
||||||
// #withViewsActions
|
// #withAlertsActions.
|
||||||
requestFetchResourceViews,
|
openAlert,
|
||||||
requestFetchResourceFields,
|
|
||||||
|
|
||||||
// #withItemCategoriesActions
|
// #withItemCategoriesActions
|
||||||
requestFetchItemCategories,
|
requestFetchItemCategories,
|
||||||
requestDeleteItemCategory,
|
setSelectedRowsCategories,
|
||||||
requestDeleteBulkItemCategories,
|
|
||||||
addItemCategoriesTableQueries,
|
|
||||||
|
|
||||||
// #withDialog
|
// #withDialog
|
||||||
openDialog,
|
openDialog,
|
||||||
@@ -43,12 +37,6 @@ const ItemCategoryList = ({
|
|||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
const [selectedRows, setSelectedRows] = useState([]);
|
|
||||||
const [filter, setFilter] = useState({});
|
|
||||||
const [deleteCategory, setDeleteCategory] = useState(false);
|
|
||||||
const [bulkDelete, setBulkDelete] = useState(false);
|
|
||||||
const [tableLoading, setTableLoading] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
id
|
id
|
||||||
? changePageTitle(formatMessage({ id: 'edit_category_details' }))
|
? changePageTitle(formatMessage({ id: 'edit_category_details' }))
|
||||||
@@ -59,156 +47,35 @@ const ItemCategoryList = ({
|
|||||||
requestFetchItemCategories(),
|
requestFetchItemCategories(),
|
||||||
);
|
);
|
||||||
|
|
||||||
const fetchResourceFields = useQuery(
|
|
||||||
['resource-fields', 'item_category'],
|
|
||||||
(key, resourceName) => requestFetchResourceFields(resourceName),
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleFilterChanged = useCallback(() => {}, []);
|
const handleFilterChanged = useCallback(() => {}, []);
|
||||||
|
|
||||||
// Handle selected rows change.
|
// Handle selected rows change.
|
||||||
const handleSelectedRowsChange = useCallback(
|
const handleSelectedRowsChange = (selectedRows) => {
|
||||||
(itemCategories) => {
|
const selectedRowsIds = selectedRows.map((r) => r.id);
|
||||||
setSelectedRows(itemCategories);
|
setSelectedRowsCategories(selectedRowsIds);
|
||||||
},
|
|
||||||
[setSelectedRows],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleFetchData = useCallback(
|
|
||||||
({ pageIndex, pageSize, sortBy }) => {
|
|
||||||
const page = pageIndex + 1;
|
|
||||||
|
|
||||||
addItemCategoriesTableQueries({
|
|
||||||
...(sortBy.length > 0
|
|
||||||
? {
|
|
||||||
column_sort_by: sortBy[0].id,
|
|
||||||
sort_order: sortBy[0].desc ? 'desc' : 'asc',
|
|
||||||
}
|
|
||||||
: {}),
|
|
||||||
page_size: pageSize,
|
|
||||||
page,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[addItemCategoriesTableQueries],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleDeleteCategory = (itemCategory) => {
|
|
||||||
setDeleteCategory(itemCategory);
|
|
||||||
};
|
|
||||||
const handleCancelItemDelete = () => {
|
|
||||||
setDeleteCategory(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle alert confirm delete item category.
|
// Handle delete Item.
|
||||||
const handleConfirmItemDelete = () => {
|
const handleDeleteCategory = ({ id }) => {
|
||||||
requestDeleteItemCategory(deleteCategory.id)
|
openAlert('item-category-delete', { itemCategoryId: id });
|
||||||
.then(() => {
|
|
||||||
setDeleteCategory(false);
|
|
||||||
AppToaster.show({
|
|
||||||
message: formatMessage({
|
|
||||||
id: 'the_item_category_has_been_deleted_successfully',
|
|
||||||
}),
|
|
||||||
intent: Intent.SUCCESS,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setDeleteCategory(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle Edit item category.
|
||||||
const handleEditCategory = (category) => {
|
const handleEditCategory = (category) => {
|
||||||
openDialog('item-category-form', { action: 'edit', id: category.id });
|
openDialog('item-category-form', { action: 'edit', id: category.id });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle itemCategories bulk delete.
|
|
||||||
const handleBulkDelete = useCallback(
|
|
||||||
(itemsCategoriesIds) => {
|
|
||||||
setBulkDelete(itemsCategoriesIds);
|
|
||||||
},
|
|
||||||
[setBulkDelete],
|
|
||||||
);
|
|
||||||
|
|
||||||
// handle confirm itemCategories bulk delete.
|
|
||||||
const handleConfirmBulkDelete = useCallback(() => {
|
|
||||||
requestDeleteBulkItemCategories(bulkDelete)
|
|
||||||
.then(() => {
|
|
||||||
setBulkDelete(false);
|
|
||||||
AppToaster.show({
|
|
||||||
message: formatMessage({
|
|
||||||
id: 'the_item_categories_has_been_deleted_successfully',
|
|
||||||
}),
|
|
||||||
intent: Intent.SUCCESS,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((errors) => {
|
|
||||||
setBulkDelete(false);
|
|
||||||
});
|
|
||||||
}, [requestDeleteBulkItemCategories, bulkDelete, formatMessage]);
|
|
||||||
|
|
||||||
//Handel cancel itemCategories bulk delete.
|
|
||||||
const handleCancelBulkDelete = useCallback(() => {
|
|
||||||
setBulkDelete(false);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Calculates the data table selected rows count.
|
|
||||||
const selectedRowsCount = useMemo(() => Object.values(selectedRows).length, [
|
|
||||||
selectedRows,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardInsider
|
<DashboardInsider name={'item-category-list'}>
|
||||||
loading={fetchResourceFields.isFetching || fetchCategories.isFetching}
|
<ItemsCategoryActionsBar onFilterChanged={handleFilterChanged} />
|
||||||
name={'item-category-list'}
|
|
||||||
>
|
|
||||||
<ItemsCategoryActionsBar
|
|
||||||
selectedRows={selectedRows}
|
|
||||||
onFilterChanged={handleFilterChanged}
|
|
||||||
onBulkDelete={handleBulkDelete}
|
|
||||||
/>
|
|
||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<ItemCategoriesDataTable
|
<ItemCategoriesDataTable
|
||||||
onEditCategory={handleEditCategory}
|
|
||||||
onFetchData={handleFetchData}
|
|
||||||
onSelectedRowsChange={handleSelectedRowsChange}
|
|
||||||
onDeleteCategory={handleDeleteCategory}
|
onDeleteCategory={handleDeleteCategory}
|
||||||
|
onEditCategory={handleEditCategory}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Alert
|
|
||||||
cancelButtonText={<T id={'cancel'} />}
|
|
||||||
confirmButtonText={<T id={'delete'} />}
|
|
||||||
icon="trash"
|
|
||||||
intent={Intent.DANGER}
|
|
||||||
isOpen={deleteCategory}
|
|
||||||
onCancel={handleCancelItemDelete}
|
|
||||||
onConfirm={handleConfirmItemDelete}
|
|
||||||
>
|
|
||||||
<p>
|
|
||||||
<FormattedHTMLMessage
|
|
||||||
id={'once_delete_this_item_category_you_will_able_to_restore_it'}
|
|
||||||
/>
|
|
||||||
</p>
|
|
||||||
</Alert>
|
|
||||||
|
|
||||||
<Alert
|
|
||||||
cancelButtonText={<T id={'cancel'} />}
|
|
||||||
confirmButtonText={`${formatMessage({
|
|
||||||
id: 'delete',
|
|
||||||
})} (${selectedRowsCount})`}
|
|
||||||
icon="trash"
|
|
||||||
intent={Intent.DANGER}
|
|
||||||
isOpen={bulkDelete}
|
|
||||||
onCancel={handleCancelBulkDelete}
|
|
||||||
onConfirm={handleConfirmBulkDelete}
|
|
||||||
>
|
|
||||||
<p>
|
|
||||||
<FormattedHTMLMessage
|
|
||||||
id={
|
|
||||||
'once_delete_these_item_categories_you_will_not_able_restore_them'
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</p>
|
|
||||||
</Alert>
|
|
||||||
</DashboardPageContent>
|
</DashboardPageContent>
|
||||||
|
<ItemsAlerts />
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -217,5 +84,5 @@ export default compose(
|
|||||||
withItemCategoriesActions,
|
withItemCategoriesActions,
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
withResourceActions,
|
withAlertsActions,
|
||||||
)(ItemCategoryList);
|
)(ItemCategoryList);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import classNames from 'classnames';
|
|||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import LoadingIndicator from 'components/LoadingIndicator';
|
import LoadingIndicator from 'components/LoadingIndicator';
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
import { useIsValuePassed } from 'hooks';
|
||||||
import DataTable from 'components/DataTable';
|
import DataTable from 'components/DataTable';
|
||||||
|
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
@@ -32,10 +33,10 @@ const ItemsCategoryList = ({
|
|||||||
// #ownProps
|
// #ownProps
|
||||||
onFetchData,
|
onFetchData,
|
||||||
onDeleteCategory,
|
onDeleteCategory,
|
||||||
onEditCategory,
|
|
||||||
onSelectedRowsChange,
|
onSelectedRowsChange,
|
||||||
}) => {
|
}) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const isLoadedBefore = useIsValuePassed(categoriesTableLoading, false);
|
||||||
|
|
||||||
const handelEditCategory = useCallback(
|
const handelEditCategory = useCallback(
|
||||||
(category) => () => {
|
(category) => () => {
|
||||||
@@ -143,7 +144,10 @@ const ItemsCategoryList = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.DASHBOARD_DATATABLE)}>
|
<div className={classNames(CLASSES.DASHBOARD_DATATABLE)}>
|
||||||
<LoadingIndicator mount={false}>
|
<LoadingIndicator
|
||||||
|
loading={categoriesTableLoading && !isLoadedBefore}
|
||||||
|
mount={false}
|
||||||
|
>
|
||||||
<DataTable
|
<DataTable
|
||||||
noInitialFetch={true}
|
noInitialFetch={true}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
@@ -154,7 +158,6 @@ const ItemsCategoryList = ({
|
|||||||
expandable={true}
|
expandable={true}
|
||||||
sticky={true}
|
sticky={true}
|
||||||
onSelectedRowsChange={handleSelectedRowsChange}
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
loading={categoriesTableLoading}
|
|
||||||
rowContextMenu={handleRowContextMenu}
|
rowContextMenu={handleRowContextMenu}
|
||||||
/>
|
/>
|
||||||
</LoadingIndicator>
|
</LoadingIndicator>
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import ItemDeleteAlert from 'containers/Alerts/Item/ItemDeleteAlert';
|
|||||||
import ItemInactivateAlert from 'containers/Alerts/Item/ItemInactivateAlert';
|
import ItemInactivateAlert from 'containers/Alerts/Item/ItemInactivateAlert';
|
||||||
import ItemActivateAlert from 'containers/Alerts/Item/ItemActivateAlert';
|
import ItemActivateAlert from 'containers/Alerts/Item/ItemActivateAlert';
|
||||||
import ItemBulkDeleteAlert from 'containers/Alerts/Item/ItemBulkDeleteAlert';
|
import ItemBulkDeleteAlert from 'containers/Alerts/Item/ItemBulkDeleteAlert';
|
||||||
|
import ItemCategoryDeleteAlert from 'containers/Alerts/Item/ItemCategoryDeleteAlert';
|
||||||
|
import ItemCategoryBulkDeleteAlert from 'containers/Alerts/Item/ItemCategoryBulkDeleteAlert';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Items alert.
|
* Items alert.
|
||||||
@@ -14,6 +16,8 @@ export default function ItemsAlerts() {
|
|||||||
<ItemInactivateAlert name={'item-inactivate'} />
|
<ItemInactivateAlert name={'item-inactivate'} />
|
||||||
<ItemActivateAlert name={'item-activate'} />
|
<ItemActivateAlert name={'item-activate'} />
|
||||||
<ItemBulkDeleteAlert name={'items-bulk-delete'} />
|
<ItemBulkDeleteAlert name={'items-bulk-delete'} />
|
||||||
|
<ItemCategoryDeleteAlert name={'item-category-delete'} />
|
||||||
|
<ItemCategoryBulkDeleteAlert name={'item-categories-bulk-delete'} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,38 +11,29 @@ import {
|
|||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import { If, Icon } from 'components';
|
import { If, Icon } from 'components';
|
||||||
|
|
||||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
import FilterDropdown from 'components/FilterDropdown';
|
|
||||||
|
|
||||||
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
|
||||||
import withItemCategories from './withItemCategories';
|
import withItemCategories from './withItemCategories';
|
||||||
import withItemCategoriesActions from './withItemCategoriesActions';
|
import withItemCategoriesActions from './withItemCategoriesActions';
|
||||||
|
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
const ItemsCategoryActionsBar = ({
|
const ItemsCategoryActionsBar = ({
|
||||||
// #withResourceDetail
|
|
||||||
resourceFields,
|
|
||||||
|
|
||||||
// #withDialog
|
// #withDialog
|
||||||
openDialog,
|
openDialog,
|
||||||
|
|
||||||
// #withItemCategories
|
// #withItemCategories
|
||||||
categoriesViews,
|
itemCategoriesSelectedRows,
|
||||||
|
|
||||||
// #withItemCategoriesActions
|
// #withAlertActions
|
||||||
addItemCategoriesTableQueries,
|
openAlert,
|
||||||
|
|
||||||
// #ownProps
|
|
||||||
selectedRows = [],
|
|
||||||
onFilterChanged,
|
|
||||||
onBulkDelete,
|
|
||||||
}) => {
|
}) => {
|
||||||
const [filterCount, setFilterCount] = useState(0);
|
const [filterCount, setFilterCount] = useState(0);
|
||||||
|
|
||||||
@@ -50,30 +41,12 @@ const ItemsCategoryActionsBar = ({
|
|||||||
openDialog('item-category-form', {});
|
openDialog('item-category-form', {});
|
||||||
}, [openDialog]);
|
}, [openDialog]);
|
||||||
|
|
||||||
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
const handelBulkDelete = () => {
|
||||||
selectedRows,
|
openAlert('item-categories-bulk-delete', {
|
||||||
]);
|
itemCategoriesIds: itemCategoriesSelectedRows,
|
||||||
|
});
|
||||||
// const filterDropdown = FilterDropdown({
|
};
|
||||||
// fields: resourceFields,
|
console.log(itemCategoriesSelectedRows, 'EE');
|
||||||
// initialCondition: {
|
|
||||||
// fieldKey: 'name',
|
|
||||||
// compatator: 'contains',
|
|
||||||
// value: '',
|
|
||||||
// },
|
|
||||||
// onFilterChange: (filterConditions) => {
|
|
||||||
// setFilterCount(filterConditions.length || 0);
|
|
||||||
// addItemCategoriesTableQueries({
|
|
||||||
// filter_roles: filterConditions || '',
|
|
||||||
// });
|
|
||||||
// onFilterChanged && onFilterChanged(filterConditions);
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
const handelBulkDelete = useCallback(() => {
|
|
||||||
onBulkDelete && onBulkDelete(selectedRows.map((r) => r.id));
|
|
||||||
}, [onBulkDelete, selectedRows]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
@@ -105,7 +78,7 @@ const ItemsCategoryActionsBar = ({
|
|||||||
/>
|
/>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|
||||||
<If condition={hasSelectedRows}>
|
<If condition={itemCategoriesSelectedRows.length}>
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||||
@@ -130,20 +103,12 @@ const ItemsCategoryActionsBar = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
|
||||||
resourceName: 'items_categories',
|
|
||||||
});
|
|
||||||
const withItemsCategoriesActionsBar = connect(mapStateToProps);
|
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withItemsCategoriesActionsBar,
|
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withResourceDetail(({ resourceFields }) => ({
|
withItemCategories(({ itemCategoriesSelectedRows }) => ({
|
||||||
resourceFields,
|
itemCategoriesSelectedRows,
|
||||||
})),
|
})),
|
||||||
// withItemCategories(({ categoriesViews }) => ({
|
|
||||||
// categoriesViews,
|
|
||||||
// })),
|
|
||||||
withItemCategoriesActions,
|
withItemCategoriesActions,
|
||||||
|
withAlertActions,
|
||||||
)(ItemsCategoryActionsBar);
|
)(ItemsCategoryActionsBar);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export default (mapState) => {
|
|||||||
categoriesList: getItemsCategoriesList(state, props),
|
categoriesList: getItemsCategoriesList(state, props),
|
||||||
itemCategoriesViews: getResourceViews(state, props, 'items_categories'),
|
itemCategoriesViews: getResourceViews(state, props, 'items_categories'),
|
||||||
categoriesTableLoading: state.itemCategories.loading,
|
categoriesTableLoading: state.itemCategories.loading,
|
||||||
|
itemCategoriesSelectedRows: state.itemCategories.selectedRows,
|
||||||
};
|
};
|
||||||
return mapState ? mapState(mapped, state, props) : mapState;
|
return mapState ? mapState(mapped, state, props) : mapState;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ export const mapDispatchToProps = (dispatch) => ({
|
|||||||
type: t.ITEM_CATEGORIES_TABLE_QUERIES_ADD,
|
type: t.ITEM_CATEGORIES_TABLE_QUERIES_ADD,
|
||||||
queries,
|
queries,
|
||||||
}),
|
}),
|
||||||
|
setSelectedRowsCategories: (selectedRows) =>
|
||||||
|
dispatch({
|
||||||
|
type: t.ITEM_CATEGORY_SELECTED_ROW_SET,
|
||||||
|
payload: { selectedRows },
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps);
|
export default connect(null, mapDispatchToProps);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { createReducer } from '@reduxjs/toolkit';
|
|||||||
const initialState = {
|
const initialState = {
|
||||||
categories: {},
|
categories: {},
|
||||||
loading: false,
|
loading: false,
|
||||||
|
selectedRows: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createReducer(initialState, {
|
export default createReducer(initialState, {
|
||||||
@@ -45,6 +46,11 @@ export default createReducer(initialState, {
|
|||||||
});
|
});
|
||||||
state.categories = categories;
|
state.categories = categories;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[t.ITEM_CATEGORY_SELECTED_ROW_SET]: (state, action) => {
|
||||||
|
const { selectedRows } = action.payload;
|
||||||
|
state.selectedRows = selectedRows;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getCategoryId = (state, id) => {
|
export const getCategoryId = (state, id) => {
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ export default {
|
|||||||
ITEM_CATEGORIES_BULK_DELETE: 'ITEM_CATEGORIES_BULK_DELETE',
|
ITEM_CATEGORIES_BULK_DELETE: 'ITEM_CATEGORIES_BULK_DELETE',
|
||||||
ITEM_CATEGORIES_TABLE_QUERIES_ADD: 'ITEM_CATEGORIES_TABLE_QUERIES_ADD',
|
ITEM_CATEGORIES_TABLE_QUERIES_ADD: 'ITEM_CATEGORIES_TABLE_QUERIES_ADD',
|
||||||
ITEM_CATEGORIES_SET_CURRENT_VIEW: 'ITEM_CATEGORIES_SET_CURRENT_VIEW',
|
ITEM_CATEGORIES_SET_CURRENT_VIEW: 'ITEM_CATEGORIES_SET_CURRENT_VIEW',
|
||||||
|
ITEM_CATEGORY_SELECTED_ROW_SET: 'ITEM_CATEGORY_SELECTED_ROW_SET',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user