mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
WIP / fix_accounts
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState, useMemo, useCallback } from 'react';
|
import React, { useEffect, useState, useMemo, useCallback } from 'react';
|
||||||
import { Route, Switch } from 'react-router-dom';
|
import { Route, Switch } from 'react-router-dom';
|
||||||
import { Alert, Intent } from '@blueprintjs/core';
|
import { Alert, Intent } from '@blueprintjs/core';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery, queryCache } from 'react-query';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
FormattedHTMLMessage,
|
FormattedHTMLMessage,
|
||||||
@@ -136,16 +136,22 @@ function AccountsChart({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Handle confirm account activation.
|
// Handle confirm account activation.
|
||||||
|
|
||||||
const handleConfirmAccountActive = useCallback(() => {
|
const handleConfirmAccountActive = useCallback(() => {
|
||||||
requestInactiveAccount(inactiveAccount.id).then(() => {
|
requestInactiveAccount(inactiveAccount.id)
|
||||||
setInactiveAccount(false);
|
.then(() => {
|
||||||
AppToaster.show({
|
setInactiveAccount(false);
|
||||||
message: formatMessage({
|
AppToaster.show({
|
||||||
id: 'the_account_has_been_successfully_inactivated',
|
message: formatMessage({
|
||||||
}),
|
id: 'the_account_has_been_successfully_inactivated',
|
||||||
intent: Intent.SUCCESS,
|
}),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
queryCache.refetchQueries('accounts-table', { force: true });
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
setInactiveAccount(false);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}, [inactiveAccount, requestInactiveAccount, formatMessage]);
|
}, [inactiveAccount, requestInactiveAccount, formatMessage]);
|
||||||
|
|
||||||
// Handle activate account click.
|
// Handle activate account click.
|
||||||
@@ -160,16 +166,21 @@ function AccountsChart({
|
|||||||
|
|
||||||
// Handle activate account confirm.
|
// Handle activate account confirm.
|
||||||
const handleConfirmAccountActivate = useCallback(() => {
|
const handleConfirmAccountActivate = useCallback(() => {
|
||||||
requestActivateAccount(activateAccount.id).then(() => {
|
requestActivateAccount(activateAccount.id)
|
||||||
setActivateAccount(false);
|
.then(() => {
|
||||||
AppToaster.show({
|
setActivateAccount(false);
|
||||||
message: formatMessage({
|
AppToaster.show({
|
||||||
id: 'the_account_has_been_successfully_activated',
|
message: formatMessage({
|
||||||
}),
|
id: 'the_account_has_been_successfully_activated',
|
||||||
intent: Intent.SUCCESS,
|
}),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
queryCache.refetchQueries('accounts-table', { force: true });
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
setActivateAccount(false);
|
||||||
});
|
});
|
||||||
});
|
}, [activateAccount, requestActivateAccount, formatMessage]);
|
||||||
});
|
|
||||||
|
|
||||||
const handleRestoreAccount = (account) => {};
|
const handleRestoreAccount = (account) => {};
|
||||||
|
|
||||||
@@ -341,7 +352,6 @@ function AccountsChart({
|
|||||||
onEditAccount={handleEditAccount}
|
onEditAccount={handleEditAccount}
|
||||||
onFetchData={handleFetchData}
|
onFetchData={handleFetchData}
|
||||||
onSelectedRowsChange={handleSelectedRowsChange}
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
|
|||||||
@@ -69,7 +69,12 @@ function AccountsDataTable({
|
|||||||
|
|
||||||
const handleNewParentAccount = useCallback(
|
const handleNewParentAccount = useCallback(
|
||||||
(account) => {
|
(account) => {
|
||||||
openDialog('account-form', { action: 'new_child', id: account.id });
|
openDialog('account-form', {
|
||||||
|
action: 'new_child',
|
||||||
|
parentAccountId: account.id,
|
||||||
|
accountTypeId: account.account_type_id,
|
||||||
|
subaccount: true,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
[openDialog],
|
[openDialog],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
deleteBulkAccounts,
|
deleteBulkAccounts,
|
||||||
bulkActivateAccounts,
|
bulkActivateAccounts,
|
||||||
bulkInactiveAccounts,
|
bulkInactiveAccounts,
|
||||||
editAccount
|
editAccount,
|
||||||
} from 'store/accounts/accounts.actions';
|
} from 'store/accounts/accounts.actions';
|
||||||
|
|
||||||
const mapActionsToProps = (dispatch) => ({
|
const mapActionsToProps = (dispatch) => ({
|
||||||
@@ -22,9 +22,9 @@ const mapActionsToProps = (dispatch) => ({
|
|||||||
requestActivateAccount: (id) => dispatch(activateAccount({ id })),
|
requestActivateAccount: (id) => dispatch(activateAccount({ id })),
|
||||||
requestFetchAccount: (id) => dispatch(fetchAccount({ id })),
|
requestFetchAccount: (id) => dispatch(fetchAccount({ id })),
|
||||||
requestDeleteBulkAccounts: (ids) => dispatch(deleteBulkAccounts({ ids })),
|
requestDeleteBulkAccounts: (ids) => dispatch(deleteBulkAccounts({ ids })),
|
||||||
requestBulkActivateAccounts:(ids)=>dispatch(bulkActivateAccounts({ids})),
|
requestBulkActivateAccounts: (ids) => dispatch(bulkActivateAccounts({ ids })),
|
||||||
requestBulkInactiveAccounts:(ids)=>dispatch(bulkInactiveAccounts({ids})),
|
requestBulkInactiveAccounts: (ids) => dispatch(bulkInactiveAccounts({ ids })),
|
||||||
requestEditAccount:({id,form}) => dispatch(editAccount({id,form}))
|
requestEditAccount: (id, form) => dispatch(editAccount(id, form)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(null, mapActionsToProps);
|
export default connect(null, mapActionsToProps);
|
||||||
@@ -9,7 +9,6 @@ import withAccounts from 'containers/Accounts/withAccounts';
|
|||||||
|
|
||||||
export const mapStateToProps = (state, props) => {
|
export const mapStateToProps = (state, props) => {
|
||||||
const dialogPayload = getDialogPayload(state, 'account-form');
|
const dialogPayload = getDialogPayload(state, 'account-form');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'account-form',
|
name: 'account-form',
|
||||||
payload: { action: 'new', id: null, ...dialogPayload },
|
payload: { action: 'new', id: null, ...dialogPayload },
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useEffect, useMemo } from 'react';
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Classes,
|
Classes,
|
||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { useFormik } from 'formik';
|
import { useFormik } from 'formik';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
import { If } from 'components';
|
||||||
import { omit, pick } from 'lodash';
|
import { omit, pick } from 'lodash';
|
||||||
import { useQuery, queryCache } from 'react-query';
|
import { useQuery, queryCache } from 'react-query';
|
||||||
|
|
||||||
@@ -59,14 +59,16 @@ function AccountFormDialog({
|
|||||||
.nullable()
|
.nullable()
|
||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'account_type_id' })),
|
.label(formatMessage({ id: 'account_type_id' })),
|
||||||
description: Yup.string().trim(),
|
description: Yup.string().nullable().trim(),
|
||||||
|
// parent_account_id: Yup.string().nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
account_type_id: null,
|
account_type_id: null,
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
|
code: '',
|
||||||
|
type: '',
|
||||||
}),
|
}),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
@@ -92,7 +94,11 @@ function AccountFormDialog({
|
|||||||
} = useFormik({
|
} = useFormik({
|
||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
initialValues: {
|
initialValues: {
|
||||||
...(payload.action === 'edit' && account ? account : initialValues),
|
// ...initialValues,
|
||||||
|
// ...(payload.action === 'edit' && account ? account : initialValues),
|
||||||
|
|
||||||
|
...(payload.action === 'edit' &&
|
||||||
|
pick(account, Object.keys(initialValues))),
|
||||||
},
|
},
|
||||||
validationSchema: accountFormValidationSchema,
|
validationSchema: accountFormValidationSchema,
|
||||||
onSubmit: (values, { setSubmitting, setErrors }) => {
|
onSubmit: (values, { setSubmitting, setErrors }) => {
|
||||||
@@ -102,22 +108,12 @@ function AccountFormDialog({
|
|||||||
: values.name;
|
: values.name;
|
||||||
|
|
||||||
if (payload.action === 'edit') {
|
if (payload.action === 'edit') {
|
||||||
requestEditAccount({
|
requestEditAccount(payload.id, values)
|
||||||
payload: payload.id,
|
|
||||||
// form: { ...omit(values, [...exclude, 'account_type_id']) },
|
|
||||||
form: {
|
|
||||||
...pick(values, [
|
|
||||||
...exclude,
|
|
||||||
'account_type_id',
|
|
||||||
'name',
|
|
||||||
'description',
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
closeDialog(name);
|
|
||||||
queryCache.refetchQueries('accounts-table', { force: true });
|
queryCache.refetchQueries('accounts-table', { force: true });
|
||||||
|
|
||||||
|
closeDialog(name);
|
||||||
|
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage(
|
message: formatMessage(
|
||||||
{ id: 'service_has_been_successful_edited' },
|
{ id: 'service_has_been_successful_edited' },
|
||||||
@@ -135,7 +131,10 @@ function AccountFormDialog({
|
|||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
requestSubmitAccount({ form: { ...omit(values, exclude) } })
|
requestSubmitAccount({
|
||||||
|
payload: payload.parent_account_id,
|
||||||
|
form: { ...omit(values, exclude) },
|
||||||
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
closeDialog(name);
|
closeDialog(name);
|
||||||
queryCache.refetchQueries('accounts-table', { force: true });
|
queryCache.refetchQueries('accounts-table', { force: true });
|
||||||
@@ -161,6 +160,9 @@ function AccountFormDialog({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handlechange = useCallback((newChecked) => {
|
||||||
|
setChecked(newChecked);
|
||||||
|
}, []);
|
||||||
// Filtered accounts based on the given account type.
|
// Filtered accounts based on the given account type.
|
||||||
const filteredAccounts = useMemo(
|
const filteredAccounts = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -190,7 +192,12 @@ function AccountFormDialog({
|
|||||||
// Account item of select accounts field.
|
// Account item of select accounts field.
|
||||||
const accountItem = (item, { handleClick, modifiers, query }) => {
|
const accountItem = (item, { handleClick, modifiers, query }) => {
|
||||||
return (
|
return (
|
||||||
<MenuItem text={item.name} label={item.code} key={item.id} onClick={handleClick} />
|
<MenuItem
|
||||||
|
text={item.name}
|
||||||
|
label={item.code}
|
||||||
|
key={item.id}
|
||||||
|
onClick={handleClick}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,6 +218,8 @@ function AccountFormDialog({
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log(values, 'Values');
|
||||||
|
|
||||||
// Handles dialog close.
|
// Handles dialog close.
|
||||||
const handleClose = useCallback(() => {
|
const handleClose = useCallback(() => {
|
||||||
closeDialog(name);
|
closeDialog(name);
|
||||||
@@ -234,7 +243,15 @@ function AccountFormDialog({
|
|||||||
|
|
||||||
// Fetch the given account id on edit mode.
|
// Fetch the given account id on edit mode.
|
||||||
const fetchAccount = useQuery(
|
const fetchAccount = useQuery(
|
||||||
payload.action === 'edit' && ['account', payload.id],
|
(payload.action === 'edit' && ['account', payload.id]) ||
|
||||||
|
(payload.action === 'new_child' && ['account', payload.parentAccountId]),
|
||||||
|
// payload.action === 'new_child' ||
|
||||||
|
// (payload.action === 'edit' && [
|
||||||
|
// 'account',
|
||||||
|
|
||||||
|
// payload.id,
|
||||||
|
// payload.parentAccountId,
|
||||||
|
// ]),
|
||||||
(key, id) => requestFetchAccount(id),
|
(key, id) => requestFetchAccount(id),
|
||||||
{ manual: true },
|
{ manual: true },
|
||||||
);
|
);
|
||||||
@@ -249,6 +266,13 @@ function AccountFormDialog({
|
|||||||
fetchAccountsList.refetch();
|
fetchAccountsList.refetch();
|
||||||
fetchAccountsTypes.refetch();
|
fetchAccountsTypes.refetch();
|
||||||
fetchAccount.refetch();
|
fetchAccount.refetch();
|
||||||
|
|
||||||
|
if (payload.action === 'new_child') {
|
||||||
|
// sub account checkbox should be equal true.
|
||||||
|
setFieldValue('subaccount', payload.subaccount);
|
||||||
|
setFieldValue('parent_account_id', payload.parentAccountId);
|
||||||
|
setFieldValue('account_type_id', payload.accountTypeId);
|
||||||
|
}
|
||||||
}, [fetchAccount, fetchAccountsList, fetchAccountsTypes]);
|
}, [fetchAccount, fetchAccountsList, fetchAccountsTypes]);
|
||||||
|
|
||||||
const onChangeAccountType = useCallback(
|
const onChangeAccountType = useCallback(
|
||||||
@@ -376,10 +400,11 @@ function AccountFormDialog({
|
|||||||
inline={true}
|
inline={true}
|
||||||
label={subAccountLabel}
|
label={subAccountLabel}
|
||||||
{...getFieldProps('subaccount')}
|
{...getFieldProps('subaccount')}
|
||||||
|
checked={values.subaccount}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
<If condition={values.subaccount}>
|
||||||
{values.subaccount && (
|
{/* {values.subaccount && ( */}
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'parent_account'} />}
|
label={<T id={'parent_account'} />}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
@@ -402,8 +427,8 @@ function AccountFormDialog({
|
|||||||
labelProp={'name'}
|
labelProp={'name'}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
{/* )} */}
|
||||||
|
</If>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'description'} />}
|
label={<T id={'description'} />}
|
||||||
className={'form-group--description'}
|
className={'form-group--description'}
|
||||||
|
|||||||
@@ -67,8 +67,10 @@ function ExchangeRateDialog({
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const fetchExchangeRatesDialog = useQuery('exchange-rates-dialog', () =>
|
const fetchExchangeRatesDialog = useQuery(
|
||||||
requestFetchExchangeRates(),
|
'exchange-rates-dialog',
|
||||||
|
() => requestFetchExchangeRates(),
|
||||||
|
{ manual: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ function ViewForm({
|
|||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
resource_name: Yup.string().required(),
|
resource_name: Yup.string().required(),
|
||||||
name: Yup.string().required(),
|
name: Yup.string().required().label(intl.formatMessage({id:'name_'})),
|
||||||
logic_expression: Yup.string().required(),
|
logic_expression: Yup.string().required().label(intl.formatMessage({id:'logic_expression'})),
|
||||||
roles: Yup.array().of(
|
roles: Yup.array().of(
|
||||||
Yup.object().shape({
|
Yup.object().shape({
|
||||||
comparator: Yup.string().required(),
|
comparator: Yup.string().required(),
|
||||||
|
|||||||
@@ -447,6 +447,7 @@ export default {
|
|||||||
as_date: 'As Date',
|
as_date: 'As Date',
|
||||||
aging_before_days: 'Aging before days',
|
aging_before_days: 'Aging before days',
|
||||||
aging_periods: 'Aging periods',
|
aging_periods: 'Aging periods',
|
||||||
|
name_:'name',
|
||||||
as: 'As',
|
as: 'As',
|
||||||
receivable_aging_summary: 'Receivable Aging Summary',
|
receivable_aging_summary: 'Receivable Aging Summary',
|
||||||
customers: 'Customers',
|
customers: 'Customers',
|
||||||
@@ -457,7 +458,7 @@ export default {
|
|||||||
customer_type: 'Customer Type',
|
customer_type: 'Customer Type',
|
||||||
business: 'business',
|
business: 'business',
|
||||||
individual: 'Individual',
|
individual: 'Individual',
|
||||||
display_name:'Display Name',
|
display_name: 'Display Name',
|
||||||
the_customer_has_been_successfully_created:
|
the_customer_has_been_successfully_created:
|
||||||
'The customer has been successfully created.',
|
'The customer has been successfully created.',
|
||||||
select_contact: 'Select contact',
|
select_contact: 'Select contact',
|
||||||
@@ -470,7 +471,8 @@ export default {
|
|||||||
all_reports: 'All Reports',
|
all_reports: 'All Reports',
|
||||||
next: 'Next',
|
next: 'Next',
|
||||||
previous: 'Previous',
|
previous: 'Previous',
|
||||||
showing_current_page_to_total: 'Showing {currentPage} to {totalPages} of {total} entries',
|
showing_current_page_to_total:
|
||||||
|
'Showing {currentPage} to {totalPages} of {total} entries',
|
||||||
new_child_account: 'New Child Account',
|
new_child_account: 'New Child Account',
|
||||||
display_name: 'Display Name',
|
display_name: 'Display Name',
|
||||||
contact_name: 'Contact Name',
|
contact_name: 'Contact Name',
|
||||||
@@ -489,14 +491,14 @@ export default {
|
|||||||
shipping_address: 'Shipping Address',
|
shipping_address: 'Shipping Address',
|
||||||
customers_list: 'Customers List',
|
customers_list: 'Customers List',
|
||||||
edit_customer_details: 'Edit Customer Details',
|
edit_customer_details: 'Edit Customer Details',
|
||||||
receivable_balance:'Receivable balance',
|
receivable_balance: 'Receivable balance',
|
||||||
the_customer_has_been_successfully_created:
|
the_customer_has_been_successfully_created:
|
||||||
'The customer has been successfully created.',
|
'The customer has been successfully created.',
|
||||||
the_customer_has_been_successfully_deleted:
|
the_customer_has_been_successfully_deleted:
|
||||||
'The customer has been successfully deleted.',
|
'The customer has been successfully deleted.',
|
||||||
the_customers_has_been_successfully_deleted:
|
the_customers_has_been_successfully_deleted:
|
||||||
'The customers have been successfully deleted.',
|
'The customers have been successfully deleted.',
|
||||||
the_item_customer_has_been_successfully_edited:
|
the_item_customer_has_been_successfully_edited:
|
||||||
'The item customer has been successfully edited.',
|
'The item customer has been successfully edited.',
|
||||||
once_delete_this_customer_you_will_able_to_restore_it: `Once you delete this customer, you won\'t be able to restore it later. Are you sure you want to delete this cusomter?`,
|
once_delete_this_customer_you_will_able_to_restore_it: `Once you delete this customer, you won\'t be able to restore it later. Are you sure you want to delete this cusomter?`,
|
||||||
once_delete_these_customers_you_will_not_able_restore_them:
|
once_delete_these_customers_you_will_not_able_restore_them:
|
||||||
@@ -510,4 +512,5 @@ export default {
|
|||||||
create_a_new_view: 'Create a new view',
|
create_a_new_view: 'Create a new view',
|
||||||
in: 'In',
|
in: 'In',
|
||||||
not_equals: 'Not Equals',
|
not_equals: 'Not Equals',
|
||||||
|
logic_expression: 'logic expression ',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,44 +6,48 @@ export const fetchAccountTypes = () => {
|
|||||||
return (dispatch, getState) =>
|
return (dispatch, getState) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
ApiService.get('account_types')
|
ApiService.get('account_types')
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNT_TYPES_LIST_SET,
|
type: t.ACCOUNT_TYPES_LIST_SET,
|
||||||
account_types: response.data.account_types
|
account_types: response.data.account_types,
|
||||||
});
|
});
|
||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
.catch(error => { reject(error); });
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchAccountsList = ({ query } = {}) => {
|
export const fetchAccountsList = ({ query } = {}) => {
|
||||||
return dispatch => new Promise((resolve, reject) => {
|
return (dispatch) =>
|
||||||
dispatch({
|
new Promise((resolve, reject) => {
|
||||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
|
});
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
|
});
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
|
});
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
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
|
|
||||||
});
|
|
||||||
dispatch({
|
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
|
||||||
});
|
|
||||||
resolve(response);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
dispatch({
|
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
|
||||||
});
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchAccountsTable = ({ query } = {}) => {
|
export const fetchAccountsTable = ({ query } = {}) => {
|
||||||
@@ -54,7 +58,8 @@ export const fetchAccountsTable = ({ query } = {}) => {
|
|||||||
if (pageQuery.filter_roles) {
|
if (pageQuery.filter_roles) {
|
||||||
pageQuery = {
|
pageQuery = {
|
||||||
...omit(pageQuery, ['filter_roles']),
|
...omit(pageQuery, ['filter_roles']),
|
||||||
stringified_filter_roles: JSON.stringify(pageQuery.filter_roles) || '',
|
stringified_filter_roles:
|
||||||
|
JSON.stringify(pageQuery.filter_roles) || '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
dispatch({
|
dispatch({
|
||||||
@@ -69,11 +74,11 @@ export const fetchAccountsTable = ({ query } = {}) => {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNTS_PAGE_SET,
|
type: t.ACCOUNTS_PAGE_SET,
|
||||||
accounts: response.data.accounts,
|
accounts: response.data.accounts,
|
||||||
customViewId: response.data.customViewId
|
customViewId: response.data.customViewId,
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNTS_ITEMS_SET,
|
type: t.ACCOUNTS_ITEMS_SET,
|
||||||
accounts: response.data.accounts
|
accounts: response.data.accounts,
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNTS_TABLE_LOADING,
|
type: t.ACCOUNTS_TABLE_LOADING,
|
||||||
@@ -94,29 +99,29 @@ export const fetchAccountsTable = ({ query } = {}) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const fetchAccountsDataTable = ({ query }) => {
|
export const fetchAccountsDataTable = ({ query }) => {
|
||||||
return dispatch =>
|
return (dispatch) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
ApiService.get('accounts')
|
ApiService.get('accounts')
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNTS_DATA_TABLE,
|
type: t.ACCOUNTS_DATA_TABLE,
|
||||||
data: response.data
|
data: response.data,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const submitAccount = ({ form }) => {
|
export const submitAccount = ({ form }) => {
|
||||||
return dispatch =>
|
return (dispatch) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
});
|
});
|
||||||
ApiService.post('accounts', form)
|
ApiService.post('accounts', form)
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNT_ERRORS_CLEAR,
|
type: t.ACCOUNT_ERRORS_CLEAR,
|
||||||
});
|
});
|
||||||
@@ -125,140 +130,149 @@ export const submitAccount = ({ form }) => {
|
|||||||
});
|
});
|
||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
const { response } = error;
|
const { response } = error;
|
||||||
const { data } = response;
|
const { data } = response;
|
||||||
const { errors } = data;
|
// const { errors } = data;
|
||||||
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNT_ERRORS_CLEAR,
|
type: t.ACCOUNT_ERRORS_CLEAR,
|
||||||
});
|
});
|
||||||
if (errors) {
|
if (error) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNT_ERRORS_SET,
|
type: t.ACCOUNT_ERRORS_SET,
|
||||||
payload: { errors },
|
payload: { error },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
});
|
});
|
||||||
reject(errors);
|
reject(data?.errors);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const editAccount = ({ id, form }) => {
|
export const editAccount = (id, form) => {
|
||||||
return dispatch => new Promise((resolve, reject) => {
|
return (dispatch) =>
|
||||||
dispatch({
|
|
||||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
|
||||||
});
|
|
||||||
ApiService.post(`accounts/${id}`, form)
|
|
||||||
.then(response => {
|
|
||||||
dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
|
|
||||||
dispatch({
|
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
|
||||||
});
|
|
||||||
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 });
|
|
||||||
}
|
|
||||||
dispatch({
|
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
|
||||||
});
|
|
||||||
reject(errors);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const activateAccount = ({ id }) => {
|
|
||||||
return dispatch => ApiService.post(`accounts/${id}/active`);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const inactiveAccount = ({ id }) => {
|
|
||||||
return dispatch => ApiService.post(`accounts/${id}/inactive`);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const bulkActivateAccounts =({ids})=>{
|
|
||||||
|
|
||||||
return dispatch => new Promise((resolve, reject) => {
|
|
||||||
|
|
||||||
ApiService.post(`accounts/bulk/activate`, null, { params: { ids }}).then((response) => {
|
|
||||||
dispatch({
|
|
||||||
type: t.BULK_ACTIVATE_ACCOUNTS,
|
|
||||||
payload: { ids }
|
|
||||||
});
|
|
||||||
resolve(response);
|
|
||||||
}).catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const bulkInactiveAccounts =({ids})=>{
|
|
||||||
|
|
||||||
return dispatch => new Promise((resolve, reject) => {
|
|
||||||
|
|
||||||
ApiService.post(`accounts/bulk/inactivate`, null, { params: { ids }}).then((response) => {
|
|
||||||
dispatch({
|
|
||||||
type: t.BULK_INACTIVATE_ACCOUNTS,
|
|
||||||
payload: { ids }
|
|
||||||
});
|
|
||||||
resolve(response);
|
|
||||||
}).catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const deleteAccount = ({ id }) => {
|
|
||||||
return dispatch => new Promise((resolve, reject) => {
|
|
||||||
ApiService.delete(`accounts/${id}`).then((response) => {
|
|
||||||
dispatch({ type: t.ACCOUNT_DELETE, id });
|
|
||||||
resolve(response);
|
|
||||||
}).catch((error) => {
|
|
||||||
reject(error.response.data.errors || []);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deleteBulkAccounts = ({ ids }) => {
|
|
||||||
return dispatch => new Promise((resolve, reject) => {
|
|
||||||
ApiService.delete(`accounts`, { params: { ids }}).then((response) => {
|
|
||||||
dispatch({
|
|
||||||
type: t.ACCOUNTS_BULK_DELETE,
|
|
||||||
payload: { ids }
|
|
||||||
});
|
|
||||||
resolve(response);
|
|
||||||
}).catch((error) => {
|
|
||||||
const { response } = error;
|
|
||||||
const { data } = response;
|
|
||||||
const { errors } = data;
|
|
||||||
|
|
||||||
reject(errors);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const fetchAccount = ({ id }) => {
|
|
||||||
return dispatch =>
|
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
ApiService.get(`accounts/${id}`)
|
dispatch({
|
||||||
.then(response => {
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
|
});
|
||||||
|
ApiService.post(`accounts/${id}`, form)
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNT_SET,
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
account: response.data.account
|
|
||||||
});
|
});
|
||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
|
const { response } = error;
|
||||||
|
const { data } = response;
|
||||||
|
// const { errors } = data;
|
||||||
|
|
||||||
|
dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
|
||||||
|
if (error) {
|
||||||
|
dispatch({ type: t.ACCOUNT_FORM_ERRORS, error });
|
||||||
|
}
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
|
});
|
||||||
|
reject(data?.errors);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const activateAccount = ({ id }) => {
|
||||||
|
return (dispatch) => ApiService.post(`accounts/${id}/active`);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const inactiveAccount = ({ id }) => {
|
||||||
|
return (dispatch) => ApiService.post(`accounts/${id}/inactive`);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const bulkActivateAccounts = ({ ids }) => {
|
||||||
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
ApiService.post(`accounts/bulk/activate`, null, { params: { ids } })
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.BULK_ACTIVATE_ACCOUNTS,
|
||||||
|
payload: { ids },
|
||||||
|
});
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const bulkInactiveAccounts = ({ ids }) => {
|
||||||
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
ApiService.post(`accounts/bulk/inactivate`, null, { params: { ids } })
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.BULK_INACTIVATE_ACCOUNTS,
|
||||||
|
payload: { ids },
|
||||||
|
});
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteAccount = ({ id }) => {
|
||||||
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
ApiService.delete(`accounts/${id}`)
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({ type: t.ACCOUNT_DELETE, id });
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error.response.data.errors || []);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteBulkAccounts = ({ ids }) => {
|
||||||
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
ApiService.delete(`accounts`, { params: { ids } })
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.ACCOUNTS_BULK_DELETE,
|
||||||
|
payload: { ids },
|
||||||
|
});
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const { response } = error;
|
||||||
|
const { data } = response;
|
||||||
|
// const { errors } = data;
|
||||||
|
|
||||||
|
reject(data?.errors);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user