mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
WIP / Features / Sate
This commit is contained in:
137
client/src/store/Invoice/invoices.actions.js
Normal file
137
client/src/store/Invoice/invoices.actions.js
Normal file
@@ -0,0 +1,137 @@
|
||||
import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const submitInvoice = ({ form }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||
});
|
||||
ApiService.post('sales/invoices', form)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
|
||||
reject(data?.errors);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteInvoice = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resovle, reject) => {
|
||||
ApiService.delete(`invoice/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({ type: t.INVOICE_DELETE });
|
||||
resovle(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error.response.data.errors || []);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const editInvoice = (id, form) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||
});
|
||||
ApiService.post(`invoice/${id}`, form)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
reject(data?.errors);
|
||||
});
|
||||
});
|
||||
};
|
||||
export const fetchInvoicesTable = ({ query = {} }) => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, rejcet) => {
|
||||
const pageQuery = getState().invoices.tableQuery;
|
||||
|
||||
dispatch({
|
||||
type: t.INVOICES_TABLE_LOADING,
|
||||
payload: {
|
||||
loading: true,
|
||||
},
|
||||
});
|
||||
ApiService.get('invoices', {
|
||||
params: { ...pageQuery, ...query },
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.INVOICES_PAGE_SET,
|
||||
payload: {
|
||||
invoices: response.data.invoices.results,
|
||||
pagination: response.data.invoices.pagination,
|
||||
customViewId: response.data.customViewId || -1,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.INVOICES_ITEMS_SET,
|
||||
payload: {
|
||||
invoices: response.data.invoices.results,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.INVOICES_PAGINATION_SET,
|
||||
payload: {
|
||||
pagination: response.data.invoices.pagination,
|
||||
customViewId: response.data.customViewId || -1,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.INVOICES_TABLE_LOADING,
|
||||
payload: {
|
||||
loading: false,
|
||||
},
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
rejcet(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchInvoice = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resovle, reject) => {
|
||||
ApiService.get(`invoices/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.INVOICE_SET,
|
||||
payload: {
|
||||
id,
|
||||
invoice: response.data.invoice,
|
||||
},
|
||||
});
|
||||
resovle(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
reject(data?.errors);
|
||||
});
|
||||
});
|
||||
};
|
||||
32
client/src/store/Invoice/invoices.reducer.js
Normal file
32
client/src/store/Invoice/invoices.reducer.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { createTableQueryReducers } from 'store/queryReducers';
|
||||
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
items: {},
|
||||
views: {},
|
||||
loading: false,
|
||||
tableQuery: {
|
||||
page_size: 12,
|
||||
page: 1,
|
||||
},
|
||||
currentViewId: -1,
|
||||
};
|
||||
|
||||
const defaultInvoice = {
|
||||
entires: [],
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
const reducer = createReducer(initialState, {
|
||||
[t.INVOICE_SET]:(state,actio)=>{
|
||||
|
||||
const {id,INVOICE_SET} = action.payload;
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
9
client/src/store/Invoice/invoices.selector.js
Normal file
9
client/src/store/Invoice/invoices.selector.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
const invoiceByIdSelector = (state, props) =>
|
||||
state.invoices.items[props.invoiceId];
|
||||
|
||||
export const getInvoiceById = () =>
|
||||
createSelector(invoiceByIdSelector, (_invoice) => {
|
||||
return _invoice;
|
||||
});
|
||||
12
client/src/store/Invoice/invoices.types.js
Normal file
12
client/src/store/Invoice/invoices.types.js
Normal file
@@ -0,0 +1,12 @@
|
||||
export default {
|
||||
INVOICE_DELETE: 'INVOICE_DELETE',
|
||||
INVOICES_BULK_DELETE: 'INVOICES_BULK_DELETE',
|
||||
INVOICES_LIST_SET: 'INVOICES_LIST_SET',
|
||||
INVOICE_SET: 'INVOICE_SET',
|
||||
INVOICES_SET_CURRENT_VIEW: 'INVOICES_SET_CURRENT_VIEW',
|
||||
INVOICES_TABLE_QUERIES_ADD: 'INVOICES_TABLE_QUERIES_ADD',
|
||||
INVOICES_TABLE_LOADING: 'INVOICES_TABLE_LOADING',
|
||||
INVOICES_PAGINATION_SET: 'INVOICES_PAGINATION_SET',
|
||||
INVOICES_PAGE_SET: 'INVOICES_PAGE_SET',
|
||||
INVOICES_ITEMS_SET: 'INVOICES_ITEMS_SET',
|
||||
};
|
||||
Reference in New Issue
Block a user