2022-07-14 09:38:09 +00:00
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
|
|
|
import { assign } from '../redux/functions';
|
2017-03-07 03:34:51 +00:00
|
|
|
|
2022-06-20 14:53:19 +00:00
|
|
|
import {
|
|
|
|
HIDE_DIALOG,
|
|
|
|
HIDE_SHEET,
|
|
|
|
OPEN_DIALOG,
|
|
|
|
OPEN_SHEET
|
|
|
|
} from './actionTypes';
|
2017-03-07 03:34:51 +00:00
|
|
|
|
2022-07-14 09:38:09 +00:00
|
|
|
export interface IDialogState {
|
|
|
|
component?: Object;
|
|
|
|
componentProps?: Object;
|
|
|
|
sheet?: Object;
|
|
|
|
sheetProps?: Object;
|
|
|
|
}
|
|
|
|
|
2017-03-07 03:34:51 +00:00
|
|
|
/**
|
2017-04-22 22:57:08 +00:00
|
|
|
* Reduces redux actions which show or hide dialogs.
|
2017-03-07 03:34:51 +00:00
|
|
|
*
|
2022-07-14 09:38:09 +00:00
|
|
|
* @param {IDialogState} state - The current redux state.
|
2017-04-22 22:57:08 +00:00
|
|
|
* @param {Action} action - The redux action to reduce.
|
|
|
|
* @param {string} action.type - The type of the redux action to reduce..
|
|
|
|
* @returns {State} The next redux state that is the result of reducing the
|
|
|
|
* specified action.
|
2017-03-07 03:34:51 +00:00
|
|
|
*/
|
2022-07-14 09:38:09 +00:00
|
|
|
ReducerRegistry.register('features/base/dialog', (state: IDialogState = {}, action) => {
|
2017-03-07 03:34:51 +00:00
|
|
|
switch (action.type) {
|
2017-09-18 20:52:10 +00:00
|
|
|
case HIDE_DIALOG: {
|
|
|
|
const { component } = action;
|
|
|
|
|
|
|
|
if (typeof component === 'undefined' || state.component === component) {
|
|
|
|
return assign(state, {
|
|
|
|
component: undefined,
|
2022-04-25 14:19:53 +00:00
|
|
|
componentProps: undefined
|
2017-09-18 20:52:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-04-22 22:57:08 +00:00
|
|
|
|
2017-03-07 03:34:51 +00:00
|
|
|
case OPEN_DIALOG:
|
2017-04-22 22:57:08 +00:00
|
|
|
return assign(state, {
|
2017-03-07 03:34:51 +00:00
|
|
|
component: action.component,
|
2022-04-25 14:19:53 +00:00
|
|
|
componentProps: action.componentProps
|
2017-03-07 03:34:51 +00:00
|
|
|
});
|
2022-06-20 14:53:19 +00:00
|
|
|
|
|
|
|
case HIDE_SHEET:
|
|
|
|
return assign(state, {
|
|
|
|
sheet: undefined,
|
|
|
|
sheetProps: undefined
|
|
|
|
});
|
|
|
|
|
|
|
|
case OPEN_SHEET:
|
|
|
|
return assign(state, {
|
|
|
|
sheet: action.component,
|
|
|
|
sheetProps: action.componentProps
|
|
|
|
});
|
2017-03-07 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|