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.

44 lines
1.3 KiB

  1. import { Map as ImmutableMap } from 'immutable';
  2. import {
  3. ACCOUNT_NOTE_INIT_EDIT,
  4. ACCOUNT_NOTE_CANCEL,
  5. ACCOUNT_NOTE_CHANGE_COMMENT,
  6. ACCOUNT_NOTE_SUBMIT_REQUEST,
  7. ACCOUNT_NOTE_SUBMIT_FAIL,
  8. ACCOUNT_NOTE_SUBMIT_SUCCESS,
  9. } from '../actions/account_notes';
  10. const initialState = ImmutableMap({
  11. edit: ImmutableMap({
  12. isSubmitting: false,
  13. account_id: null,
  14. comment: null,
  15. }),
  16. });
  17. export default function account_notes(state = initialState, action) {
  18. switch (action.type) {
  19. case ACCOUNT_NOTE_INIT_EDIT:
  20. return state.withMutations((state) => {
  21. state.setIn(['edit', 'isSubmitting'], false);
  22. state.setIn(['edit', 'account_id'], action.account.get('id'));
  23. state.setIn(['edit', 'comment'], action.comment);
  24. });
  25. case ACCOUNT_NOTE_CHANGE_COMMENT:
  26. return state.setIn(['edit', 'comment'], action.comment);
  27. case ACCOUNT_NOTE_SUBMIT_REQUEST:
  28. return state.setIn(['edit', 'isSubmitting'], true);
  29. case ACCOUNT_NOTE_SUBMIT_FAIL:
  30. return state.setIn(['edit', 'isSubmitting'], false);
  31. case ACCOUNT_NOTE_SUBMIT_SUCCESS:
  32. case ACCOUNT_NOTE_CANCEL:
  33. return state.withMutations((state) => {
  34. state.setIn(['edit', 'isSubmitting'], false);
  35. state.setIn(['edit', 'account_id'], null);
  36. state.setIn(['edit', 'comment'], null);
  37. });
  38. default:
  39. return state;
  40. }
  41. }