From cac6620ffe77cba65f3caac34c4b577a72212a5f Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Wed, 15 Apr 2020 01:29:46 +0200 Subject: [PATCH] fix bugs in items form. --- .../components/Accounts/AccountsDataTable.js | 7 +- client/src/components/Items/ItemForm.js | 100 ++++++++++++----- .../JournalEntry/ManualJournalsDataTable.js | 8 +- client/src/config/sidebarMenu.js | 4 +- client/src/connectors/Items.connect.js | 9 ++ .../src/connectors/ItemsCategory.connect.js | 2 + .../Dashboard/Accounts/AccountsChart.js | 3 +- .../containers/Dashboard/Items/ItemForm.js | 10 +- .../Dashboard/Items/ItemsActionsBar.js | 20 ++-- .../Dashboard/Items/ItemsDataTable.js | 105 +++++++++--------- .../containers/Dashboard/Items/ItemsList.js | 67 ++++++++--- .../Dashboard/Items/ItemsViewsTabs.js | 94 ++++++++++++++++ client/src/routes/dashboard.js | 15 ++- client/src/store/items/items.actions.js | 14 ++- client/src/store/items/items.reducer.js | 11 +- client/src/store/items/items.types.js | 5 + client/src/style/objects/form.scss | 1 + client/src/style/pages/accounts-chart.scss | 8 -- client/src/style/pages/dashboard.scss | 16 ++- client/src/style/pages/items.scss | 8 ++ 20 files changed, 378 insertions(+), 129 deletions(-) create mode 100644 client/src/containers/Dashboard/Items/ItemsViewsTabs.js 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} > - + + >