2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-11-11 15:00:04 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
2017-03-02 13:29:32 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-11-11 15:00:04 +01:00
|
|
|
|
2017-05-09 12:01:44 +02:00
|
|
|
import { ERRORS, validateName } from '@parity/shared/util/validation';
|
2017-05-12 12:06:16 +02:00
|
|
|
import { Button, Form, Input, Portal } from '@parity/ui';
|
|
|
|
import Editor from '@parity/ui/Editor';
|
|
|
|
import { CancelIcon, SaveIcon } from '@parity/ui/Icons';
|
2016-11-11 15:00:04 +01:00
|
|
|
|
|
|
|
import styles from './saveContract.css';
|
|
|
|
|
|
|
|
export default class SaveContract extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
sourcecode: PropTypes.string.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onSave: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
name: '',
|
|
|
|
nameError: ERRORS.invalidName
|
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { sourcecode } = this.props;
|
|
|
|
const { name, nameError } = this.state;
|
|
|
|
|
|
|
|
return (
|
2017-02-22 15:26:58 +01:00
|
|
|
<Portal
|
|
|
|
buttons={ this.renderDialogActions() }
|
|
|
|
onClose={ this.onClose }
|
|
|
|
open
|
2017-03-02 13:29:32 +01:00
|
|
|
title={
|
|
|
|
<FormattedMessage
|
|
|
|
id='saveContract.title'
|
|
|
|
defaultMessage='save contract'
|
|
|
|
/>
|
|
|
|
}
|
2016-11-11 15:00:04 +01:00
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<Form>
|
|
|
|
<Input
|
2017-03-02 13:29:32 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='saveContract.name.label'
|
|
|
|
defaultMessage='contract name'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='saveContract.name.hint'
|
|
|
|
defaultMessage='choose a name for this contract'
|
|
|
|
/>
|
|
|
|
}
|
2016-11-11 15:00:04 +01:00
|
|
|
value={ name }
|
|
|
|
error={ nameError }
|
|
|
|
onChange={ this.onChangeName }
|
|
|
|
/>
|
|
|
|
</Form>
|
|
|
|
<Editor
|
|
|
|
className={ styles.source }
|
|
|
|
value={ sourcecode }
|
2017-02-22 15:26:58 +01:00
|
|
|
maxLines={ 25 }
|
2016-11-11 15:00:04 +01:00
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
</div>
|
2017-02-22 15:26:58 +01:00
|
|
|
</Portal>
|
2016-11-11 15:00:04 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDialogActions () {
|
|
|
|
const cancelBtn = (
|
|
|
|
<Button
|
2017-03-02 13:29:32 +01:00
|
|
|
icon={ <CancelIcon /> }
|
2017-02-22 15:26:58 +01:00
|
|
|
key='cancel'
|
2017-03-02 13:29:32 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='saveContract.buttons.cancel'
|
|
|
|
defaultMessage='Cancel'
|
|
|
|
/>
|
|
|
|
}
|
2016-11-11 15:00:04 +01:00
|
|
|
onClick={ this.onClose }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const confirmBtn = (
|
|
|
|
<Button
|
|
|
|
icon={ <SaveIcon /> }
|
2017-02-22 15:26:58 +01:00
|
|
|
key='save'
|
2017-03-02 13:29:32 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='saveContract.buttons.save'
|
|
|
|
defaultMessage='Save'
|
|
|
|
/>
|
|
|
|
}
|
2016-11-11 15:00:04 +01:00
|
|
|
disabled={ !!this.state.nameError }
|
|
|
|
onClick={ this.onSave }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
return [ cancelBtn, confirmBtn ];
|
|
|
|
}
|
|
|
|
|
|
|
|
onClose = () => {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
onSave = () => {
|
|
|
|
const { name } = this.state;
|
|
|
|
const { sourcecode } = this.props;
|
|
|
|
|
|
|
|
this.props.onSave({ name, sourcecode });
|
|
|
|
this.onClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeName = (event, value) => {
|
|
|
|
const { name, nameError } = validateName(value);
|
2017-01-23 13:39:52 +01:00
|
|
|
|
2016-11-11 15:00:04 +01:00
|
|
|
this.setState({ name, nameError });
|
|
|
|
}
|
|
|
|
}
|