From c7db1394e7b9e5ecef26d00ce65a725bd26b0190 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 26 Mar 2020 15:27:38 +0200 Subject: [PATCH] fix items connector. --- .gitignore | 1 + client/src/components/Items/ItemForm.js | 28 +++++++++------ client/src/config/sidebarMenu.js | 4 +-- client/src/connectors/Items.connect.js | 3 +- .../containers/Dashboard/Items/ItemForm.js | 35 +++++++------------ .../Dashboard/Items/ItemsDataTable.js | 4 +-- 6 files changed, 36 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 3af0ccb68..c0579ae4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /data +.env \ No newline at end of file diff --git a/client/src/components/Items/ItemForm.js b/client/src/components/Items/ItemForm.js index a335be95a..dee577483 100644 --- a/client/src/components/Items/ItemForm.js +++ b/client/src/components/Items/ItemForm.js @@ -1,7 +1,6 @@ import React, { useState } from 'react'; import * as Yup from 'yup'; import { useFormik } from 'formik'; - import { FormGroup, MenuItem, @@ -13,19 +12,21 @@ import { import { Row, Col } from 'react-grid-system'; import { Select } from '@blueprintjs/select'; import AppToaster from 'components/AppToaster'; +import AccountsConnect from 'connectors/Accounts.connector'; +import ItemsConnect from 'connectors/Items.connect'; +import {compose} from 'utils'; -export default function ItemForm({ - submitItem, +const ItemForm = ({ + requestSubmitItem, accounts, - category, -}) { +}) => { const [selectedAccounts, setSelectedAccounts] = useState({}); const ItemTypeDisplay = [ - { label: 'Select Item Type' }, - { value: 'service', label: 'service' }, - { value: 'inventory', label: 'inventory' }, - { value: 'non-inventory', label: 'non-inventory' } + { value: null, label: 'Select Item Type' }, + { value: 'service', label: 'Service' }, + { value: 'inventory', label: 'Inventory' }, + { value: 'non-inventory', label: 'Non-Inventory' } ]; const validationSchema = Yup.object().shape({ name: Yup.string().required(), @@ -46,7 +47,7 @@ export default function ItemForm({ validationSchema: validationSchema, initialValues: {}, onSubmit: values => { - submitItem(values) + requestSubmitItem(values) .then(response => { AppToaster.show({ message: 'The_Items_has_been_Submit' @@ -295,4 +296,9 @@ export default function ItemForm({ ); -} +}; + +export default compose( + AccountsConnect, + ItemsConnect, +)(ItemForm); \ No newline at end of file diff --git a/client/src/config/sidebarMenu.js b/client/src/config/sidebarMenu.js index 402cc599d..f40892cf9 100644 --- a/client/src/config/sidebarMenu.js +++ b/client/src/config/sidebarMenu.js @@ -19,11 +19,11 @@ export default [ children: [ { text: 'Items List', - href: '/dashboard/accounts', + href: '/dashboard/items/list', }, { text: 'New Item', - href: '/dashboard/accounts', + href: '/dashboard/items/new', }, ] }, diff --git a/client/src/connectors/Items.connect.js b/client/src/connectors/Items.connect.js index 6a8da3e9f..29c675c24 100644 --- a/client/src/connectors/Items.connect.js +++ b/client/src/connectors/Items.connect.js @@ -3,7 +3,6 @@ import {connect} from 'react-redux'; import { fetchItems, - fetchItem, deleteItem, submitItem, } from 'store/items/items.actions'; @@ -29,7 +28,7 @@ export const mapStateToProps = (state, props) => { }; export const mapDispatchToProps = (dispatch) => ({ - fetchItems: (query) => dispatch(fetchItems({ query })), + requestFetchItems: (query) => dispatch(fetchItems({ query })), requestDeleteItem: (id) => dispatch(deleteItem({ id })), requestSubmitItem: (form) => dispatch(submitItem({ form })), addBulkActionItem: (id) => dispatch({ diff --git a/client/src/containers/Dashboard/Items/ItemForm.js b/client/src/containers/Dashboard/Items/ItemForm.js index c80aead50..288ce1590 100644 --- a/client/src/containers/Dashboard/Items/ItemForm.js +++ b/client/src/containers/Dashboard/Items/ItemForm.js @@ -5,43 +5,34 @@ import DashboardConnect from 'connectors/Dashboard.connector'; import ItemForm from 'components/Items/ItemForm'; import DashboardInsider from 'components/Dashboard/DashboardInsider'; import ItemsConnect from 'connectors/Items.connect'; +import AccountsConnect from 'connectors/Accounts.connector'; import { compose } from 'utils'; + const ItemFormContainer = ({ changePageTitle, - fetchAccount, - submitItem, - editItem, - fetchItems, - fetchItem, - deleteItem, - accounts + fetchAccounts, }) => { const { id } = useParams(); useEffect(() => { - id ? changePageTitle('Edit Item Details') : changePageTitle('New Item'); + id ? + changePageTitle('Edit Item Details') : + changePageTitle('New Item'); }, []); const fetchHook = useAsync(async () => { - await Promise.all([fetchAccount()]); + await Promise.all([ + fetchAccounts(), + ]); }); return ( - - + + ); }; export default compose( DashboardConnect, - ItemsConnect - // AccountsConnect + ItemsConnect, + AccountsConnect, )(ItemFormContainer); diff --git a/client/src/containers/Dashboard/Items/ItemsDataTable.js b/client/src/containers/Dashboard/Items/ItemsDataTable.js index d47a22b6f..fe28d8abd 100644 --- a/client/src/containers/Dashboard/Items/ItemsDataTable.js +++ b/client/src/containers/Dashboard/Items/ItemsDataTable.js @@ -19,7 +19,7 @@ import Icon from 'components/Icon'; import {handleBooleanChange} from 'utils'; const ItemsDataTable = ({ - fetchItems, + requestFetchItems, filterConditions, currentPageItems, onEditItem, @@ -31,7 +31,7 @@ const ItemsDataTable = ({ const fetchHook = useAsync(async () => { await Promise.all([ - fetchItems({ + requestFetchItems({ custom_view_id: customViewId, stringified_filter_roles: JSON.stringify(filterConditions), }),