mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
WIP
This commit is contained in:
41
client/src/store/expenses/expenses.actions.js
Normal file
41
client/src/store/expenses/expenses.actions.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import ApiService from "services/ApiService";
|
||||
import t from 'store/types';
|
||||
|
||||
export const fetchExpensesList = ({ query }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get('expenses').then((response) => {
|
||||
dispatch({
|
||||
type: t.EXPENSES_LIST_SET,
|
||||
expenses: response.data.expenses,
|
||||
});
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchExpense = ({ id }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`expenses/${id}`).then((response) => {
|
||||
dispatch({
|
||||
type: t.EXPENSE_SET,
|
||||
expense: response.data.expense,
|
||||
});
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const submitExpense = ({ form }) => {
|
||||
return (dispatch) => ApiService.post('expenses', { ...form });
|
||||
};
|
||||
|
||||
export const editExpense = ({ form, id }) => {
|
||||
return (dispatch) => ApiService.post(`expensed/${id}`, form);
|
||||
};
|
||||
|
||||
export const deleteExpense = ({ id }) => {
|
||||
return (dispatch) => ApiService.delete(`expenses/${id}`);
|
||||
};
|
||||
|
||||
export const publishExpense = ({ id }) => {
|
||||
return (dispatch) => ApiService.post(`expenses/${id}/publish`);
|
||||
};
|
||||
|
||||
21
client/src/store/expenses/expenses.reducer.js
Normal file
21
client/src/store/expenses/expenses.reducer.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
list: [],
|
||||
detailsById: {},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.EXPENSES_LIST_SET]: (state, action) => {
|
||||
state.list = action.expenses;
|
||||
},
|
||||
|
||||
[t.EXPENSE_SET]: (state, action) => {
|
||||
state.detailsById[action.expense.id] = action.expense;
|
||||
},
|
||||
});
|
||||
|
||||
export const getExpenseById = (state, id) => {
|
||||
return state.expenses.detailsById[id];
|
||||
};
|
||||
5
client/src/store/expenses/expenses.types.js
Normal file
5
client/src/store/expenses/expenses.types.js
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
export default {
|
||||
EXPENSES_LIST_SET: 'EXPENSES_LIST_SET',
|
||||
EXPENSE_SET: 'EXPENSE_SET',
|
||||
};
|
||||
Reference in New Issue
Block a user