1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 22:54:11 +00:00
Files
seahub/frontend/src/components/dialog/new-wiki-dialog.js

77 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-12-08 00:01:23 +08:00
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,
};
2018-12-10 13:33:32 +08:00
class NewWikiDialog extends React.Component {
2018-12-08 00:01:23 +08:00
constructor(props) {
super(props);
this.state = {
isExist: false,
2018-12-11 13:44:09 +08:00
name: '',
repoID: '',
2019-05-17 11:11:59 +08:00
isSubmitBtnActive: false,
2018-12-08 00:01:23 +08:00
};
this.newName = React.createRef();
}
componentDidMount() {
this.newName.focus();
this.newName.setSelectionRange(0, -1);
}
inputNewName = (e) => {
2019-05-17 11:11:59 +08:00
if (!event.target.value.trim()) {
this.setState({isSubmitBtnActive: false});
} else {
this.setState({isSubmitBtnActive: true});
}
2018-12-08 00:01:23 +08:00
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 (
<Modal isOpen={true}>
<ModalHeader toggle={this.toggle}>{gettext('New Wiki')}</ModalHeader>
<ModalBody>
<label className="form-label">{gettext('Name')}</label>
2018-12-11 13:44:09 +08:00
<Input onKeyPress={this.handleKeyPress} innerRef={input => {this.newName = input;}} value={this.state.name} onChange={this.inputNewName}/>
2018-12-08 00:01:23 +08:00
</ModalBody>
<ModalFooter>
2018-12-08 13:31:41 +08:00
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
2019-05-17 11:11:59 +08:00
<Button color="primary" onClick={this.handleSubmit} disabled={!this.state.isSubmitBtnActive}>{gettext('Submit')}</Button>
2018-12-08 00:01:23 +08:00
</ModalFooter>
</Modal>
);
}
}
2018-12-10 13:33:32 +08:00
NewWikiDialog.propTypes = propTypes;
2018-12-08 00:01:23 +08:00
2018-12-10 13:33:32 +08:00
export default NewWikiDialog;