Skip to content

Commit

Permalink
provide setCurrency function on stripes (#687)
Browse files Browse the repository at this point in the history
* provide setCurrency function on stripes

Refs UIU-1040
  • Loading branch information
zburke committed Jun 6, 2019
1 parent d3313db commit d026639
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

* Allow modules to be ingested by stripes-core as more than one type -- the `type` property of the `stripes` section is now replaced by `actsAs` which can be a module type string or an array of them. Also removes redundant copies of the icons, Okapi interfaces, and permissions in the `modules.<type>` structure exposed by the `ModulesContext` as they are kept elsewhere. (STCOR-148)
* New settings icon.
* Provide `setCurrency` on the stripes object, à la `setLocale` and `setTimezone`. Refs UIU-1040.

## [3.5.1](https://github.com/folio-org/stripes-core/tree/v3.5.1) (2019-05-13)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v3.5.0...v3.5.1)
Expand Down
2 changes: 2 additions & 0 deletions src/Stripes.js
Expand Up @@ -52,9 +52,11 @@ export const stripesShape = PropTypes.shape({
).isRequired,
locale: PropTypes.string,
timezone: PropTypes.string,
currency: PropTypes.string,
metadata: PropTypes.object,
setLocale: PropTypes.func.isRequired,
setTimezone: PropTypes.func.isRequired,
setCurrency: PropTypes.func.isRequired,
plugins: PropTypes.object,
setSinglePlugin: PropTypes.func.isRequired,
bindings: PropTypes.object,
Expand Down
10 changes: 8 additions & 2 deletions src/components/Root/Root.js
Expand Up @@ -17,7 +17,7 @@ import { ConnectContext } from '@folio/stripes-connect';
import initialReducers from '../../initialReducers';
import enhanceReducer from '../../enhanceReducer';
import createApolloClient from '../../createApolloClient';
import { setSinglePlugin, setBindings, setOkapiToken, setTimezone } from '../../okapiActions';
import { setSinglePlugin, setBindings, setOkapiToken, setTimezone, setCurrency } from '../../okapiActions';
import { loadTranslations, checkOkapiSession } from '../../loginServices';
import { getQueryResourceKey, getCurrentModule } from '../../locationService';
import Stripes from '../../Stripes';
Expand Down Expand Up @@ -86,7 +86,7 @@ class Root extends Component {
}

render() {
const { logger, store, epics, config, okapi, actionNames, token, disableAuth, currentUser, currentPerms, locale, defaultTranslations, timezone, plugins, bindings, discovery, translations, history, serverDown } = this.props;
const { logger, store, epics, config, okapi, actionNames, token, disableAuth, currentUser, currentPerms, locale, defaultTranslations, timezone, currency, plugins, bindings, discovery, translations, history, serverDown } = this.props;

if (serverDown) {
return <div>Error: server is down.</div>;
Expand All @@ -108,9 +108,11 @@ class Root extends Component {
actionNames,
locale,
timezone,
currency,
metadata,
setLocale: (localeValue) => { loadTranslations(store, localeValue, defaultTranslations); },
setTimezone: (timezoneValue) => { store.dispatch(setTimezone(timezoneValue)); },
setCurrency: (currencyValue) => { store.dispatch(setCurrency(currencyValue)); },
plugins: plugins || {},
setSinglePlugin: (key, value) => { store.dispatch(setSinglePlugin(key, value)); },
bindings,
Expand All @@ -131,6 +133,7 @@ class Root extends Component {
locale={locale}
key={locale}
timeZone={timezone}
currency={currency}
messages={translations}
textComponent={Fragment}
>
Expand Down Expand Up @@ -169,6 +172,7 @@ Root.propTypes = {
locale: PropTypes.string,
defaultTranslations: PropTypes.object,
timezone: PropTypes.string,
currency: PropTypes.string,
translations: PropTypes.object,
modules: PropTypes.shape({
app: PropTypes.array,
Expand Down Expand Up @@ -204,6 +208,7 @@ Root.defaultProps = {
// TODO: remove after locale is accessible from a global config / public url
locale: 'en-US',
timezone: 'UTC',
currency: 'USD',
okapiReady: false,
serverDown: false,
};
Expand All @@ -215,6 +220,7 @@ function mapStateToProps(state) {
currentPerms: state.okapi.currentPerms,
locale: state.okapi.locale,
timezone: state.okapi.timezone,
currency: state.okapi.currency,
translations: state.okapi.translations,
plugins: state.okapi.plugins,
bindings: state.okapi.bindings,
Expand Down
4 changes: 3 additions & 1 deletion src/loginServices.js
Expand Up @@ -11,6 +11,7 @@ import {
setCurrentPerms,
setLocale,
setTimezone,
setCurrency,
setPlugins,
setBindings,
setTranslations,
Expand Down Expand Up @@ -71,11 +72,12 @@ export function getLocale(okapiUrl, store, tenant) {
response.json().then((json) => {
if (json.configs.length) {
const localeValues = JSON.parse(json.configs[0].value);
const { locale, timezone } = localeValues;
const { locale, timezone, currency } = localeValues;
if (locale) {
loadTranslations(store, locale);
}
if (timezone) store.dispatch(setTimezone(timezone));
if (currency) store.dispatch(setCurrency(currency));
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions src/okapiActions.js
Expand Up @@ -32,6 +32,13 @@ function setTimezone(timezone) {
};
}

function setCurrency(currency) {
return {
type: 'SET_CURRENCY',
currency,
};
}

function setPlugins(plugins) {
return {
type: 'SET_PLUGINS',
Expand Down Expand Up @@ -127,6 +134,7 @@ export {
setCurrentPerms,
setLocale,
setTimezone,
setCurrency,
setPlugins,
setSinglePlugin,
setBindings,
Expand Down
2 changes: 2 additions & 0 deletions src/okapiReducer.js
Expand Up @@ -12,6 +12,8 @@ export default function okapiReducer(state = {}, action) {
return Object.assign({}, state, { locale: action.locale });
case 'SET_TIMEZONE':
return Object.assign({}, state, { timezone: action.timezone });
case 'SET_CURRENCY':
return Object.assign({}, state, { currency: action.currency });
case 'SET_PLUGINS':
return Object.assign({}, state, { plugins: action.plugins });
case 'SET_SINGLE_PLUGIN':
Expand Down

0 comments on commit d026639

Please sign in to comment.