import React from 'react'; import PropTypes from 'prop-types'; import { gettext } from '../../utils/constants'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input } from 'reactstrap'; const propTypes = { toggleCancel: PropTypes.func.isRequired, addWiki: PropTypes.func.isRequired, }; class NewWikiDialog extends React.Component { constructor(props) { super(props); this.state = { isExist: false, name: '', repoID: '', isSubmitBtnActive: false, }; this.newName = React.createRef(); } componentDidMount() { this.newName.focus(); this.newName.setSelectionRange(0, -1); } inputNewName = (e) => { if (!event.target.value.trim()) { this.setState({isSubmitBtnActive: false}); } else { this.setState({isSubmitBtnActive: true}); } this.setState({ name: e.target.value, }); } handleKeyPress = (e) => { if (e.key === 'Enter') { this.handleSubmit(); } } handleSubmit = () => { let { isExist, name, repoID } = this.state; this.props.addWiki(isExist, name, repoID); this.props.toggleCancel(); } toggle = () => { this.props.toggleCancel(); } render() { return ( {gettext('New Wiki')} {this.newName = input;}} value={this.state.name} onChange={this.inputNewName}/> ); } } NewWikiDialog.propTypes = propTypes; export default NewWikiDialog;