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.

70 lines
1.8 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import { changeListEditorTitle, submitListEditor } from '../../../actions/lists';
  5. import IconButton from '../../../components/icon_button';
  6. import { defineMessages, injectIntl } from 'react-intl';
  7. const messages = defineMessages({
  8. title: { id: 'lists.edit.submit', defaultMessage: 'Change title' },
  9. });
  10. const mapStateToProps = state => ({
  11. value: state.getIn(['listEditor', 'title']),
  12. disabled: !state.getIn(['listEditor', 'isChanged']) || !state.getIn(['listEditor', 'title']),
  13. });
  14. const mapDispatchToProps = dispatch => ({
  15. onChange: value => dispatch(changeListEditorTitle(value)),
  16. onSubmit: () => dispatch(submitListEditor(false)),
  17. });
  18. class ListForm extends React.PureComponent {
  19. static propTypes = {
  20. value: PropTypes.string.isRequired,
  21. disabled: PropTypes.bool,
  22. intl: PropTypes.object.isRequired,
  23. onChange: PropTypes.func.isRequired,
  24. onSubmit: PropTypes.func.isRequired,
  25. };
  26. handleChange = e => {
  27. this.props.onChange(e.target.value);
  28. };
  29. handleSubmit = e => {
  30. e.preventDefault();
  31. this.props.onSubmit();
  32. };
  33. handleClick = () => {
  34. this.props.onSubmit();
  35. };
  36. render () {
  37. const { value, disabled, intl } = this.props;
  38. const title = intl.formatMessage(messages.title);
  39. return (
  40. <form className='column-inline-form' onSubmit={this.handleSubmit}>
  41. <input
  42. className='setting-text'
  43. value={value}
  44. onChange={this.handleChange}
  45. />
  46. <IconButton
  47. disabled={disabled}
  48. icon='check'
  49. title={title}
  50. onClick={this.handleClick}
  51. />
  52. </form>
  53. );
  54. }
  55. }
  56. export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(ListForm));