2022-08-09 12:22:18 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
2017-08-07 16:20:44 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
CANCEL_FEEDBACK,
|
2019-07-31 17:59:22 +00:00
|
|
|
SUBMIT_FEEDBACK_ERROR,
|
|
|
|
SUBMIT_FEEDBACK_SUCCESS
|
2017-08-07 16:20:44 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
const DEFAULT_STATE = {
|
|
|
|
message: '',
|
|
|
|
|
|
|
|
// The sentinel value -1 is used to denote no rating has been set and to
|
|
|
|
// preserve pre-redux behavior.
|
|
|
|
score: -1,
|
|
|
|
submitted: false
|
|
|
|
};
|
|
|
|
|
2022-08-09 12:22:18 +00:00
|
|
|
export interface IFeedbackState {
|
|
|
|
message: string;
|
|
|
|
score: number;
|
|
|
|
submitted: boolean;
|
|
|
|
}
|
|
|
|
|
2017-08-07 16:20:44 +00:00
|
|
|
/**
|
|
|
|
* Reduces the Redux actions of the feature features/feedback.
|
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IFeedbackState>(
|
2017-08-07 16:20:44 +00:00
|
|
|
'features/feedback',
|
2022-09-05 09:05:07 +00:00
|
|
|
(state = DEFAULT_STATE, action): IFeedbackState => {
|
2017-08-07 16:20:44 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case CANCEL_FEEDBACK: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
message: action.message,
|
|
|
|
score: action.score
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-07-31 17:59:22 +00:00
|
|
|
case SUBMIT_FEEDBACK_ERROR:
|
|
|
|
case SUBMIT_FEEDBACK_SUCCESS: {
|
2017-08-07 16:20:44 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
message: '',
|
|
|
|
score: -1,
|
|
|
|
submitted: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|