35 lines
800 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 {
2020-05-24 02:08:24 +03:00
Popup: React.ElementType;
props?: Record<string, any>;
// Don't allow hiding popup
disableOverlayClose?: boolean;
2019-12-07 13:28:52 +02:00
}
export type State = {
2020-05-24 02:08:24 +03:00
popups: Array<PopupConfig>;
2019-12-07 13:28:52 +02:00
};
export default combineReducers<State>({
2020-05-24 02:08:24 +03:00
popups,
2019-12-07 13:28:52 +02:00
});
function popups(state: Array<PopupConfig> = [], { type, payload }: Action) {
2020-05-24 02:08:24 +03:00
switch (type) {
case 'POPUP_CREATE':
if (!payload.Popup) {
throw new Error('Popup is required');
}
2019-12-07 13:28:52 +02:00
2020-05-24 02:08:24 +03:00
return state.concat(payload);
case 'POPUP_DESTROY':
return state.filter((popup) => popup !== payload);
default:
return state;
}
2019-12-07 13:28:52 +02:00
}