diff --git a/client/src/components/EstimateListField.js b/client/src/components/EstimateListField.js index ea37b794f..a7b94a662 100644 --- a/client/src/components/EstimateListField.js +++ b/client/src/components/EstimateListField.js @@ -1,39 +1,71 @@ import React, { useCallback, useMemo, useEffect, useState } from 'react'; -import { MenuItem, Button } from '@blueprintjs/core'; +import { MenuItem } from '@blueprintjs/core'; import ListSelect from 'components/ListSelect'; import { FormattedMessage as T } from 'react-intl'; function EstimateListField({ products, + initialProductId, selectedProductId, - onProductSelected, defautlSelectText = , + onProductSelected, }) { + const initialProduct = useMemo( + () => products.find((a) => a.id === initialProductId), + [initialProductId], + ); + + const [selectedProduct, setSelectedProduct] = useState( + initialProduct || null, + ); + + useEffect(() => { + if (typeof selectedProductId !== 'undefined') { + const product = selectedProductId + ? products.find((a) => a.id === selectedProductId) + : null; + setSelectedProduct(product); + } + }, [selectedProductId, products, setSelectedProduct]); + const onProductSelect = useCallback( (product) => { + setSelectedProduct({ ...product }); onProductSelected && onProductSelected(product); }, [onProductSelected], ); const productRenderer = useCallback( - (item, { handleClick, modifiers, query }) => ( - + (item, { handleClick }) => ( + ), [], ); + const filterProduct = useCallback((query, product, _index, exactMatch) => { + const normalizedTitle = product.name.toLowerCase(); + const normalizedQuery = query.toLowerCase(); + + if (exactMatch) { + return normalizedTitle === normalizedQuery; + } else { + return normalizedTitle.indexOf(normalizedQuery) >= 0; + } + }, []); + return ( } itemRenderer={productRenderer} + itemPredicate={filterProduct} popoverProps={{ minimal: true }} onItemSelect={onProductSelect} selectedItem={`${selectedProductId}`} selectedItemProp={'id'} labelProp={'name'} - defaultText={defautlSelectText} + defaultText={selectedProduct ? selectedProduct.name : defautlSelectText} /> ); } diff --git a/client/src/config/sidebarMenu.js b/client/src/config/sidebarMenu.js index 9e72634cf..8945fa9dd 100644 --- a/client/src/config/sidebarMenu.js +++ b/client/src/config/sidebarMenu.js @@ -42,21 +42,35 @@ export default [ text: , href: '/estimates/new', }, + // { + // text: , + // href: '/estimates', + // }, { text: , href: '/invoices/new', }, + // { + // text: , + // href: '/invoices', + // }, { text: , href: '/payment-receive/new', }, { divider: true, + text: , + href: '/invoices', }, { text: , href: '/receipts/new', }, + // { + // text: , + // href: '/receipts', + // }, ], }, { @@ -64,8 +78,12 @@ export default [ children: [ { text: , - href: '/bill/new', + href: '/bills/new', }, + // { + // text: , + // href: '/bills', + // }, { text: , }, diff --git a/client/src/containers/Purchases/Bill/BillActionsBar.js b/client/src/containers/Purchases/Bill/BillActionsBar.js new file mode 100644 index 000000000..dad1c4f2b --- /dev/null +++ b/client/src/containers/Purchases/Bill/BillActionsBar.js @@ -0,0 +1,148 @@ +import React, { useCallback, useState, useMemo } from 'react'; +import Icon from 'components/Icon'; +import { + Button, + Classes, + Menu, + MenuItem, + Popover, + NavbarDivider, + NavbarGroup, + PopoverInteractionKind, + Position, + Intent, +} from '@blueprintjs/core'; + +import classNames from 'classnames'; +import { useRouteMatch, useHistory } from 'react-router-dom'; +import { FormattedMessage as T, useIntl } from 'react-intl'; + +import { connect } from 'react-redux'; +import FilterDropdown from 'components/FilterDropdown'; +import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar'; + +import { If, DashboardActionViewsList } from 'components'; + +import withResourceDetail from 'containers/Resources/withResourceDetails'; +import withBillActions from './withBillActions'; +import withBills from './withBills'; + +import { compose } from 'utils'; + +function BillActionsBar({ + // #withResourceDetail + resourceFields, + + //#withBills + billsViews, + + //#withBillActions + addBillsTableQueries, + + // #own Porps + onFilterChanged, + selectedRows = [], +}) { + const history = useHistory(); + const { path } = useRouteMatch(); + const [filterCount, setFilterCount] = useState(0); + const { formatMessage } = useIntl(); + + const handleClickNewBill = useCallback(() => { + history.push('/bills/new'); + }, [history]); + + // const FilterDropdown = FilterDropdown({ + // initialCondition: { + // fieldKey: '', + // compatator: '', + // value: '', + // }, + // fields: resourceFields, + // onFilterChange: (filterConditions) => { + // addBillsTableQueries({ + // filter_roles: filterConditions || '', + // }); + // onFilterChanged && onFilterChanged(filterConditions); + // }, + // }); + + const hasSelectedRows = useMemo(() => selectedRows.length > 0, [ + selectedRows, + ]); + + return ( + + + + +