From f6c5cae82ef4464a31b598a7e278bd5291a78a9e Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Wed, 29 Apr 2020 05:11:02 +0200 Subject: [PATCH] fix bugs. --- client/src/components/App.js | 28 ++--- .../Dashboard/DashboardContentRoute.js | 3 +- client/src/components/Dashboard/TopbarUser.js | 7 +- client/src/components/DataTable.js | 6 +- client/src/components/Items/ItemForm.js | 57 +++++----- .../src/components/Items/ItemsCategoryList.js | 92 +++++++-------- .../JournalEntry/ManualJournalActionsBar.js | 14 ++- .../JournalEntry/ManualJournalsDataTable.js | 75 ++++++++----- .../src/components/NProgress/AppProgress.js | 18 +++ client/src/components/Sidebar/SidebarMenu.js | 5 +- client/src/connectors/Items.connect.js | 6 +- .../src/connectors/ItemsCategory.connect.js | 3 +- .../src/connectors/ManualJournals.connect.js | 7 +- client/src/containers/Authentication/Login.js | 50 ++++----- .../Accounting/MakeJournalEntriesHeader.js | 36 +++--- .../Accounting/MakeJournalEntriesPage.js | 6 +- .../Accounting/ManualJournalsTable.js | 95 +++++++++++++--- .../Dashboard/Accounts/AccountsChart.js | 10 +- .../Dashboard/Dialogs/UserFormDialog.js | 11 -- .../containers/Dashboard/Items/ItemForm.js | 3 +- .../Dashboard/Items/ItemsActionsBar.js | 12 +- .../Items/ItemsCategoryActionsBar.js | 34 +++--- .../Dashboard/Items/ItemsCategoryList.js | 27 +++-- .../Dashboard/Items/ItemsDataTable.js | 34 ++++-- .../containers/Dashboard/Items/ItemsList.js | 22 +++- .../containers/Dashboard/Preferences/Users.js | 9 +- client/src/index.js | 8 ++ client/src/routes/authentication.js | 2 +- client/src/routes/dashboard.js | 25 +---- client/src/store/accounts/accounts.actions.js | 106 ++++++++++++------ .../authentication/authentication.actions.js | 11 +- .../itemCategories/itemsCategory.actions.js | 31 ++--- client/src/store/items/items.actions.js | 15 ++- .../manualJournals/manualJournals.actions.js | 29 ++++- .../manualJournals/manualJournals.reducers.js | 18 ++- .../manualJournals/manualJournals.types.js | 1 + .../src/store/resources/resources.actions.js | 12 ++ client/src/store/selectors.js | 2 +- client/src/style/pages/dashboard.scss | 3 +- client/src/style/views/Sidebar.scss | 2 +- server/src/http/controllers/Accounting.js | 24 +--- server/src/http/controllers/Items.js | 17 +-- 42 files changed, 575 insertions(+), 401 deletions(-) create mode 100644 client/src/components/NProgress/AppProgress.js diff --git a/client/src/components/App.js b/client/src/components/App.js index e343d0355..8dd729cd8 100644 --- a/client/src/components/App.js +++ b/client/src/components/App.js @@ -12,19 +12,24 @@ import Progress from 'components/NProgress/Progress'; import messages from 'lang/en'; import 'style/App.scss'; -function App(props) { +function App({ + isAuthorized, + locale, +}) { const history = createBrowserHistory(); + history.listen((location, action) => { + console.log(`new location via ${action}`, location); + }); + return ( - +
- - + +
- -
); } @@ -33,13 +38,10 @@ App.defaultProps = { locale: 'en', }; -App.propTypes = { - locale: PropTypes.string, - isAuthorized: PropTypes.bool, +const mapStateToProps = (state) => { + return { + isAuthorized: isAuthenticated(state), + }; }; -const mapStateToProps = (state) => ({ - isAuthorized: isAuthenticated(state), - isLoading: !!state.dashboard.requestsLoading, -}); export default connect(mapStateToProps)(App); \ No newline at end of file diff --git a/client/src/components/Dashboard/DashboardContentRoute.js b/client/src/components/Dashboard/DashboardContentRoute.js index 45f77d476..5f36b219f 100644 --- a/client/src/components/Dashboard/DashboardContentRoute.js +++ b/client/src/components/Dashboard/DashboardContentRoute.js @@ -9,7 +9,8 @@ export default function DashboardContentRoute() { { routes.map((route, index) => ( ))} diff --git a/client/src/components/Dashboard/TopbarUser.js b/client/src/components/Dashboard/TopbarUser.js index 36b4d83cf..501f90fee 100644 --- a/client/src/components/Dashboard/TopbarUser.js +++ b/client/src/components/Dashboard/TopbarUser.js @@ -15,11 +15,8 @@ function DashboardTopbarUser({ logout }) { const onClickLogout = useCallback(() => { logout(); - - setTimeout(() => { - history.push('/auth/login'); - }, 100); - }, [history, logout]); + history.go('/auth/login'); + }, [logout, history]); const userAvatarDropMenu = useMemo(() => ( diff --git a/client/src/components/DataTable.js b/client/src/components/DataTable.js index db5e4a45d..7ad733d26 100644 --- a/client/src/components/DataTable.js +++ b/client/src/components/DataTable.js @@ -93,9 +93,9 @@ export default function DataTable({ ...(selectionColumn) ? [{ id: 'selection', disableResizing: true, - minWidth: 35, - width: 35, - maxWidth: 35, + minWidth: 42, + width: 42, + maxWidth: 42, // The header can use the table's getToggleAllRowsSelectedProps method // to render a checkbox Header: ({ getToggleAllRowsSelectedProps }) => ( diff --git a/client/src/components/Items/ItemForm.js b/client/src/components/Items/ItemForm.js index 49d3b91bb..f9fa1ec46 100644 --- a/client/src/components/Items/ItemForm.js +++ b/client/src/components/Items/ItemForm.js @@ -22,15 +22,15 @@ import classNames from 'classnames'; import Icon from 'components/Icon'; import ItemCategoryConnect from 'connectors/ItemsCategory.connect'; import MoneyInputGroup from 'components/MoneyInputGroup'; - +import {useHistory} from 'react-router-dom'; const ItemForm = ({ requestSubmitItem, accounts, categories, - categoriesList, }) => { const [selectedAccounts, setSelectedAccounts] = useState({}); + const history = useHistory(); const ItemTypeDisplay = useMemo(() => ([ { value: null, label: 'Select Item Type' }, @@ -43,7 +43,7 @@ const ItemForm = ({ active: Yup.boolean(), name: Yup.string().required(), type: Yup.string().trim().required(), - sku: Yup.string().required(), + sku: Yup.string().trim(), cost_price: Yup.number(), sell_price: Yup.number(), cost_account_id: Yup.number().required(), @@ -71,7 +71,14 @@ const ItemForm = ({ note: '', }), []); - const formik = useFormik({ + const { + getFieldProps, + setFieldValue, + values, + touched, + errors, + handleSubmit, + } = useFormik({ enableReinitialize: true, validationSchema: validationSchema, initialValues: { @@ -83,13 +90,13 @@ const ItemForm = ({ message: 'The_Items_has_been_Submit' }); setSubmitting(false); + history.push('/dashboard/items'); }) .catch((error) => { setSubmitting(false); }); } }); - const {errors, values, touched} = useMemo(() => formik, [formik]); const accountItem = useCallback((item, { handleClick }) => ( @@ -112,9 +119,9 @@ const ItemForm = ({ ...selectedAccounts, [filedName]: account }); - formik.setFieldValue(filedName, account.id); + setFieldValue(filedName, account.id); }; - }, [formik, selectedAccounts]); + }, [setFieldValue, selectedAccounts]); const categoryItem = useCallback((item, { handleClick }) => ( @@ -129,12 +136,12 @@ const ItemForm = ({ const infoIcon = useMemo(() => (), []); const handleMoneyInputChange = (fieldKey) => (e, value) => { - formik.setFieldValue(fieldKey, value); + setFieldValue(fieldKey, value); }; return (
-
+
} + helperText={} inline={true} > @@ -157,13 +164,13 @@ const ItemForm = ({ labelInfo={requiredSpan} className={'form-group--item-name'} intent={(errors.name && touched.name) && Intent.DANGER} - helperText={} + helperText={} inline={true} > @@ -172,13 +179,13 @@ const ItemForm = ({ labelInfo={infoIcon} className={'form-group--item-sku'} intent={(errors.sku && touched.sku) && Intent.DANGER} - helperText={} + helperText={} inline={true} > @@ -187,7 +194,7 @@ const ItemForm = ({ labelInfo={infoIcon} inline={true} intent={(errors.category_id && touched.category_id) && Intent.DANGER} - helperText={} + helperText={} className={classNames( 'form-group--select-list', 'form-group--category', @@ -195,7 +202,7 @@ const ItemForm = ({ )} >