mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
Fix: specific item api & customer api
This commit is contained in:
@@ -17,6 +17,7 @@ function Customer({
|
|||||||
formik,
|
formik,
|
||||||
//#withCustomersActions
|
//#withCustomersActions
|
||||||
requestFetchCustomers,
|
requestFetchCustomers,
|
||||||
|
requestFetchCustomer,
|
||||||
}) {
|
}) {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -26,11 +27,12 @@ function Customer({
|
|||||||
requestFetchCustomers({}),
|
requestFetchCustomers({}),
|
||||||
);
|
);
|
||||||
// Handle fetch customer details.
|
// Handle fetch customer details.
|
||||||
const fetchCustomer= useQuery(['customer', id], () =>
|
const fetchCustomer = useQuery(
|
||||||
requestFetchCustomers(),
|
['customer', id],
|
||||||
{ enabled: !!id },
|
(key, customerId) => requestFetchCustomer(customerId),
|
||||||
|
{ enabled: id && id },
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleFormSubmit = useCallback(
|
const handleFormSubmit = useCallback(
|
||||||
(payload) => {
|
(payload) => {
|
||||||
payload.redirect && history.push('/customers');
|
payload.redirect && history.push('/customers');
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {
|
import {
|
||||||
fetchCustomers,
|
fetchCustomers,
|
||||||
|
fetchCustomer,
|
||||||
submitCustomer,
|
submitCustomer,
|
||||||
editCustomer,
|
editCustomer,
|
||||||
deleteCustomer,
|
deleteCustomer,
|
||||||
deleteBulkCustomers
|
deleteBulkCustomers,
|
||||||
} from 'store/customers/customers.actions';
|
} from 'store/customers/customers.actions';
|
||||||
import t from 'store/types';
|
import t from 'store/types';
|
||||||
|
|
||||||
export const mapDispatchToProps = (dispatch) => ({
|
export const mapDispatchToProps = (dispatch) => ({
|
||||||
requestFetchCustomers: (query) => dispatch(fetchCustomers({ query })),
|
requestFetchCustomers: (query) => dispatch(fetchCustomers({ query })),
|
||||||
requestDeleteCustomer: (id) => dispatch(deleteCustomer({ id })),
|
requestDeleteCustomer: (id) => dispatch(deleteCustomer({ id })),
|
||||||
requestDeleteBulkCustomers:(ids)=>dispatch(deleteBulkCustomers({ids})),
|
requestDeleteBulkCustomers: (ids) => dispatch(deleteBulkCustomers({ ids })),
|
||||||
requestSubmitCustomer: (form) => dispatch(submitCustomer({ form })),
|
requestSubmitCustomer: (form) => dispatch(submitCustomer({ form })),
|
||||||
requestEditCustomer: (id, form) => dispatch(editCustomer({ id, form })),
|
requestEditCustomer: (id, form) => dispatch(editCustomer({ id, form })),
|
||||||
|
requestFetchCustomer: (id) => dispatch(fetchCustomer({ id })),
|
||||||
addCustomersTableQueries: (queries) =>
|
addCustomersTableQueries: (queries) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.CUSTOMERS_TABLE_QUERIES_ADD,
|
type: t.CUSTOMERS_TABLE_QUERIES_ADD,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { resolve } from 'p-progress';
|
||||||
import ApiService from 'services/ApiService';
|
import ApiService from 'services/ApiService';
|
||||||
import t from 'store/types';
|
import t from 'store/types';
|
||||||
|
|
||||||
@@ -52,10 +53,9 @@ export const fetchCustomers = ({ query }) => {
|
|||||||
ApiService.get(`customers`, { params: { ...pageQuery, ...query } })
|
ApiService.get(`customers`, { params: { ...pageQuery, ...query } })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.CUSTOMER_SET,
|
type: t.CUSTOMERS_ITEMS_SET,
|
||||||
customers: response.data.customers,
|
customers: response.data.customers,
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.CUSTOMERS_PAGE_SET,
|
type: t.CUSTOMERS_PAGE_SET,
|
||||||
customers: response.data.customers,
|
customers: response.data.customers,
|
||||||
@@ -74,6 +74,26 @@ export const fetchCustomers = ({ query }) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchCustomer = ({ id }) => {
|
||||||
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
ApiService.get(`customers/${id}`)
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.CUSTOMER_SET,
|
||||||
|
payload: {
|
||||||
|
id,
|
||||||
|
customer: response.data.contact,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const deleteCustomer = ({ id }) => {
|
export const deleteCustomer = ({ id }) => {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const initialState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const customersReducer = createReducer(initialState, {
|
const customersReducer = createReducer(initialState, {
|
||||||
[t.CUSTOMER_SET]: (state, action) => {
|
[t.CUSTOMERS_ITEMS_SET]: (state, action) => {
|
||||||
const _customers = {};
|
const _customers = {};
|
||||||
|
|
||||||
action.customers.forEach((customer) => {
|
action.customers.forEach((customer) => {
|
||||||
@@ -51,6 +51,10 @@ const customersReducer = createReducer(initialState, {
|
|||||||
});
|
});
|
||||||
state.items = items;
|
state.items = items;
|
||||||
},
|
},
|
||||||
|
[t.CUSTOMER_SET]: (state, action) => {
|
||||||
|
const { id, customer } = action.payload;
|
||||||
|
state.items[id] = { ...customer };
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default createTableQueryReducers('customers', customersReducer);
|
export default createTableQueryReducers('customers', customersReducer);
|
||||||
|
|||||||
@@ -55,8 +55,12 @@ export const fetchItem = ({ id }) => {
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ITEM_SET,
|
type: t.ITEM_SET,
|
||||||
item: response.data.item,
|
payload: {
|
||||||
|
id,
|
||||||
|
item: response.data.item,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
resolve(response);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ const itemsReducer = createReducer(initialState, {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[t.ITEM_SET]: (state, action) => {
|
||||||
|
const { id, item } = action.payload;
|
||||||
|
state.items[id] = { ...item };
|
||||||
|
},
|
||||||
|
|
||||||
[t.ITEMS_PAGE_SET]: (state, action) => {
|
[t.ITEMS_PAGE_SET]: (state, action) => {
|
||||||
const { items, customViewId, paginationMeta } = action;
|
const { items, customViewId, paginationMeta } = action;
|
||||||
|
|
||||||
@@ -42,10 +47,10 @@ const itemsReducer = createReducer(initialState, {
|
|||||||
state.itemsRelation[item.id] = [];
|
state.itemsRelation[item.id] = [];
|
||||||
}
|
}
|
||||||
const filteredRelation = state.itemsRelation[item.id].filter(
|
const filteredRelation = state.itemsRelation[item.id].filter(
|
||||||
(relation) => (
|
(relation) =>
|
||||||
relation.viewId === viewId &&
|
relation.viewId === viewId &&
|
||||||
relation.pageNumber === paginationMeta.page
|
relation.pageNumber === paginationMeta.page,
|
||||||
));
|
);
|
||||||
|
|
||||||
filteredRelation.push({
|
filteredRelation.push({
|
||||||
viewId,
|
viewId,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
ITEMS_SET: 'ITEMS_SET',
|
ITEMS_SET: 'ITEMS_SET',
|
||||||
|
ITEM_SET: 'ITEM_SET',
|
||||||
ITEMS_PAGE_SET: 'ITEMS_PAGE_SET',
|
ITEMS_PAGE_SET: 'ITEMS_PAGE_SET',
|
||||||
ITEM_DELETE: 'ITEM_DELETE',
|
ITEM_DELETE: 'ITEM_DELETE',
|
||||||
ITEM_BULK_ACTION_ADD: 'ITEM_BULK_ACTION_ADD',
|
ITEM_BULK_ACTION_ADD: 'ITEM_BULK_ACTION_ADD',
|
||||||
@@ -12,6 +11,5 @@ export default {
|
|||||||
|
|
||||||
ITEMS_TABLE_LOADING: 'ITEMS_TABLE_LOADING',
|
ITEMS_TABLE_LOADING: 'ITEMS_TABLE_LOADING',
|
||||||
ITEMS_SET_CURRENT_VIEW: 'ITEMS_SET_CURRENT_VIEW',
|
ITEMS_SET_CURRENT_VIEW: 'ITEMS_SET_CURRENT_VIEW',
|
||||||
ITEMS_BULK_DELETE:'ITEMS_BULK_DELETE'
|
ITEMS_BULK_DELETE: 'ITEMS_BULK_DELETE',
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user