35 lines
734 B
TypeScript
Raw Normal View History

2019-12-07 13:28:52 +02:00
import React from 'react';
import { combineReducers } from 'redux';
import { Action } from './actions';
2019-12-07 13:28:52 +02:00
export interface PopupConfig {
Popup: React.ElementType;
props?: Record<string, any>;
// Don't allow hiding popup
2019-12-07 13:28:52 +02:00
disableOverlayClose?: boolean;
}
export type State = {
popups: Array<PopupConfig>;
2019-12-07 13:28:52 +02:00
};
export default combineReducers<State>({
popups,
});
function popups(state: Array<PopupConfig> = [], { type, payload }: Action) {
2019-12-07 13:28:52 +02:00
switch (type) {
case 'POPUP_CREATE':
2019-12-07 13:28:52 +02:00
if (!payload.Popup) {
throw new Error('Popup is required');
}
return state.concat(payload);
case 'POPUP_DESTROY':
return state.filter((popup) => popup !== payload);
2019-12-07 13:28:52 +02:00
default:
return state;
}
}