mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
WIP / exchangeRate / localize
This commit is contained in:
57
client/src/store/ExchangeRate/exchange.actions.js
Normal file
57
client/src/store/ExchangeRate/exchange.actions.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const fetchExchangeRates = () => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||
});
|
||||
ApiService.get('exchange_rates')
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.EXCHANGE_RATE_LIST_SET,
|
||||
exchange_rates: response.data.exchange_rates.results,
|
||||
});
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const submitExchangeRate = ({ form }) => {
|
||||
return (dispatch) => {
|
||||
return ApiService.post('exchange_rates', form);
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteExchangeRate = (id) => {
|
||||
return (dispatch) => ApiService.delete(`exchange_rates/${id}`);
|
||||
};
|
||||
|
||||
export const editExchangeRate = (id, form) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post(`exchange_rates/${id}`, form)
|
||||
.then((response) => {
|
||||
dispatch({ type: t.CLEAR_EXCHANGE_RATE_FORM_ERRORS });
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
const { errors } = data;
|
||||
|
||||
dispatch({ type: t.CLEAR_EXCHANGE_RATE_FORM_ERRORS });
|
||||
if (errors) {
|
||||
dispatch({ type: t.CLEAR_EXCHANGE_RATE_FORM_ERRORS, errors });
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
20
client/src/store/ExchangeRate/exchange.reducer.js
Normal file
20
client/src/store/ExchangeRate/exchange.reducer.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
exchangeRates: {},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.EXCHANGE_RATE_LIST_SET]: (state, action) => {
|
||||
const _exchangeRates = {};
|
||||
action.exchange_rates.forEach((exchange_rate) => {
|
||||
_exchangeRates[exchange_rate.id] = exchange_rate;
|
||||
});
|
||||
|
||||
state.exchangeRates = {
|
||||
...state.exchangeRates,
|
||||
..._exchangeRates,
|
||||
};
|
||||
},
|
||||
});
|
||||
7
client/src/store/ExchangeRate/exchange.type.js
Normal file
7
client/src/store/ExchangeRate/exchange.type.js
Normal file
@@ -0,0 +1,7 @@
|
||||
export default {
|
||||
EXCHANGE_RATE_DATA_TABLE: 'EXCHANGE_RATE_DATA_TABLE',
|
||||
EXCHANGE_RATE_DELETE: 'EXCHANGE_RATE_DELETE',
|
||||
EXCHANGE_RATE_LIST_SET: 'EXCHANGE_RATE_LIST_SET',
|
||||
CLEAR_EXCHANGE_RATE_FORM_ERRORS: 'CLEAR_EXCHANGE_RATE_FORM_ERRORS',
|
||||
ExchangeRates_TABLE_QUERIES_ADD: 'ExchangeRates_TABLE_QUERIES_ADD',
|
||||
};
|
||||
Reference in New Issue
Block a user