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.

78 lines
2.0 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. label: { id: 'lists.new.title_placeholder', defaultMessage: 'New list title' },
  9. title: { id: 'lists.new.create', defaultMessage: 'Add list' },
  10. });
  11. const mapStateToProps = state => ({
  12. value: state.getIn(['listEditor', 'title']),
  13. disabled: state.getIn(['listEditor', 'isSubmitting']),
  14. });
  15. const mapDispatchToProps = dispatch => ({
  16. onChange: value => dispatch(changeListEditorTitle(value)),
  17. onSubmit: () => dispatch(submitListEditor(true)),
  18. });
  19. export default @connect(mapStateToProps, mapDispatchToProps)
  20. @injectIntl
  21. class NewListForm extends React.PureComponent {
  22. static propTypes = {
  23. value: PropTypes.string.isRequired,
  24. disabled: PropTypes.bool,
  25. intl: PropTypes.object.isRequired,
  26. onChange: PropTypes.func.isRequired,
  27. onSubmit: PropTypes.func.isRequired,
  28. };
  29. handleChange = e => {
  30. this.props.onChange(e.target.value);
  31. }
  32. handleSubmit = e => {
  33. e.preventDefault();
  34. this.props.onSubmit();
  35. }
  36. handleClick = () => {
  37. this.props.onSubmit();
  38. }
  39. render () {
  40. const { value, disabled, intl } = this.props;
  41. const label = intl.formatMessage(messages.label);
  42. const title = intl.formatMessage(messages.title);
  43. return (
  44. <form className='column-inline-form' onSubmit={this.handleSubmit}>
  45. <label>
  46. <span style={{ display: 'none' }}>{label}</span>
  47. <input
  48. className='setting-text'
  49. value={value}
  50. disabled={disabled}
  51. onChange={this.handleChange}
  52. placeholder={label}
  53. />
  54. </label>
  55. <IconButton
  56. disabled={disabled}
  57. icon='plus'
  58. title={title}
  59. onClick={this.handleClick}
  60. />
  61. </form>
  62. );
  63. }
  64. }