mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
WIP optimize connect with redux state in preferences pages.
This commit is contained in:
13
client/src/containers/Currencies/withCurrencies.js
Normal file
13
client/src/containers/Currencies/withCurrencies.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
export default (mapState) => {
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
currencies: state.currencies.data,
|
||||
currenciesList: Object.values(state.currencies.data),
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
|
||||
return connect(mapStateToProps);
|
||||
}
|
||||
17
client/src/containers/Currencies/withCurrenciesActions.js
Normal file
17
client/src/containers/Currencies/withCurrenciesActions.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
fetchCurrencies,
|
||||
submitCurrencies,
|
||||
deleteCurrency,
|
||||
editCurrency,
|
||||
} from 'store/currencies/currencies.actions';
|
||||
|
||||
|
||||
export const mapDispatchToProps = (dispatch) => ({
|
||||
requestFetchCurrencies: () => dispatch(fetchCurrencies({})),
|
||||
requestSubmitCurrencies: (form) => dispatch(submitCurrencies({ form })),
|
||||
requestEditCurrency: (id, form) => dispatch(editCurrency({ id, form })),
|
||||
requestDeleteCurrency: (currency_code) => dispatch(deleteCurrency({ currency_code })),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
16
client/src/containers/Currencies/withCurrency.js
Normal file
16
client/src/containers/Currencies/withCurrency.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
getCurrencyById,
|
||||
getCurrencyByCode,
|
||||
} from 'store/currencies/currencies.selector';
|
||||
|
||||
|
||||
const mapStateToProps = (state, props) => ({
|
||||
...(props.currencyId) ? {
|
||||
currency: getCurrencyById(state.currencies.data, props.currencyId),
|
||||
} : (props.currencyCode) ? {
|
||||
currency: getCurrencyByCode(state.currencies.data, props.currencyCode),
|
||||
} : {},
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps);
|
||||
Reference in New Issue
Block a user