2020-06-30 20:19:50 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2020-06-30 20:19:50 +03:00
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2020-06-30 20:19:50 +03:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2020-06-30 20:19:50 +03:00
|
|
|
import Textarea from 'react-textarea-autosize';
|
|
|
|
|
2023-05-28 17:38:10 +03:00
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
|
|
|
|
2020-06-30 20:19:50 +03:00
|
|
|
const messages = defineMessages({
|
2020-07-07 18:42:35 +03:00
|
|
|
placeholder: { id: 'account_note.glitch_placeholder', defaultMessage: 'No comment provided' },
|
2020-06-30 20:19:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
class Header extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
|
|
|
isEditing: PropTypes.bool,
|
|
|
|
isSubmitting: PropTypes.bool,
|
|
|
|
accountNote: PropTypes.string,
|
|
|
|
onEditAccountNote: PropTypes.func.isRequired,
|
|
|
|
onCancelAccountNote: PropTypes.func.isRequired,
|
|
|
|
onSaveAccountNote: PropTypes.func.isRequired,
|
|
|
|
onChangeAccountNote: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleChangeAccountNote = (e) => {
|
|
|
|
this.props.onChangeAccountNote(e.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
if (this.props.isEditing) {
|
|
|
|
this.props.onCancelAccountNote();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleKeyDown = e => {
|
|
|
|
if (e.keyCode === 13 && (e.ctrlKey || e.metaKey)) {
|
|
|
|
this.props.onSaveAccountNote();
|
|
|
|
} else if (e.keyCode === 27) {
|
|
|
|
this.props.onCancelAccountNote();
|
|
|
|
}
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2020-06-30 20:19:50 +03:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { account, accountNote, isEditing, isSubmitting, intl } = this.props;
|
|
|
|
|
|
|
|
if (!account || (!accountNote && !isEditing)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let action_buttons = null;
|
|
|
|
if (isEditing) {
|
|
|
|
action_buttons = (
|
|
|
|
<div className='account__header__account-note__buttons'>
|
2023-04-04 17:33:44 +03:00
|
|
|
<button className='icon-button' tabIndex={0} onClick={this.props.onCancelAccountNote} disabled={isSubmitting}>
|
2020-06-30 20:19:50 +03:00
|
|
|
<Icon id='times' size={15} /> <FormattedMessage id='account_note.cancel' defaultMessage='Cancel' />
|
|
|
|
</button>
|
|
|
|
<div className='flex-spacer' />
|
2023-04-04 17:33:44 +03:00
|
|
|
<button className='icon-button' tabIndex={0} onClick={this.props.onSaveAccountNote} disabled={isSubmitting}>
|
2020-06-30 20:19:50 +03:00
|
|
|
<Icon id='check' size={15} /> <FormattedMessage id='account_note.save' defaultMessage='Save' />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
2020-07-07 18:47:33 +03:00
|
|
|
} else {
|
|
|
|
action_buttons = (
|
|
|
|
<div className='account__header__account-note__buttons'>
|
2023-04-04 17:33:44 +03:00
|
|
|
<button className='icon-button' tabIndex={0} onClick={this.props.onEditAccountNote} disabled={isSubmitting}>
|
2020-07-07 18:47:33 +03:00
|
|
|
<Icon id='pencil' size={15} /> <FormattedMessage id='account_note.edit' defaultMessage='Edit' />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
2020-06-30 20:19:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let note_container = null;
|
|
|
|
if (isEditing) {
|
|
|
|
note_container = (
|
|
|
|
<Textarea
|
|
|
|
className='account__header__account-note__content'
|
|
|
|
disabled={isSubmitting}
|
|
|
|
placeholder={intl.formatMessage(messages.placeholder)}
|
|
|
|
value={accountNote}
|
|
|
|
onChange={this.handleChangeAccountNote}
|
|
|
|
onKeyDown={this.handleKeyDown}
|
|
|
|
autoFocus
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
note_container = (<div className='account__header__account-note__content'>{accountNote}</div>);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='account__header__account-note'>
|
|
|
|
<div className='account__header__account-note__header'>
|
2020-07-07 18:47:33 +03:00
|
|
|
<strong><FormattedMessage id='account.account_note_header' defaultMessage='Note' /></strong>
|
|
|
|
{action_buttons}
|
2020-06-30 20:19:50 +03:00
|
|
|
</div>
|
|
|
|
{note_container}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-25 00:15:25 +02:00
|
|
|
|
|
|
|
export default injectIntl(Header);
|