You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.ts 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import {
  3. CANCEL_FEEDBACK,
  4. SUBMIT_FEEDBACK_ERROR,
  5. SUBMIT_FEEDBACK_SUCCESS
  6. } from './actionTypes';
  7. const DEFAULT_STATE = {
  8. message: '',
  9. // The sentinel value -1 is used to denote no rating has been set and to
  10. // preserve pre-redux behavior.
  11. score: -1,
  12. submitted: false
  13. };
  14. export interface IFeedbackState {
  15. message: string;
  16. score: number;
  17. submitted: boolean;
  18. }
  19. /**
  20. * Reduces the Redux actions of the feature features/feedback.
  21. */
  22. ReducerRegistry.register<IFeedbackState>(
  23. 'features/feedback',
  24. (state = DEFAULT_STATE, action): IFeedbackState => {
  25. switch (action.type) {
  26. case CANCEL_FEEDBACK: {
  27. return {
  28. ...state,
  29. message: action.message,
  30. score: action.score
  31. };
  32. }
  33. case SUBMIT_FEEDBACK_ERROR:
  34. case SUBMIT_FEEDBACK_SUCCESS: {
  35. return {
  36. ...state,
  37. message: '',
  38. score: -1,
  39. submitted: true
  40. };
  41. }
  42. }
  43. return state;
  44. });