2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Button from '../../../ui/button/button.component';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
export default class AddToAddressBookModal extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
hideModal: PropTypes.func.isRequired,
|
|
|
|
addToAddressBook: PropTypes.func.isRequired,
|
|
|
|
recipient: PropTypes.string.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
state = {
|
|
|
|
alias: '',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-04-29 06:59:49 +02:00
|
|
|
onSave = async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { recipient, addToAddressBook, hideModal } = this.props;
|
|
|
|
await addToAddressBook(recipient, this.state.alias);
|
|
|
|
hideModal();
|
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
onChange = (e) => {
|
2019-07-31 21:56:44 +02:00
|
|
|
this.setState({
|
|
|
|
alias: e.target.value,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-04-29 06:59:49 +02:00
|
|
|
onKeyPress = async (e) => {
|
2019-08-02 14:54:45 +02:00
|
|
|
if (e.key === 'Enter' && this.state.alias) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.onSave();
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
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">
|
2020-11-03 00:41:28 +01:00
|
|
|
<Button type="secondary" onClick={this.props.hideModal}>
|
2019-07-31 21:56:44 +02:00
|
|
|
{t('cancel')}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
onClick={this.onSave}
|
|
|
|
disabled={!this.state.alias}
|
|
|
|
>
|
|
|
|
{t('save')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
}
|