mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
fix: customer view.
This commit is contained in:
@@ -20,17 +20,20 @@ import FilterDropdown from 'components/FilterDropdown';
|
|||||||
import { If, DashboardActionViewsList } from 'components';
|
import { If, DashboardActionViewsList } from 'components';
|
||||||
|
|
||||||
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import withCustomers from 'containers/Customers/withCustomers';
|
||||||
import addCustomersTableQueries from 'containers/Customers/withCustomersActions';
|
|
||||||
import { compose } from 'utils';
|
|
||||||
import withCustomersActions from 'containers/Customers/withCustomersActions';
|
import withCustomersActions from 'containers/Customers/withCustomersActions';
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
const CustomerActionsBar = ({
|
const CustomerActionsBar = ({
|
||||||
// #withResourceDetail
|
// #withResourceDetail
|
||||||
resourceFields,
|
resourceFields,
|
||||||
|
|
||||||
|
// #withCustomers
|
||||||
|
customersViews,
|
||||||
|
|
||||||
//#withCustomersActions
|
//#withCustomersActions
|
||||||
addCustomersTableQueries,
|
addCustomersTableQueries,
|
||||||
|
changeCustomerView,
|
||||||
|
|
||||||
// #ownProps
|
// #ownProps
|
||||||
selectedRows = [],
|
selectedRows = [],
|
||||||
@@ -45,16 +48,6 @@ const CustomerActionsBar = ({
|
|||||||
history.push('/customers/new');
|
history.push('/customers/new');
|
||||||
}, [history]);
|
}, [history]);
|
||||||
|
|
||||||
// const filterDropdown = FilterDropdown({
|
|
||||||
// fields: resourceFields,
|
|
||||||
// onFilterChange: (filterConditions) => {
|
|
||||||
// setFilterCount(filterConditions.length || 0);
|
|
||||||
// addCustomersTableQueries({
|
|
||||||
// filter_roles: filterConditions || '',
|
|
||||||
// });
|
|
||||||
// onFilterChanged && onFilterChanged(filterConditions);
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
||||||
selectedRows,
|
selectedRows,
|
||||||
@@ -64,12 +57,20 @@ const CustomerActionsBar = ({
|
|||||||
onBulkDelete && onBulkDelete(selectedRows.map((r) => r.id));
|
onBulkDelete && onBulkDelete(selectedRows.map((r) => r.id));
|
||||||
}, [onBulkDelete, selectedRows]);
|
}, [onBulkDelete, selectedRows]);
|
||||||
|
|
||||||
|
const handleTabChange = (viewId) => {
|
||||||
|
changeCustomerView(viewId.id || -1);
|
||||||
|
addCustomersTableQueries({
|
||||||
|
custom_view_id: viewId.id || null,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
<DashboardActionViewsList
|
<DashboardActionViewsList
|
||||||
resourceName={'customers'}
|
resourceName={'customers'}
|
||||||
views={[]}
|
views={customersViews}
|
||||||
|
onChange={handleTabChange}
|
||||||
/>
|
/>
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
|
|
||||||
@@ -133,4 +134,7 @@ export default compose(
|
|||||||
withResourceDetail(({ resourceFields }) => ({
|
withResourceDetail(({ resourceFields }) => ({
|
||||||
resourceFields,
|
resourceFields,
|
||||||
})),
|
})),
|
||||||
|
withCustomers(({ customersViews }) => ({
|
||||||
|
customersViews,
|
||||||
|
})),
|
||||||
)(CustomerActionsBar);
|
)(CustomerActionsBar);
|
||||||
|
|||||||
@@ -55,13 +55,14 @@ function CustomersList({
|
|||||||
}, [changePageTitle, formatMessage]);
|
}, [changePageTitle, formatMessage]);
|
||||||
|
|
||||||
// Fetch customers resource views and fields.
|
// Fetch customers resource views and fields.
|
||||||
// const fetchResourceViews = useQuery(['resource-views', 'customers'],
|
const fetchResourceViews = useQuery(
|
||||||
// () => requestFetchResourceViews('customers')
|
['resource-views', 'customers'],
|
||||||
// );
|
(key, resourceName) => requestFetchResourceViews(resourceName),
|
||||||
|
);
|
||||||
|
|
||||||
const fetchCustomers = useQuery(
|
const fetchCustomers = useQuery(
|
||||||
['customers-table', customersTableQuery],
|
['customers-table', customersTableQuery],
|
||||||
() => requestFetchCustomers(),
|
(key, query) => requestFetchCustomers({ ...query }),
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleEditCustomer = useCallback(
|
const handleEditCustomer = useCallback(
|
||||||
@@ -84,7 +85,7 @@ function CustomersList({
|
|||||||
setDeleteCustomer(false);
|
setDeleteCustomer(false);
|
||||||
}, [setDeleteCustomer]);
|
}, [setDeleteCustomer]);
|
||||||
|
|
||||||
const transformErrors = (errors) => {
|
const transformErrors = (errors) => {
|
||||||
if (errors.some((e) => e.type === 'CUSTOMER.HAS.SALES_INVOICES')) {
|
if (errors.some((e) => e.type === 'CUSTOMER.HAS.SALES_INVOICES')) {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
@@ -132,16 +133,6 @@ function CustomersList({
|
|||||||
selectedRows,
|
selectedRows,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Handle filter change to re-fetch the items.
|
|
||||||
const handleFilterChanged = useCallback(
|
|
||||||
(filterConditions) => {
|
|
||||||
// addCustomersTableQueries({
|
|
||||||
// filter_roles: filterConditions || '',
|
|
||||||
// });
|
|
||||||
},
|
|
||||||
[addCustomersTableQueries],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handle Customers bulk delete button click.,
|
// Handle Customers bulk delete button click.,
|
||||||
const handleBulkDelete = useCallback(
|
const handleBulkDelete = useCallback(
|
||||||
(customersIds) => {
|
(customersIds) => {
|
||||||
@@ -173,10 +164,12 @@ function CustomersList({
|
|||||||
}, [requestDeleteBulkCustomers, bulkDelete, formatMessage]);
|
}, [requestDeleteBulkCustomers, bulkDelete, formatMessage]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardInsider name={'customers-list'}>
|
<DashboardInsider
|
||||||
|
loading={fetchResourceViews.isFetching}
|
||||||
|
name={'customers-list'}
|
||||||
|
>
|
||||||
<CustomerActionsBar
|
<CustomerActionsBar
|
||||||
selectedRows={selectedRows}
|
selectedRows={selectedRows}
|
||||||
onFilterChanged={handleFilterChanged}
|
|
||||||
onBulkDelete={handleBulkDelete}
|
onBulkDelete={handleBulkDelete}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -188,7 +181,6 @@ function CustomersList({
|
|||||||
>
|
>
|
||||||
<CustomersViewsTabs />
|
<CustomersViewsTabs />
|
||||||
<CustomersTable
|
<CustomersTable
|
||||||
loading={fetchCustomers.isFetching}
|
|
||||||
onDeleteCustomer={handleDeleteCustomer}
|
onDeleteCustomer={handleDeleteCustomer}
|
||||||
onEditCustomer={handleEditCustomer}
|
onEditCustomer={handleEditCustomer}
|
||||||
onSelectedRowsChange={handleSelectedRowsChange}
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useMemo } from 'react';
|
import React, { useEffect, useMemo } from 'react';
|
||||||
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||||
import { compose } from 'redux';
|
import { compose } from 'redux';
|
||||||
import { useParams, withRouter, useHistory } from 'react-router-dom';
|
import { useParams, withRouter } from 'react-router-dom';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { DashboardViewsTabs } from 'components';
|
import { DashboardViewsTabs } from 'components';
|
||||||
@@ -9,6 +9,7 @@ import { DashboardViewsTabs } from 'components';
|
|||||||
import withCustomers from 'containers/Customers/withCustomers';
|
import withCustomers from 'containers/Customers/withCustomers';
|
||||||
import withCustomersActions from 'containers/Customers/withCustomersActions';
|
import withCustomersActions from 'containers/Customers/withCustomersActions';
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withViewDetail from 'containers/Views/withViewDetails';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,29 +25,35 @@ function CustomersViewsTabs({
|
|||||||
|
|
||||||
// #withCustomersActions
|
// #withCustomersActions
|
||||||
addCustomersTableQueries,
|
addCustomersTableQueries,
|
||||||
|
changeCustomerView,
|
||||||
|
|
||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
setTopbarEditView,
|
setTopbarEditView,
|
||||||
changePageSubtitle,
|
changePageSubtitle,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
|
||||||
const { custom_view_id: customViewId = null } = useParams();
|
const { custom_view_id: customViewId = null } = useParams();
|
||||||
|
|
||||||
const tabs = useMemo(() => customersViews.map((view) => ({
|
|
||||||
...pick(view, ['name', 'id']),
|
|
||||||
}), [customersViews]));
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTopbarEditView(customViewId);
|
|
||||||
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
||||||
// addCustomersTableQueries({
|
setTopbarEditView(customViewId);
|
||||||
// custom_view_id: customViewId,
|
|
||||||
// });
|
|
||||||
return () => {
|
|
||||||
setTopbarEditView(null);
|
|
||||||
changePageSubtitle('');
|
|
||||||
};
|
|
||||||
}, [customViewId]);
|
}, [customViewId]);
|
||||||
|
|
||||||
|
const tabs = useMemo(() =>
|
||||||
|
customersViews.map(
|
||||||
|
(view) => ({
|
||||||
|
...pick(view, ['name', 'id']),
|
||||||
|
}),
|
||||||
|
[customersViews],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTabsChange = (viewId) => {
|
||||||
|
changeCustomerView(viewId || -1);
|
||||||
|
addCustomersTableQueries({
|
||||||
|
custom_view_id: viewId || null,
|
||||||
|
});
|
||||||
|
setTopbarEditView(viewId);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Navbar className="navbar--dashboard-views">
|
<Navbar className="navbar--dashboard-views">
|
||||||
@@ -55,6 +62,7 @@ function CustomersViewsTabs({
|
|||||||
initialViewId={customViewId}
|
initialViewId={customViewId}
|
||||||
resourceName={'customers'}
|
resourceName={'customers'}
|
||||||
tabs={tabs}
|
tabs={tabs}
|
||||||
|
onChange={handleTabsChange}
|
||||||
/>
|
/>
|
||||||
</NavbarGroup>
|
</NavbarGroup>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
@@ -72,7 +80,8 @@ export default compose(
|
|||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withCustomersViewsTabs,
|
withCustomersViewsTabs,
|
||||||
withCustomersActions,
|
withCustomersActions,
|
||||||
|
withViewDetail(),
|
||||||
withCustomers(({ customersViews }) => ({
|
withCustomers(({ customersViews }) => ({
|
||||||
customersViews,
|
customersViews,
|
||||||
})),
|
})),
|
||||||
)(CustomersViewsTabs);
|
)(CustomersViewsTabs);
|
||||||
|
|||||||
@@ -19,8 +19,14 @@ export const mapDispatchToProps = (dispatch) => ({
|
|||||||
addCustomersTableQueries: (queries) =>
|
addCustomersTableQueries: (queries) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.CUSTOMERS_TABLE_QUERIES_ADD,
|
type: t.CUSTOMERS_TABLE_QUERIES_ADD,
|
||||||
payload: { queries }
|
payload: { queries },
|
||||||
}),
|
}),
|
||||||
|
changeCustomerView: (id) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.CUSTOMERS_SET_CURRENT_VIEW,
|
||||||
|
currentViewId: parseInt(id, 10),
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps);
|
export default connect(null, mapDispatchToProps);
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ export const fetchCustomers = ({ query }) => {
|
|||||||
type: t.CUSTOMERS_PAGE_SET,
|
type: t.CUSTOMERS_PAGE_SET,
|
||||||
payload: {
|
payload: {
|
||||||
customers: response.data.customers,
|
customers: response.data.customers,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId:
|
||||||
|
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||||
paginationMeta: response.data.pagination,
|
paginationMeta: response.data.pagination,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -62,7 +63,8 @@ export const fetchCustomers = ({ query }) => {
|
|||||||
type: t.CUSTOMERS_PAGINATION_SET,
|
type: t.CUSTOMERS_PAGINATION_SET,
|
||||||
payload: {
|
payload: {
|
||||||
pagination: response.data.pagination,
|
pagination: response.data.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId:
|
||||||
|
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export default createReducer(initialState, {
|
|||||||
state.views[viewId] = {
|
state.views[viewId] = {
|
||||||
...view,
|
...view,
|
||||||
pages: {
|
pages: {
|
||||||
|
|
||||||
...(state.views?.[viewId]?.pages || {}),
|
...(state.views?.[viewId]?.pages || {}),
|
||||||
[paginationMeta.page]: {
|
[paginationMeta.page]: {
|
||||||
ids: customers.map((i) => i.id),
|
ids: customers.map((i) => i.id),
|
||||||
@@ -64,6 +65,10 @@ export default createReducer(initialState, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[t.CUSTOMERS_SET_CURRENT_VIEW]: (state, action) => {
|
||||||
|
state.currentViewId = action.currentViewId;
|
||||||
|
},
|
||||||
|
|
||||||
[t.CUSTOMERS_TABLE_LOADING]: (state, action) => {
|
[t.CUSTOMERS_TABLE_LOADING]: (state, action) => {
|
||||||
const { loading } = action.payload;
|
const { loading } = action.payload;
|
||||||
state.loading = loading;
|
state.loading = loading;
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ export default {
|
|||||||
CUSTOMER_DELETE: 'CUSTOMER_DELETE',
|
CUSTOMER_DELETE: 'CUSTOMER_DELETE',
|
||||||
CUSTOMERS_BULK_DELETE: 'CUSTOMERS_BULK_DELETE',
|
CUSTOMERS_BULK_DELETE: 'CUSTOMERS_BULK_DELETE',
|
||||||
CUSTOMERS_PAGINATION_SET: 'CUSTOMERS_PAGINATION_SET',
|
CUSTOMERS_PAGINATION_SET: 'CUSTOMERS_PAGINATION_SET',
|
||||||
|
CUSTOMERS_SET_CURRENT_VIEW: 'CUSTOMERS_SET_CURRENT_VIEW',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user