mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10: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);
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user