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.
76 lines
1.9 KiB
76 lines
1.9 KiB
4 years ago
|
import React, { Component } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import Button from '../../../ui/button/button.component';
|
||
5 years ago
|
|
||
|
export default class AddToAddressBookModal extends Component {
|
||
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
static propTypes = {
|
||
|
hideModal: PropTypes.func.isRequired,
|
||
|
addToAddressBook: PropTypes.func.isRequired,
|
||
|
recipient: PropTypes.string.isRequired,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
state = {
|
||
|
alias: '',
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
5 years ago
|
onSave = async () => {
|
||
4 years ago
|
const { recipient, addToAddressBook, hideModal } = this.props;
|
||
|
await addToAddressBook(recipient, this.state.alias);
|
||
|
hideModal();
|
||
|
};
|
||
5 years ago
|
|
||
5 years ago
|
onChange = (e) => {
|
||
5 years ago
|
this.setState({
|
||
|
alias: e.target.value,
|
||
4 years ago
|
});
|
||
|
};
|
||
5 years ago
|
|
||
5 years ago
|
onKeyPress = async (e) => {
|
||
5 years ago
|
if (e.key === 'Enter' && this.state.alias) {
|
||
4 years ago
|
this.onSave();
|
||
5 years ago
|
}
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
render() {
|
||
4 years ago
|
const { t } = this.context;
|
||
5 years ago
|
|
||
|
return (
|
||
|
<div className="add-to-address-book-modal">
|
||
|
<div className="add-to-address-book-modal__content">
|
||
|
<div className="add-to-address-book-modal__content__header">
|
||
|
{t('addToAddressBook')}
|
||
|
</div>
|
||
|
<div className="add-to-address-book-modal__input-label">
|
||
|
{t('enterAnAlias')}
|
||
|
</div>
|
||
|
<input
|
||
|
type="text"
|
||
|
className="add-to-address-book-modal__input"
|
||
|
placeholder={t('addToAddressBookModalPlaceholder')}
|
||
|
onChange={this.onChange}
|
||
|
onKeyPress={this.onKeyPress}
|
||
|
value={this.state.alias}
|
||
|
autoFocus
|
||
|
/>
|
||
|
</div>
|
||
|
<div className="add-to-address-book-modal__footer">
|
||
4 years ago
|
<Button type="secondary" onClick={this.props.hideModal}>
|
||
5 years ago
|
{t('cancel')}
|
||
|
</Button>
|
||
|
<Button
|
||
|
type="primary"
|
||
|
onClick={this.onSave}
|
||
|
disabled={!this.state.alias}
|
||
|
>
|
||
|
{t('save')}
|
||
|
</Button>
|
||
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
5 years ago
|
}
|
||
|
}
|