From 22ac80d98fa711d42b57346fe8aa88061dd58960 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 12 Dec 2016 00:38:38 +0100 Subject: [PATCH] Add store for AddAddress (#3819) * WIP * Updated tests * Final round of fixes * Header update --- js/src/modals/AddAddress/addAddress.js | 158 ++++++++++---------- js/src/modals/AddAddress/addAddress.spec.js | 32 ++++ js/src/modals/AddAddress/store.js | 87 +++++++++++ js/src/modals/AddAddress/store.spec.js | 128 ++++++++++++++++ js/src/modals/AddAddress/store.test.js | 28 ++++ js/src/ui/Form/Input/input.js | 55 ++++--- js/src/ui/Form/InputAddress/inputAddress.js | 45 +++--- js/src/ui/Modal/modal.js | 21 ++- js/test/mocha.config.js | 4 +- 9 files changed, 423 insertions(+), 135 deletions(-) create mode 100644 js/src/modals/AddAddress/addAddress.spec.js create mode 100644 js/src/modals/AddAddress/store.js create mode 100644 js/src/modals/AddAddress/store.spec.js create mode 100644 js/src/modals/AddAddress/store.test.js diff --git a/js/src/modals/AddAddress/addAddress.js b/js/src/modals/AddAddress/addAddress.js index 177223290..437b87663 100644 --- a/js/src/modals/AddAddress/addAddress.js +++ b/js/src/modals/AddAddress/addAddress.js @@ -14,31 +14,29 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -import React, { Component, PropTypes } from 'react'; import ContentAdd from 'material-ui/svg-icons/content/add'; import ContentClear from 'material-ui/svg-icons/content/clear'; +import { observer } from 'mobx-react'; +import React, { Component, PropTypes } from 'react'; +import { FormattedMessage } from 'react-intl'; -import { Button, Modal, Form, Input, InputAddress } from '~/ui'; -import { ERRORS, validateAddress, validateName } from '~/util/validation'; +import { Button, Form, Input, InputAddress, Modal } from '~/ui'; +import Store from './store'; + +@observer export default class AddAddress extends Component { static contextTypes = { api: PropTypes.object.isRequired } static propTypes = { - contacts: PropTypes.object.isRequired, address: PropTypes.string, - onClose: PropTypes.func + contacts: PropTypes.object.isRequired, + onClose: PropTypes.func.isRequired }; - state = { - address: '', - addressError: ERRORS.invalidAddress, - name: '', - nameError: ERRORS.invalidName, - description: '' - }; + store = new Store(this.context.api, this.props.contacts); componentWillMount () { if (this.props.address) { @@ -49,109 +47,113 @@ export default class AddAddress extends Component { render () { return ( + title={ + + } + visible> { this.renderFields() } ); } renderDialogActions () { - const { addressError, nameError } = this.state; - const hasError = !!(addressError || nameError); + const { hasError } = this.store; return ([