From 6dcff7e4c25ad22f7fd3c1b4b8175b1edd79ab36 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sat, 11 Apr 2020 14:40:56 +0200 Subject: [PATCH 1/5] feat: Preferences issue. --- client/src/components/Dashboard/Dashboard.js | 2 +- .../Preferences/PreferencesContent.js | 2 +- .../Preferences/PreferencesContentRoute.js | 4 +-- .../Preferences/PreferencesSidebar.js | 14 +++++---- client/src/components/Views/ViewForm.js | 31 +++++++++++-------- .../Dashboard/Preferences/General.js | 28 +++-------------- client/src/style/pages/preferences.scss | 13 ++++++-- 7 files changed, 44 insertions(+), 50 deletions(-) diff --git a/client/src/components/Dashboard/Dashboard.js b/client/src/components/Dashboard/Dashboard.js index d24660695..e710485a6 100644 --- a/client/src/components/Dashboard/Dashboard.js +++ b/client/src/components/Dashboard/Dashboard.js @@ -8,7 +8,7 @@ import PreferencesSidebar from 'components/Preferences/PreferencesSidebar'; export default function() { return ( -
+
diff --git a/client/src/components/Preferences/PreferencesContent.js b/client/src/components/Preferences/PreferencesContent.js index 9bcfcfa9e..4e2cd404e 100644 --- a/client/src/components/Preferences/PreferencesContent.js +++ b/client/src/components/Preferences/PreferencesContent.js @@ -4,7 +4,7 @@ import PreferencesContentRoute from 'components/Preferences/PreferencesContentRo export default function() { return ( -
+
diff --git a/client/src/components/Preferences/PreferencesContentRoute.js b/client/src/components/Preferences/PreferencesContentRoute.js index d619171dd..3ed99820a 100644 --- a/client/src/components/Preferences/PreferencesContentRoute.js +++ b/client/src/components/Preferences/PreferencesContentRoute.js @@ -3,15 +3,13 @@ import { Route, Switch, useRouteMatch } from 'react-router-dom'; import preferencesRoutes from 'routes/preferences' export default function DashboardContentRoute() { - const { path } = useRouteMatch(); - return ( { preferencesRoutes.map((route, index) => ( diff --git a/client/src/components/Preferences/PreferencesSidebar.js b/client/src/components/Preferences/PreferencesSidebar.js index 763ad31a0..c1987de94 100644 --- a/client/src/components/Preferences/PreferencesSidebar.js +++ b/client/src/components/Preferences/PreferencesSidebar.js @@ -18,13 +18,15 @@ export default function PreferencesSidebar() { return (
-
-

Preferences

-
+
+
+

Preferences

+
- - { items } - + + { items } + +
); } \ No newline at end of file diff --git a/client/src/components/Views/ViewForm.js b/client/src/components/Views/ViewForm.js index 20d8c5283..0caca61e4 100644 --- a/client/src/components/Views/ViewForm.js +++ b/client/src/components/Views/ViewForm.js @@ -1,4 +1,4 @@ -import React, {useState, useEffect} from 'react'; +import React, {useState, useEffect, useCallback, useMemo} from 'react'; import {Formik, useFormik, ErrorMessage} from "formik"; import {useIntl} from 'react-intl'; import { @@ -34,12 +34,13 @@ function ViewForm({ const [draggedColumns, setDraggedColumn] = useState([]); const [availableColumns, setAvailableColumns] = useState(columns); - const defaultViewRole = { + const defaultViewRole = useMemo(() => ({ field_key: '', comparator: 'AND', value: '', index: 1, - }; + }), []); + const validationSchema = Yup.object().shape({ resource_name: Yup.string().required(), name: Yup.string().required(), @@ -86,7 +87,6 @@ function ViewForm({ ], }, onSubmit: (values) => { - if (viewForm && viewForm.id) { editView(viewForm.id, values).then((response) => { @@ -100,10 +100,11 @@ function ViewForm({ }); useEffect(() => { - formik.setFieldValue('columns', draggedColumns.map((column, index) => ({ + formik.setFieldValue('columns', + draggedColumns.map((column, index) => ({ index, key: column.key, }))); - }, [draggedColumns]); + }, [draggedColumns, formik]); const conditionalsItems = [ { value: 'and', label: 'AND' }, @@ -123,16 +124,16 @@ function ViewForm({ ]; // Resource fields. - const resourceFields = [ + const resourceFields = useMemo(() => ([ {value: '', label: 'Select a field'}, ...fields.map((field) => ({ value: field.key, label: field.labelName, })), - ]; + ]), []); // Account item of select accounts field. const selectItem = (item, { handleClick, modifiers, query }) => { return () }; // Handle click new condition button. - const onClickNewRole = () => { + const onClickNewRole = useCallback(() => { formik.setFieldValue('roles', [ ...formik.values.roles, { @@ -140,9 +141,10 @@ function ViewForm({ index: formik.values.roles.length + 1, } ]); - }; + }, [formik, defaultViewRole]); + // Handle click remove view role button. - const onClickRemoveRole = (viewRole, index) => () => { + const onClickRemoveRole = useCallback((viewRole, index) => () => { const viewRoles = [...formik.values.roles]; viewRoles.splice(index, 1); viewRoles.map((role, i) => { @@ -150,9 +152,12 @@ function ViewForm({ return role; }); formik.setFieldValue('roles', viewRoles); - }; + }, [formik]); + + const onClickDeleteView = useCallback(() => { + onDelete && onDelete(viewForm); + }, [onDelete, viewForm]); - const onClickDeleteView = () => { onDelete(viewForm); }; return (
diff --git a/client/src/containers/Dashboard/Preferences/General.js b/client/src/containers/Dashboard/Preferences/General.js index 2a2ce3cce..a7c3d9c75 100644 --- a/client/src/containers/Dashboard/Preferences/General.js +++ b/client/src/containers/Dashboard/Preferences/General.js @@ -1,30 +1,22 @@ import React from 'react'; import { useFormik } from 'formik'; import * as Yup from 'yup'; -import {connect} from 'react-redux'; import { Button, FormGroup, InputGroup, Intent, } from "@blueprintjs/core"; -import { useAsync } from 'react-use'; import {optionsMapToArray} from 'utils'; -import AppToaster from 'components/AppToaster'; -import { - savePreferences, - fetchPreferences, -} from 'store/preferences/preferences.actions'; -function GeneralPreferences({ savePreferences, fetchPreferences }) { +function GeneralPreferences({ + +}) { const validationSchema = Yup.object().shape({ organization_name: Yup.string().required(), organization_industry: Yup.string().required(), }); - const asyncHook = useAsync(async () => { - await fetchPreferences(); - }); const formik = useFormik({ enableReinitialize: true, initialValues: { @@ -35,13 +27,6 @@ function GeneralPreferences({ savePreferences, fetchPreferences }) { return {...option, group: 'general'}; }); - savePreferences(options).then((response) => { - AppToaster.show({ - message: 'preferences_have_been_updated', - }); - }).catch(error => { - - }); }, }); @@ -80,9 +65,4 @@ function GeneralPreferences({ savePreferences, fetchPreferences }) { ) } -const mapDispatchToProps = (dispatch) => ({ - savePreferences: (options) => dispatch(savePreferences({ options })), - fetchPreferences: (keys) => dispatch(fetchPreferences()) -}); - -export default connect(null, mapDispatchToProps)(GeneralPreferences); \ No newline at end of file +export default GeneralPreferences; \ No newline at end of file diff --git a/client/src/style/pages/preferences.scss b/client/src/style/pages/preferences.scss index 655884307..813ccf730 100644 --- a/client/src/style/pages/preferences.scss +++ b/client/src/style/pages/preferences.scss @@ -1,5 +1,8 @@ +.dashboard-content--preferences{ + margin-left: 430px; +} .preferences{ &__inside-content--tabable{ @@ -8,7 +11,6 @@ } &__inside-content{ - .#{$ns}-tab-list{ border-bottom: 1px solid #E5E5E5; padding-left: 15px; @@ -22,9 +24,16 @@ .preferences__sidebar{ background: #fdfdfd; + position: fixed; + left: 220px; min-width: 210px; max-width: 210px; - + height: 100%; + + .sidebar-wrapper{ + + } + &-head{ display: flex; flex-direction: row; From 37fb5a6f11bca1b7cd480aa47532ff679dde42b1 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 12 Apr 2020 12:03:45 +0200 Subject: [PATCH 2/5] feat: dashboard style. --- .../components/Accounts/AccountsViewsTabs.js | 1 + client/src/components/AccountsSelectList.js | 5 +- .../components/Dashboard/DashboardTopbar.js | 2 +- client/src/components/DataTable.js | 24 +-- client/src/components/ErrorMessage.js | 21 ++ client/src/config/app.js | 2 +- client/src/config/sidebarMenu.js | 10 +- .../connectors/AccountFormDialog.connector.js | 22 +-- client/src/connectors/Accounts.connector.js | 21 +- .../Accounting/MakeJournalEntriesPage.js | 4 +- .../Dashboard/Accounts/AccountsChart.js | 8 +- .../Dashboard/Dialogs/AccountFormDialog.js | 186 +++++++++++------- .../Dashboard/Dialogs/ItemCategoryDialog.js | 102 ++++++---- .../GeneralLedger/GeneralLedger.js | 4 +- .../src/store/accounts/accounts.selectors.js | 2 +- client/src/store/selectors.js | 4 + client/src/style/App.scss | 3 + client/src/style/components/data-table.scss | 30 ++- client/src/style/functions.scss | 41 ++++ client/src/style/objects/buttons.scss | 15 +- client/src/style/objects/form.scss | 105 +++++++++- client/src/style/pages/accounts-chart.scss | 54 +++++ client/src/style/pages/item-category.scss | 30 +++ client/src/style/views/Sidebar.scss | 22 ++- 24 files changed, 517 insertions(+), 201 deletions(-) create mode 100644 client/src/components/ErrorMessage.js create mode 100644 client/src/style/functions.scss create mode 100644 client/src/style/pages/item-category.scss diff --git a/client/src/components/Accounts/AccountsViewsTabs.js b/client/src/components/Accounts/AccountsViewsTabs.js index fde698a69..93dee0a20 100644 --- a/client/src/components/Accounts/AccountsViewsTabs.js +++ b/client/src/components/Accounts/AccountsViewsTabs.js @@ -80,6 +80,7 @@ function AccountsViewsTabs({ className='button--new-view' icon={} onClick={handleClickNewView} + minimal={true} /> diff --git a/client/src/components/AccountsSelectList.js b/client/src/components/AccountsSelectList.js index f826d33c7..32c58bd9d 100644 --- a/client/src/components/AccountsSelectList.js +++ b/client/src/components/AccountsSelectList.js @@ -5,11 +5,12 @@ import { } from '@blueprintjs/core'; import {Select} from '@blueprintjs/select'; -export default function AccountsMultiSelect({ +export default function AccountsSelectList({ accounts, onAccountSelected, error, initialAccount, + defautlSelectText = 'Select account' }) { const [selectedAccount, setSelectedAccount] = useState( initialAccount || null @@ -36,7 +37,7 @@ export default function AccountsMultiSelect({ onItemSelect={onAccountSelect}> -
diff --git a/client/src/containers/Dashboard/Dialogs/ItemCategoryDialog.js b/client/src/containers/Dashboard/Dialogs/ItemCategoryDialog.js index 53ced0aa5..6c8ffb821 100644 --- a/client/src/containers/Dashboard/Dialogs/ItemCategoryDialog.js +++ b/client/src/containers/Dashboard/Dialogs/ItemCategoryDialog.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useMemo, useCallback } from 'react'; import { Button, Classes, @@ -9,7 +9,7 @@ import { MenuItem } from '@blueprintjs/core'; import { Select } from '@blueprintjs/select'; -import { omit, pick } from 'lodash'; +import { pick } from 'lodash'; import * as Yup from 'yup'; import { useIntl } from 'react-intl'; import { useFormik } from 'formik'; @@ -20,6 +20,9 @@ import AppToaster from 'components/AppToaster'; import DialogConnect from 'connectors/Dialog.connector'; import DialogReduxConnect from 'components/DialogReduxConnect'; import ItemsCategoryConnect from 'connectors/ItemsCategory.connect'; +import ErrorMessage from 'components/ErrorMessage'; +import classNames from 'classnames'; +import Icon from 'components/Icon'; function ItemCategoryDialog({ name, @@ -33,9 +36,8 @@ function ItemCategoryDialog({ requestEditItemCategory, editItemCategory }) { - const [state, setState] = useState({ - selectedParentCategory: null - }); + const [selectedParentCategory, setParentCategory] = useState(null); + const intl = useIntl(); const ValidationSchema = Yup.object().shape({ name: Yup.string().required(intl.formatMessage({ id: 'required' })), @@ -43,11 +45,12 @@ function ItemCategoryDialog({ description: Yup.string().trim() }); - const initialValues = { + const initialValues = useMemo(() => ({ name: '', description: '', parent_category_id: null - }; + }), []); + //Formik const formik = useFormik({ enableReinitialize: true, @@ -56,30 +59,35 @@ function ItemCategoryDialog({ pick(editItemCategory, Object.keys(initialValues))) }, validationSchema: ValidationSchema, - onSubmit: values => { + onSubmit: (values, { setSubmitting }) => { if (payload.action === 'edit') { requestEditItemCategory(payload.id, values).then(response => { closeDialog(name); AppToaster.show({ message: 'the_category_has_been_edited' }); + setSubmitting(false); + }).catch((error) => { + setSubmitting(false); }); } else { requestSubmitItemCategory(values) - .then(response => { + .then((response) => { closeDialog(name); AppToaster.show({ message: 'the_category_has_been_submit' }); + setSubmitting(false); }) - .catch(error => { - alert(error.message); + .catch((error) => { + setSubmitting(false); }); } } }); + const { values, errors, touched } = useMemo(() => formik, [formik]); - const filterItemCategory = (query, category, _index, exactMatch) => { + const filterItemCategory = useCallback((query, category, _index, exactMatch) => { const normalizedTitle = category.name.toLowerCase(); const normalizedQuery = query.toLowerCase(); @@ -88,73 +96,80 @@ function ItemCategoryDialog({ } else { return normalizedTitle.indexOf(normalizedQuery) >= 0; } - }; + }, []); - const parentCategoryItem = (category, { handleClick, modifiers, query }) => { + const parentCategoryItem = useCallback((category, { handleClick, modifiers, query }) => { return ( ); - }; - const handleClose = () => { - closeDialog(name); - }; + }, []); + + const handleClose = useCallback(() => { closeDialog(name); }, [name, closeDialog]); const fetchHook = useAsync(async () => { - await Promise.all([requestFetchItemCategories()]); + await Promise.all([ + requestFetchItemCategories(), + ]); }, false); - const onDialogOpening = () => { - fetchHook.execute(); - }; + const onDialogOpening = useCallback(() => { fetchHook.execute(); }, [fetchHook]); - const onChangeParentCategory = parentCategory => { - setState({ ...state, selectedParentCategory: parentCategory.name }); + const onChangeParentCategory = useCallback((parentCategory) => { + setParentCategory(parentCategory); formik.setFieldValue('parent_category_id', parentCategory.id); - }; + }, [formik]); - const onDialogClosed = () => { + const onDialogClosed = useCallback(() => { formik.resetForm(); closeDialog(name); - }; + }, [formik, closeDialog, name]); + + const requiredSpan = useMemo(() => (*), []); + const infoIcon = useMemo(() => (), []); return (
)} inline={true} > )} + intent={(errors.parent_category_id && touched.parent_category_id) && Intent.DANGER} > @@ -174,8 +190,8 @@ function ItemCategoryDialog({ )} inline={true} >