aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/modals/edit-account-name-modal.js
blob: edced87257902a6a03aeb951913713d48223581c (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const Component = require('react').Component
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const inherits = require('util').inherits
const connect = require('react-redux').connect
const actions = require('../../actions')
const { getSelectedAccount } = require('../../selectors')

function mapStateToProps (state) {
  return {
    selectedAccount: getSelectedAccount(state),
    identity: state.appState.modal.modalState.props.identity,
  }
}

function mapDispatchToProps (dispatch) {
  return {
    hideModal: () => {
      dispatch(actions.hideModal())
    },
    setAccountLabel: (account, label) => {
      dispatch(actions.setAccountLabel(account, label))
    },
  }
}

inherits(EditAccountNameModal, Component)
function EditAccountNameModal (props) {
  Component.call(this)

  this.state = {
    inputText: props.identity.name,
  }
}

EditAccountNameModal.contextTypes = {
  t: PropTypes.func,
}

module.exports = connect(mapStateToProps, mapDispatchToProps)(EditAccountNameModal)


EditAccountNameModal.prototype.render = function () {
  const { hideModal, setAccountLabel, identity } = this.props

  return h('div', {}, [
    h('div.flex-column.edit-account-name-modal-content', {
    }, [

      h('div.edit-account-name-modal-cancel', {
        onClick: () => {
          hideModal()
        },
      }, [
        h('i.fa.fa-times'),
      ]),

      h('div.edit-account-name-modal-title', {
      }, [this.context.t('editAccountName')]),

      h('input.edit-account-name-modal-input', {
        placeholder: identity.name,
        onChange: (event) => {
          this.setState({ inputText: event.target.value })
        },
        value: this.state.inputText,
      }, []),

      h('button.btn-clear.edit-account-name-modal-save-button.allcaps', {
        onClick: () => {
          if (this.state.inputText.length !== 0) {
            setAccountLabel(identity.address, this.state.inputText)
            hideModal()
          }
        },
        disabled: this.state.inputText.length === 0,
      }, [
        this.context.t('save'),
      ]),

    ]),
  ])
}