about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/account/containers/account_note_container.js
blob: f1d007ecb0b2846d8b0f3f0885a789eb9ffff286 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { connect } from 'react-redux';
import { changeAccountNoteComment, submitAccountNote, initEditAccountNote, cancelAccountNote } from 'flavours/glitch/actions/account_notes';
import AccountNote from '../components/account_note';

const mapStateToProps = (state, { account }) => {
  const isEditing = state.getIn(['account_notes', 'edit', 'account_id']) === account.get('id');

  return {
    isSubmitting: state.getIn(['account_notes', 'edit', 'isSubmitting']),
    accountNote: isEditing ? state.getIn(['account_notes', 'edit', 'comment']) : account.getIn(['relationship', 'note']),
    isEditing,
  };
};

const mapDispatchToProps = (dispatch, { account }) => ({

  onEditAccountNote() {
    dispatch(initEditAccountNote(account));
  },

  onSaveAccountNote() {
    dispatch(submitAccountNote());
  },

  onCancelAccountNote() {
    dispatch(cancelAccountNote());
  },

  onChangeAccountNote(comment) {
    dispatch(changeAccountNoteComment(comment));
  },
});

export default connect(mapStateToProps, mapDispatchToProps)(AccountNote);