diff --git a/client/src/components/Accounts/AccountsDataTable.js b/client/src/components/Accounts/AccountsDataTable.js index 7e51e2ec6..84d678cc0 100644 --- a/client/src/components/Accounts/AccountsDataTable.js +++ b/client/src/components/Accounts/AccountsDataTable.js @@ -52,7 +52,7 @@ function AccountsDataTable({ openDialog('account-form', { action: 'edit', id: account.id }); }, [openDialog]); - const actionMenuList = account => ( + const actionMenuList = useCallback(account => ( @@ -66,7 +66,8 @@ function AccountsDataTable({ text='Delete Account' onClick={() => onDeleteAccount(account)} /> - ); + ), [handleEditAccount, onDeleteAccount, onInactiveAccount]); + const columns = useMemo(() => [ { id: 'name', @@ -139,7 +140,7 @@ function AccountsDataTable({ className: 'actions', width: 50, } - ], []); + ], [actionMenuList]); const selectionColumn = useMemo(() => ({ minWidth: 42, diff --git a/client/src/components/Items/ItemForm.js b/client/src/components/Items/ItemForm.js index 0ddcd0570..49d3b91bb 100644 --- a/client/src/components/Items/ItemForm.js +++ b/client/src/components/Items/ItemForm.js @@ -9,6 +9,7 @@ import { HTMLSelect, Button, Classes, + Checkbox, } from '@blueprintjs/core'; import { Row, Col } from 'react-grid-system'; import { Select } from '@blueprintjs/select'; @@ -19,11 +20,15 @@ import {compose} from 'utils'; import ErrorMessage from 'components/ErrorMessage'; import classNames from 'classnames'; import Icon from 'components/Icon'; +import ItemCategoryConnect from 'connectors/ItemsCategory.connect'; +import MoneyInputGroup from 'components/MoneyInputGroup'; const ItemForm = ({ requestSubmitItem, accounts, + categories, + categoriesList, }) => { const [selectedAccounts, setSelectedAccounts] = useState({}); @@ -35,24 +40,30 @@ const ItemForm = ({ ]), []); const validationSchema = Yup.object().shape({ + active: Yup.boolean(), name: Yup.string().required(), type: Yup.string().trim().required(), sku: Yup.string().required(), - cost_price: Yup.number().required(), - sell_price: Yup.number().required(), + cost_price: Yup.number(), + sell_price: Yup.number(), cost_account_id: Yup.number().required(), sell_account_id: Yup.number().required(), - inventory_account_id: Yup.number().required(), - category_id: Yup.number().required(), + inventory_account_id: Yup.number().when('type', { + is: (value) => value === 'inventory', + then: Yup.number().required(), + otherwise: Yup.number().nullable(), + }), + category_id: Yup.number().nullable(), stock: Yup.string() || Yup.boolean() }); const initialValues = useMemo(() => ({ + active: true, name: '', type: '', sku: '', - cost_price: null, - sell_price: null, + cost_price: 0, + sell_price: 0, cost_account_id: null, sell_account_id: null, inventory_account_id: null, @@ -80,9 +91,10 @@ const ItemForm = ({ }); const {errors, values, touched} = useMemo(() => formik, [formik]); - const accountItem = (item, { handleClick }) => ( + const accountItem = useCallback((item, { handleClick }) => ( - ); + ), []); + // Filter Account Items const filterAccounts = (query, account, _index, exactMatch) => { const normalizedTitle = account.name.toLowerCase(); @@ -104,6 +116,10 @@ const ItemForm = ({ }; }, [formik, selectedAccounts]); + const categoryItem = useCallback((item, { handleClick }) => ( + + ), []); + const getSelectedAccountLabel = useCallback((fieldName, defaultLabel) => { return typeof selectedAccounts[fieldName] !== 'undefined' ? selectedAccounts[fieldName].name : defaultLabel; @@ -112,6 +128,10 @@ const ItemForm = ({ const requiredSpan = useMemo(() => (*), []); const infoIcon = useMemo(() => (), []); + const handleMoneyInputChange = (fieldKey) => (e, value) => { + formik.setFieldValue(fieldKey, value); + }; + return (
@@ -175,8 +195,8 @@ const ItemForm = ({ )} > + + + +
-

Purchase Information

+

Purchase Information

} inline={true} > - + -

Sales Information

+

+ Sales Information +

} inline={true} > - + + >