+
}
- href="/dashboard/expenses/new"
- text="New Expense"
- onClick={onClickNewAccount} />
-
-
}
- text="Delete Expense"
- onClick={onClickNewAccount} />
+ icon={
}
+ href='/dashboard/expenses/new'
+ text='New Expense'
+ onClick={onClickNewAccount}
+ />
}
- text="Bulk Update"
- onClick={onClickNewAccount} />
+ icon={
}
+ text='Delete Expense'
+ onClick={onClickNewAccount}
+ />
+
+
}
+ text='Bulk Update'
+ onClick={onClickNewAccount}
+ />
- )
-}
\ No newline at end of file
+ );
+}
diff --git a/client/src/components/Items/ItemForm.js b/client/src/components/Items/ItemForm.js
index 3bc05f815..a335be95a 100644
--- a/client/src/components/Items/ItemForm.js
+++ b/client/src/components/Items/ItemForm.js
@@ -1,15 +1,298 @@
+import React, { useState } from 'react';
+import * as Yup from 'yup';
+import { useFormik } from 'formik';
+import {
+ FormGroup,
+ MenuItem,
+ Intent,
+ InputGroup,
+ HTMLSelect,
+ Button
+} from '@blueprintjs/core';
+import { Row, Col } from 'react-grid-system';
+import { Select } from '@blueprintjs/select';
+import AppToaster from 'components/AppToaster';
+
+export default function ItemForm({
+ submitItem,
+ 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' }
+ ];
+ const validationSchema = Yup.object().shape({
+ name: Yup.string().required(),
+ type: Yup.string()
+ .trim()
+ .required(),
+ sku: Yup.string().required(),
+ cost_price: Yup.number().required(),
+ sell_price: Yup.number().required(),
+ cost_account_id: Yup.number().required(),
+ sell_account_id: Yup.number().required(),
+ inventory_account_id: Yup.number().required(),
+ category_id: Yup.number().required(),
+ stock: Yup.string() || Yup.boolean()
+ });
+ const formik = useFormik({
+ enableReinitialize: true,
+ validationSchema: validationSchema,
+ initialValues: {},
+ onSubmit: values => {
+ submitItem(values)
+ .then(response => {
+ AppToaster.show({
+ message: 'The_Items_has_been_Submit'
+ });
+ })
+ .catch(err => {
+ alert(err.message);
+ });
+ }
+ });
+
+ const accountItem = (item, { handleClick }) => (
+
+ );
+ // Filter Account Items
+ const filterAccounts = (query, account, _index, exactMatch) => {
+ const normalizedTitle = account.name.toLowerCase();
+ const normalizedQuery = query.toLowerCase();
+ if (exactMatch) {
+ return normalizedTitle === normalizedQuery;
+ } else {
+ return `${account.code} ${normalizedTitle}`.indexOf(normalizedQuery) >= 0;
+ }
+ };
+
+ const onItemAccountSelect = filedName => {
+ return account => {
+ setSelectedAccounts({
+ ...selectedAccounts,
+ [filedName]: account
+ });
+ formik.setFieldValue(filedName, account.id);
+ };
+ };
+
+ const getSelectedAccountLabel = (fieldName, defaultLabel) => {
+ return typeof selectedAccounts[fieldName] !== 'undefined'
+ ? selectedAccounts[fieldName].name
+ : defaultLabel;
+ };
-export default function ItemForm() {
-
- // Type
- // Name
- //
-
return (
-
+
+
- )
-};
\ No newline at end of file
+ );
+}
diff --git a/client/src/components/Items/ItemsActionsBar.js b/client/src/components/Items/ItemsActionsBar.js
index e69de29bb..373dd5e0a 100644
--- a/client/src/components/Items/ItemsActionsBar.js
+++ b/client/src/components/Items/ItemsActionsBar.js
@@ -0,0 +1,13 @@
+import React from 'react';
+import { Button, AnchorButton, Classes, Icon } from '@blueprintjs/core';
+
+const ItemsActionsBar = () => {
+
+ return (
+
+ ItemsActionsBar 22
+
+ );
+};
+
+export default ItemsActionsBar;
diff --git a/client/src/components/LoadingIndicator.js b/client/src/components/LoadingIndicator.js
index d59de58d9..2b2ee3160 100644
--- a/client/src/components/LoadingIndicator.js
+++ b/client/src/components/LoadingIndicator.js
@@ -1,5 +1,5 @@
import React from 'react';
-import {Spinner} from '@blueprintjs/core';
+import { Spinner } from '@blueprintjs/core';
export default function LoadingIndicator({
loading,
@@ -8,10 +8,13 @@ export default function LoadingIndicator({
}) {
return (
<>
- { (loading) ? (
-
+ {loading ? (
+
-
) : children }
+
+ ) : (
+ children
+ )}
>
);
-}
\ No newline at end of file
+}
diff --git a/client/src/components/MenuItem.js b/client/src/components/MenuItem.js
index 4c5ed596f..4b3d0e82f 100644
--- a/client/src/components/MenuItem.js
+++ b/client/src/components/MenuItem.js
@@ -161,7 +161,9 @@ export default class MenuItem extends AbstractPureComponent2 {
className,
);
- const handleAnchorClick = () => {
+ const handleAnchorClick = (event) => {
+ htmlProps.onClick && htmlProps.onClick(event);
+
if (dropdownType === 'collapse') {
this.setState({ isCollapseActive: !this.state.isCollapseActive });
}
@@ -210,7 +212,9 @@ export default class MenuItem extends AbstractPureComponent2 {
return (
<>
{target}
-
{ children }
+
+ { children }
+
>
);
}
diff --git a/client/src/components/Sidebar/SidebarMenu.js b/client/src/components/Sidebar/SidebarMenu.js
index 983a69fe8..9d0d4a86b 100644
--- a/client/src/components/Sidebar/SidebarMenu.js
+++ b/client/src/components/Sidebar/SidebarMenu.js
@@ -24,17 +24,14 @@ export default function SidebarMenu() {
children={children}
dropdownType={item.dropdownType || 'collapse'}
onClick={() => {
- history.push(item.href);
+ if (item.href) {
+ history.push(item.href);
+ }
}} />
);
});
};
-
const items = menuItemsMapper(sidebarMenuList);
- return (
-
- )
+ return (
);
};
diff --git a/client/src/config/sidebarMenu.js b/client/src/config/sidebarMenu.js
index 63dd585b9..402cc599d 100644
--- a/client/src/config/sidebarMenu.js
+++ b/client/src/config/sidebarMenu.js
@@ -1,18 +1,16 @@
-
-
export default [
{
- divider: true,
+ divider: true
},
{
icon: 'homepage',
iconSize: 20,
text: 'Homepage',
disabled: false,
- href: '/dashboard/homepage',
+ href: '/dashboard/homepage'
},
{
- divider: true,
+ divider: true
},
{
icon: 'homepage',
@@ -36,7 +34,6 @@ export default [
icon: 'balance-scale',
iconSize: 20,
text: 'Financial',
- href: '/dashboard/accounts',
children: [
{
text: 'Accounts Chart',
@@ -52,7 +49,6 @@ export default [
icon: 'university',
iconSize: 20,
text: 'Banking',
- href: '/dashboard/accounts',
children: [
]
@@ -61,7 +57,6 @@ export default [
icon: 'shopping-cart',
iconSize: 20,
text: 'Sales',
- href: '/dashboard/accounts',
children: [
]
@@ -70,13 +65,12 @@ export default [
icon: 'balance-scale',
iconSize: 20,
text: 'Purchases',
- href: '/dashboard/accounts',
children: [
{
icon: 'cut',
text: 'cut',
label: '⌘C',
- disabled: false,
+ disabled: false
}
]
},
@@ -84,7 +78,6 @@ export default [
icon: 'analytics',
iconSize: 18,
text: 'Financial Reports',
- href: '/dashboard/accounts',
children: [
{
text: 'Balance Sheet',
@@ -124,14 +117,14 @@ export default [
]
},
{
- divider: true,
+ divider: true
},
{
text: 'Preferences',
- href: '/dashboard/preferences',
+ href: '/dashboard/preferences'
},
{
text: 'Auditing System',
- href: '/dashboard/accounts',
- },
-]
\ No newline at end of file
+ href: '/dashboard/accounts'
+ }
+];
diff --git a/client/src/connectors/Dashboard.connector.js b/client/src/connectors/Dashboard.connector.js
index e31f6b196..7ef246e4f 100644
--- a/client/src/connectors/Dashboard.connector.js
+++ b/client/src/connectors/Dashboard.connector.js
@@ -1,6 +1,4 @@
-
-
import { connect } from 'react-redux';
import t from 'store/types';
diff --git a/client/src/connectors/Items.connect.js b/client/src/connectors/Items.connect.js
index 3c2d4eb84..6a8da3e9f 100644
--- a/client/src/connectors/Items.connect.js
+++ b/client/src/connectors/Items.connect.js
@@ -5,6 +5,7 @@ import {
fetchItems,
fetchItem,
deleteItem,
+ submitItem,
} from 'store/items/items.actions';
import {
getResourceViews,
@@ -30,6 +31,7 @@ export const mapStateToProps = (state, props) => {
export const mapDispatchToProps = (dispatch) => ({
fetchItems: (query) => dispatch(fetchItems({ query })),
requestDeleteItem: (id) => dispatch(deleteItem({ id })),
+ requestSubmitItem: (form) => dispatch(submitItem({ form })),
addBulkActionItem: (id) => dispatch({
type: t.ITEM_BULK_ACTION_ADD, itemId: id
}),
@@ -38,4 +40,4 @@ export const mapDispatchToProps = (dispatch) => ({
}),
});
-export default connect(mapStateToProps, mapDispatchToProps);
\ No newline at end of file
+export default connect(mapStateToProps, mapDispatchToProps);
diff --git a/client/src/containers/Dashboard/Dialogs/AccountFormDialog.js b/client/src/containers/Dashboard/Dialogs/AccountFormDialog.js
index 287c89121..ae82c4ba3 100644
--- a/client/src/containers/Dashboard/Dialogs/AccountFormDialog.js
+++ b/client/src/containers/Dashboard/Dialogs/AccountFormDialog.js
@@ -1,5 +1,5 @@
-import React, { useState} from 'react';
-import {
+import React, { useState } from 'react';
+import {
Button,
Classes,
FormGroup,
@@ -7,9 +7,9 @@ import {
Intent,
TextArea,
MenuItem,
- Checkbox,
-} from "@blueprintjs/core";
-import {Select} from '@blueprintjs/select';
+ Checkbox
+} from '@blueprintjs/core';
+import { Select } from '@blueprintjs/select';
import * as Yup from 'yup';
import { useFormik } from 'formik';
import { useIntl } from 'react-intl';
@@ -22,7 +22,7 @@ import DialogConnect from 'connectors/Dialog.connector';
import DialogReduxConnect from 'components/DialogReduxConnect';
import AccountFormDialogConnect from 'connectors/AccountFormDialog.connector';
-function AccountFormDialog ({
+function AccountFormDialog({
name,
payload,
isOpen,
@@ -37,55 +37,51 @@ function AccountFormDialog ({
}) {
const intl = useIntl();
const accountFormValidationSchema = Yup.object().shape({
- name: Yup
- .string()
- .required(intl.formatMessage({ 'id': 'required' })),
- code: Yup
- .number(intl.formatMessage({ id: 'field_name_must_be_number' })),
- account_type_id: Yup
- .string()
+ name: Yup.string().required(intl.formatMessage({ id: 'required' })),
+ code: Yup.number(intl.formatMessage({ id: 'field_name_must_be_number' })),
+ account_type_id: Yup.string()
.nullable()
- .required(intl.formatMessage({ 'id': 'required' })),
- description: Yup.string().trim(),
+ .required(intl.formatMessage({ id: 'required' })),
+ description: Yup.string().trim()
});
// Formik
const formik = useFormik({
enableReinitialize: true,
initialValues: {
- ...payload.action === 'edit' && editAccount,
+ ...(payload.action === 'edit' && editAccount)
},
validationSchema: accountFormValidationSchema,
- onSubmit: (values) => {
+ onSubmit: values => {
const exclude = ['subaccount'];
if (payload.action === 'edit') {
editAccount({
payload: payload.id,
form: { ...omit(values, exclude) }
- }).then((response) => {
+ }).then(response => {
closeDialog(name);
AppToaster.show({
- message: 'the_account_has_been_edited',
+ message: 'the_account_has_been_edited'
});
});
} else {
submitAccount({ form: { ...omit(values, exclude) } }).then(response => {
closeDialog(name);
AppToaster.show({
- message: 'the_account_has_been_submit',
+ message: 'the_account_has_been_submit'
});
});
}
- },
+ }
});
const [state, setState] = useState({
loading: true,
dialogActive: true,
selectedAccountType: null,
- selectedSubaccount: null,
+ selectedSubaccount: null
});
-
+
// Filters accounts types items.
const filterAccountTypeItems = (query, accountType, _index, exactMatch) => {
const normalizedTitle = accountType.name.toLowerCase();
@@ -100,12 +96,19 @@ function AccountFormDialog ({
// Account type item of select filed.
const accountTypeItem = (item, { handleClick, modifiers, query }) => {
- return (
);
+ return
;
};
// Account item of select accounts field.
const accountItem = (item, { handleClick, modifiers, query }) => {
- return (
)
+ return (
+
+ );
};
// Filters accounts items.
@@ -120,7 +123,9 @@ function AccountFormDialog ({
}
};
- const handleClose = () => { closeDialog(name); };
+ const handleClose = () => {
+ closeDialog(name);
+ };
const fetchHook = useAsync(async () => {
await Promise.all([
@@ -128,19 +133,19 @@ function AccountFormDialog ({
fetchAccountTypes(),
// Fetch the target in case edit mode.
- ...(payload.action === 'edit') ? [
- fetchAccount(payload.id),
- ] : [],
+ ...(payload.action === 'edit' ? [fetchAccount(payload.id)] : [])
]);
- }, false);
+ });
- const onDialogOpening = async () => { fetchHook.execute(); }
-
- const onChangeAccountType = (accountType) => {
+ const onDialogOpening = async () => {
+ fetchHook.execute();
+ };
+
+ const onChangeAccountType = accountType => {
setState({ ...state, selectedAccountType: accountType.name });
formik.setFieldValue('account_type_id', accountType.id);
};
- const onChangeSubaccount = (account) => {
+ const onChangeSubaccount = account => {
setState({ ...state, selectedSubaccount: account });
formik.setFieldValue('parent_account_id', account.id);
};
@@ -150,14 +155,17 @@ function AccountFormDialog ({
setState({
...state,
selectedSubaccount: null,
- selectedAccountType: null,
+ selectedAccountType: null
});
};
return (
-
@@ -269,5 +295,5 @@ function AccountFormDialog ({
export default compose(
AccountFormDialogConnect,
DialogReduxConnect,
- DialogConnect,
-)(AccountFormDialog);
\ No newline at end of file
+ DialogConnect
+)(AccountFormDialog);
diff --git a/client/src/containers/Dashboard/Expenses/ExpenseForm.js b/client/src/containers/Dashboard/Expenses/ExpenseForm.js
index f6cb6e171..6d793c563 100644
--- a/client/src/containers/Dashboard/Expenses/ExpenseForm.js
+++ b/client/src/containers/Dashboard/Expenses/ExpenseForm.js
@@ -33,6 +33,7 @@ function ExpenseFormContainer({
return (
+
);
}
diff --git a/client/src/containers/Dashboard/Expenses/ExpensesList.js b/client/src/containers/Dashboard/Expenses/ExpensesList.js
index c0feac777..13d99f063 100644
--- a/client/src/containers/Dashboard/Expenses/ExpensesList.js
+++ b/client/src/containers/Dashboard/Expenses/ExpensesList.js
@@ -1,6 +1,6 @@
-import React, {useEffect, useState} from 'react';
+import React, { useEffect, useState } from 'react';
import { useAsync } from 'react-use';
-import {Alert, Intent} from '@blueprintjs/core';
+import { Alert, Intent } from '@blueprintjs/core';
import DashboardInsider from 'components/Dashboard/DashboardInsider';
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
import ExpensesActionsBar from 'components/Expenses/ExpensesActionsBar';
@@ -15,7 +15,7 @@ function ExpensesList({
// fetchViews,
expenses,
getResourceViews,
- changePageTitle,
+ changePageTitle
}) {
useEffect(() => {
changePageTitle('Expenses List');
@@ -23,21 +23,25 @@ function ExpensesList({
const [deleteExpenseState, setDeleteExpense] = useState();
- const handleDeleteExpense = (expense) => { setDeleteExpense(expense); };
- const handleCancelAccountDelete = () => { setDeleteExpense(false); }
+ const handleDeleteExpense = expense => {
+ setDeleteExpense(expense);
+ };
+ const handleCancelAccountDelete = () => {
+ setDeleteExpense(false);
+ };
const handleConfirmAccountDelete = () => {
deleteExpense(deleteExpenseState.id).then(() => {
setDeleteExpense(false);
AppToaster.show({
- message: 'the_expense_has_been_deleted',
+ message: 'the_expense_has_been_deleted'
});
});
};
-
+
const fetchHook = useAsync(async () => {
await Promise.all([
- fetchExpenses(),
+ fetchExpenses()
// getResourceViews('expenses'),
]);
});
@@ -48,24 +52,28 @@ function ExpensesList({
-
+
+ onConfirm={handleConfirmAccountDelete}
+ >
- Are you sure you want to move filename to Trash? You will be able to restore it later,
- but it will become private to you.
+ Are you sure you want to move filename to Trash? You will be
+ able to restore it later, but it will become private to you.
);
-};
+}
-export default connector(ExpensesList);
\ No newline at end of file
+export default connector(ExpensesList);
diff --git a/client/src/containers/Dashboard/Items/ItemForm.js b/client/src/containers/Dashboard/Items/ItemForm.js
index e69de29bb..c80aead50 100644
--- a/client/src/containers/Dashboard/Items/ItemForm.js
+++ b/client/src/containers/Dashboard/Items/ItemForm.js
@@ -0,0 +1,47 @@
+import React, { useEffect } from 'react';
+import { useParams } from 'react-router-dom';
+import { useAsync } from 'react-use';
+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 { compose } from 'utils';
+const ItemFormContainer = ({
+ changePageTitle,
+ fetchAccount,
+ submitItem,
+ editItem,
+ fetchItems,
+ fetchItem,
+ deleteItem,
+ accounts
+}) => {
+ const { id } = useParams();
+ useEffect(() => {
+ id ? changePageTitle('Edit Item Details') : changePageTitle('New Item');
+ }, []);
+
+ const fetchHook = useAsync(async () => {
+ await Promise.all([fetchAccount()]);
+ });
+ return (
+
+
+
+ );
+};
+
+export default compose(
+ DashboardConnect,
+ ItemsConnect
+ // AccountsConnect
+)(ItemFormContainer);
diff --git a/client/src/containers/Dashboard/Items/ItemsList.js b/client/src/containers/Dashboard/Items/ItemsList.js
index ef772983e..da167e123 100644
--- a/client/src/containers/Dashboard/Items/ItemsList.js
+++ b/client/src/containers/Dashboard/Items/ItemsList.js
@@ -91,4 +91,4 @@ export default compose(
ResourceConnect,
ItemsConnect,
CustomViewsConnect,
-)(ItemsList);
\ No newline at end of file
+)(ItemsList);
diff --git a/client/src/routes/dashboard.js b/client/src/routes/dashboard.js
index b6e8070e5..e319ea631 100644
--- a/client/src/routes/dashboard.js
+++ b/client/src/routes/dashboard.js
@@ -10,7 +10,7 @@ export default [
component: LazyLoader({
loader: () => import('containers/Dashboard/Homepage')
}),
- exact: true,
+ exact: true
},
// Accounts.
@@ -19,7 +19,7 @@ export default [
name: 'dashboard.accounts',
component: LazyLoader({
loader: () => import('containers/Dashboard/Accounts/AccountsChart')
- }),
+ })
},
// Custom views.
@@ -28,14 +28,14 @@ export default [
name: 'dashboard.custom_view.new',
component: LazyLoader({
loader: () => import('containers/Dashboard/Views/ViewFormPage')
- }),
+ })
},
{
path: `${BASE_URL}/custom_views/:view_id/edit`,
name: 'dashboard.custom_view.edit',
component: LazyLoader({
loader: () => import('containers/Dashboard/Views/ViewFormPage')
- }),
+ })
},
// Expenses.
@@ -45,25 +45,25 @@ export default [
component: LazyLoader({
loader: () => import('containers/Dashboard/Expenses/ExpenseForm')
}),
- text: 'New Expense',
+ text: 'New Expense'
},
{
path: `${BASE_URL}/expenses`,
name: 'dashboard.expeneses.list',
component: LazyLoader({
loader: () => import('containers/Dashboard/Expenses/ExpensesList')
- }),
+ })
},
-
// Accounting
{
path: `${BASE_URL}/accounting/make-journal-entry`,
name: 'dashboard.accounting.make.journal',
component: LazyLoader({
- loader: () => import('containers/Dashboard/Accounting/MakeJournalEntriesPage')
+ loader: () =>
+ import('containers/Dashboard/Accounting/MakeJournalEntriesPage')
}),
- text: 'Make Journal Entry',
+ text: 'Make Journal Entry'
},
// Items
@@ -73,41 +73,58 @@ export default [
loader: () => import('containers/Dashboard/Items/ItemsList')
}),
},
+ {
+ path: `${BASE_URL}/items/new`,
+ component: LazyLoader({
+ loader: () => import('containers/Dashboard/Items/ItemForm')
+ }),
+ },
// Financial Reports.
{
path: `${BASE_URL}/accounting/general-ledger`,
name: 'dashboard.accounting.general.ledger',
component: LazyLoader({
- loader: () => import('containers/Dashboard/FinancialStatements/LedgerSheet')
- }),
+ loader: () =>
+ import('containers/Dashboard/FinancialStatements/LedgerSheet')
+ })
},
{
path: `${BASE_URL}/accounting/balance-sheet`,
name: 'dashboard.accounting.balance.sheet',
component: LazyLoader({
- loader: () => import('containers/Dashboard/FinancialStatements/BalanceSheet/BalanceSheet')
- }),
+ loader: () =>
+ import(
+ 'containers/Dashboard/FinancialStatements/BalanceSheet/BalanceSheet'
+ )
+ })
},
{
path: `${BASE_URL}/accounting/trial-balance-sheet`,
name: 'dashboard.accounting.trial.balance',
component: LazyLoader({
- loader: () => import('containers/Dashboard/FinancialStatements/TrialBalanceSheet/TrialBalanceSheet')
- }),
+ loader: () =>
+ import(
+ 'containers/Dashboard/FinancialStatements/TrialBalanceSheet/TrialBalanceSheet'
+ )
+ })
},
{
path: `${BASE_URL}/accounting/profit-loss-sheet`,
name: 'dashboard.accounting.profit.loss.sheet',
component: LazyLoader({
- loader: () => import('containers/Dashboard/FinancialStatements/ProfitLossSheet/ProfitLossSheet')
- }),
+ loader: () =>
+ import(
+ 'containers/Dashboard/FinancialStatements/ProfitLossSheet/ProfitLossSheet'
+ )
+ })
},
{
path: `${BASE_URL}/accounting/journal-sheet`,
name: 'dashboard.accounting.journal.sheet',
component: LazyLoader({
- loader: () => import('containers/Dashboard/FinancialStatements/Journal/Journal')
- }),
- },
-];
\ No newline at end of file
+ loader: () =>
+ import('containers/Dashboard/FinancialStatements/Journal/Journal')
+ })
+ }
+];
diff --git a/client/src/store/accounts/accounts.actions.js b/client/src/store/accounts/accounts.actions.js
index 4acbe3be7..3b2d5b6a1 100644
--- a/client/src/store/accounts/accounts.actions.js
+++ b/client/src/store/accounts/accounts.actions.js
@@ -2,107 +2,131 @@ import ApiService from 'services/ApiService';
import t from 'store/types';
export const fetchAccountTypes = () => {
- return (dispatch, getState) => new Promise((resolve, reject) => {
- ApiService.get('account_types').then((response) => {
- dispatch({
- type: t.ACCOUNT_TYPES_LIST_SET,
- account_types: response.data.account_types,
- });
- resolve(response);
- }).catch((error) => { reject(error); });
- });
+ return (dispatch, getState) =>
+ new Promise((resolve, reject) => {
+ ApiService.get('account_types')
+ .then(response => {
+ dispatch({
+ type: t.ACCOUNT_TYPES_LIST_SET,
+ account_types: response.data.account_types
+ });
+ resolve(response);
+ })
+ .catch(error => {
+ reject(error);
+ });
+ });
};
export const fetchAccountsList = ({ query } = {}) => {
- return (dispatch) => new Promise((resolve, reject) => {
- ApiService.get('accounts', { params: query }).then((response) => {
- dispatch({
- type: t.ACCOUNTS_PAGE_SET,
- accounts: response.data.accounts,
- customViewId: response.data.customViewId,
- });
- dispatch({
- type: t.ACCOUNTS_ITEMS_SET,
- accounts: response.data.accounts,
- });
- resolve(response);
- }).catch((error) => { reject(error); });
- });
+ return dispatch =>
+ new Promise((resolve, reject) => {
+ ApiService.get('accounts', { params: query })
+ .then(response => {
+ dispatch({
+ type: t.ACCOUNTS_PAGE_SET,
+ accounts: response.data.accounts,
+ customViewId: response.data.customViewId
+ });
+ dispatch({
+ type: t.ACCOUNTS_ITEMS_SET,
+ accounts: response.data.accounts
+ });
+ resolve(response);
+ })
+ .catch(error => {
+ reject(error);
+ });
+ });
};
export const fetchAccountsDataTable = ({ query }) => {
- return (dispatch) => new Promise((resolve, reject) => {
- ApiService.get('accounts', ).then((response) => {
- dispatch({
- type: t.ACCOUNTS_DATA_TABLE,
- data: response.data,
- })
- }).catch((error) => { reject(error); })
- })
+ return dispatch =>
+ new Promise((resolve, reject) => {
+ ApiService.get('accounts')
+ .then(response => {
+ dispatch({
+ type: t.ACCOUNTS_DATA_TABLE,
+ data: response.data
+ });
+ })
+ .catch(error => {
+ reject(error);
+ });
+ });
};
export const submitAccount = ({ form }) => {
- return (dispatch) => new Promise((resolve, reject) => {
- ApiService.post('accounts', form).then((response) => {
- dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
- resolve(response);
- }).catch((error) => {
- const { response } = error;
- const { data } = response;
- const { errors } = data;
+ return dispatch =>
+ new Promise((resolve, reject) => {
+ ApiService.post('accounts', form)
+ .then(response => {
+ dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
+ resolve(response);
+ })
+ .catch(error => {
+ const { response } = error;
+ const { data } = response;
+ const { errors } = data;
- dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
- if (errors){
- dispatch({ type: t.ACCOUNT_FORM_ERRORS, errors });
- }
- reject(error);
+ dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
+ if (errors) {
+ dispatch({ type: t.ACCOUNT_FORM_ERRORS, errors });
+ }
+ reject(error);
+ });
});
- });
};
export const editAccount = ({ id, form }) => {
- return (dispatch) => new Promise((resolve, reject) => {
- ApiService.post(`accounts/${id}`, form).then((response) => {
- dispatch({type: t.CLEAR_ACCOUNT_FORM_ERRORS});
- resolve(response);
- }).catch((error) => {
- const { response } = error;
- const { data } = response;
- const { errors } = data;
+ return dispatch =>
+ new Promise((resolve, reject) => {
+ ApiService.post(`accounts/${id}`, form)
+ .then(response => {
+ dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
+ resolve(response);
+ })
+ .catch(error => {
+ const { response } = error;
+ const { data } = response;
+ const { errors } = data;
- dispatch({type: t.CLEAR_ACCOUNT_FORM_ERRORS});
- if (errors){
- dispatch({ type: t.ACCOUNT_FORM_ERRORS, errors });
- }
- reject(error);
+ dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
+ if (errors) {
+ dispatch({ type: t.ACCOUNT_FORM_ERRORS, errors });
+ }
+ reject(error);
+ });
});
- });
};
export const activeAccount = ({ id }) => {
- return (dispatch) => ApiService.post(`accounts/${id}/active`);
+ return dispatch => ApiService.post(`accounts/${id}/active`);
};
export const inactiveAccount = ({ id }) => {
- return (dispatch) => ApiService.post(`accounts/${id}/inactive`);
+ return dispatch => ApiService.post(`accounts/${id}/inactive`);
};
export const deleteAccount = ({ id }) => {
- return (dispatch) => ApiService.delete(`accounts/${id}`);
+ return dispatch => ApiService.delete(`accounts/${id}`);
};
-export const deleteBulkAccounts = ({ ids }) => {
-
-};
+export const deleteBulkAccounts = ({ ids }) => {};
export const fetchAccount = ({ id }) => {
- return (dispatch) => new Promise((resolve, reject) => {
- ApiService.get(`accounts/${id}`).then((response) => {
- dispatch({
- type: t.ACCOUNT_SET,
- account: response.data.account,
- });
- resolve(response);
- }).catch((error) => { reject(error); });
- });
-}
\ No newline at end of file
+ return dispatch =>
+ new Promise((resolve, reject) => {
+ ApiService.get(`accounts/${id}`)
+ .then(response => {
+ dispatch({
+ type: t.ACCOUNT_SET,
+ account: response.data.account
+ });
+ resolve(response);
+ })
+ .catch(error => {
+ reject(error);
+ });
+ });
+};
diff --git a/client/src/store/items/items.actions.js b/client/src/store/items/items.actions.js
index 09a467bde..70b2c00f8 100644
--- a/client/src/store/items/items.actions.js
+++ b/client/src/store/items/items.actions.js
@@ -1,12 +1,12 @@
-import ApiService from "services/ApiService"
+import ApiService from 'services/ApiService';
import t from 'store/types';
export const submitItem = ({ form }) => {
- return (dispatch) => ApiService.post(`items`, form);
+ return dispatch => ApiService.post(`items`, form);
};
export const editItem = ({ id, form }) => {
- return (dispatch) => ApiService.post(`items/${id}`, form);
+ return dispatch => ApiService.post(`items/${id}`, form);
};
export const fetchItems = ({ query }) => {
@@ -28,16 +28,21 @@ export const fetchItems = ({ query }) => {
};
export const fetchItem = ({ id }) => {
- return (dispatch) => new Promise((resolve, reject) => {
- ApiService.get(`items/${id}`).then((response) => {
- dispatch({
- type: t.ITEM_SET,
- item: response.data.item,
- });
- }).catch(error => { reject(error); });
- });
+ return dispatch =>
+ new Promise((resolve, reject) => {
+ ApiService.get(`items/${id}`)
+ .then(response => {
+ dispatch({
+ type: t.ITEM_SET,
+ item: response.data.item
+ });
+ })
+ .catch(error => {
+ reject(error);
+ });
+ });
};
export const deleteItem = ({ id }) => {
- return (dispatch) => ApiService.delete(`items/${id}`);
-};
\ No newline at end of file
+ return dispatch => ApiService.delete(`items/${id}`);
+};
diff --git a/client/src/store/items/items.reducer.js b/client/src/store/items/items.reducer.js
index 535f12a46..5fb2c5d16 100644
--- a/client/src/store/items/items.reducer.js
+++ b/client/src/store/items/items.reducer.js
@@ -89,4 +89,4 @@ export default createReducer(initialState, {
export const getItemById = (state, id) => {
return state.items.items[id];
-};
\ No newline at end of file
+};
diff --git a/client/src/store/items/items.types.js b/client/src/store/items/items.types.js
index 2f304348a..41baed9de 100644
--- a/client/src/store/items/items.types.js
+++ b/client/src/store/items/items.types.js
@@ -6,4 +6,4 @@ export default {
ITEM_DELETE: 'ITEM_DELETE',
ITEM_BULK_ACTION_ADD: 'ITEM_BULK_ACTION_ADD',
ITEM_BULK_ACTION_REMOVE: 'ITEM_BULK_ACTION_REMOVE',
-}
\ No newline at end of file
+}