dispatch/client/js/state/modals.js

48 lines
888 B
JavaScript
Raw Normal View History

import { createSelector } from 'reselect';
import createReducer from 'utils/createReducer';
import * as actions from './actions';
export const getModals = state => state.modals;
2020-04-30 05:54:30 +00:00
export const getHasOpenModals = createSelector(getModals, modals => {
const keys = Object.keys(modals);
2020-04-30 05:54:30 +00:00
for (let i = 0; i < keys.length; i++) {
if (modals[keys[i]].isOpen) {
return true;
}
}
2020-04-30 05:54:30 +00:00
return false;
});
export default createReducer(
{},
{
[actions.OPEN_MODAL](state, { name, payload = {} }) {
state[name] = {
isOpen: true,
payload
};
},
[actions.CLOSE_MODAL](state, { name }) {
state[name].isOpen = false;
}
}
);
export function openModal(name, payload) {
return {
type: actions.OPEN_MODAL,
name,
payload
};
}
export function closeModal(name) {
return {
type: actions.CLOSE_MODAL,
name
};
}