mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
WIP feature/Currencies
This commit is contained in:
@@ -1,26 +1,51 @@
|
||||
import ApiService from "services/ApiService";
|
||||
import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const fetchCurrencies = () => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`currencies/registered`).then((response) => {
|
||||
dispatch({
|
||||
type: t.CURRENCIES_REGISTERED_SET,
|
||||
currencies: response.data.currencies,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
export const submitCurrencies = ({ form }) => {
|
||||
return (dispatch) => {
|
||||
return ApiService.post('currencies', form);
|
||||
};
|
||||
};
|
||||
|
||||
export const fetchAllCurrencies = () => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`currencies/all`).then((response) => {
|
||||
dispatch({
|
||||
type: t.CURRENCIES_ALL_SET,
|
||||
currencies: response.data.currencies,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
};
|
||||
export const deleteCurrency = ({ currency_code }) => {
|
||||
return (dispatch) => ApiService.delete(`currencies/${currency_code}`);
|
||||
};
|
||||
|
||||
export const editCurrency = ({ id, form }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post(`currencies/${id}`, form)
|
||||
.then((response) => {
|
||||
dispatch({ type: t.CLEAR_CURRENCY_FORM_ERRORS });
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
const { errors } = data;
|
||||
|
||||
dispatch({ type: t.CLEAR_CURRENCY_FORM_ERRORS });
|
||||
if (errors) {
|
||||
dispatch({ type: t.CLEAR_CURRENCY_FORM_ERRORS, errors });
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchCurrencies = () => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.get('currencies')
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.CURRENCIES_REGISTERED_SET,
|
||||
currencies: response.data.currencies,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
import {createReducer} from '@reduxjs/toolkit'
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
all: [],
|
||||
registered: [],
|
||||
preferences: {
|
||||
currencies: [],
|
||||
},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.CURRENCIES_REGISTERED_SET]: (state, action) => {
|
||||
state.registered = action.currencies;
|
||||
},
|
||||
const _currencies = {};
|
||||
|
||||
[t.CURRENCIES_ALL_SET]: (state, action) => {
|
||||
state.all = action.currencies;
|
||||
action.currencies.forEach((currency) => {
|
||||
_currencies[currency.currency_code] = currency;
|
||||
});
|
||||
state.preferences.currencies = {
|
||||
...state.preferences.currencies,
|
||||
..._currencies,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
3
client/src/store/currencies/currencies.selector.js
Normal file
3
client/src/store/currencies/currencies.selector.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export const getCurrencyById = (items, id) => {
|
||||
return items[id] || null;
|
||||
};
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
export default {
|
||||
CURRENCIES_REGISTERED_SET: 'CURRENCIES_REGISTERED_SET',
|
||||
CURRENCIES_ALL_SET: 'CURRENCIES_ALL_SET',
|
||||
};
|
||||
CLEAR_CURRENCY_FORM_ERRORS: 'CLEAR_CURRENCY_FORM_ERRORS',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user