1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-11 20:01:40 +00:00
seahub/frontend/src/components/dialog/new-wiki-dialog.js
llj a4e2e4aba4
[keypress] replaced 'onKeyPress' with 'onKeyDown' as 'keypress' is de… (#5764)
* [keypress] replaced 'onKeyPress' with 'onKeyDown' as 'keypress' is deprecated

* cleaned up code
2023-11-14 20:25:25 +08:00

71 lines
1.8 KiB
JavaScript

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,
};
}
inputNewName = (e) => {
if (!event.target.value.trim()) {
this.setState({isSubmitBtnActive: false});
} else {
this.setState({isSubmitBtnActive: true});
}
this.setState({
name: e.target.value,
});
};
handleKeyDown = (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} autoFocus={false}>
<ModalHeader toggle={this.toggle}>{gettext('New Wiki')}</ModalHeader>
<ModalBody>
<label className="form-label">{gettext('Name')}</label>
<Input onKeyDown={this.handleKeyDown} autoFocus={true} value={this.state.name} onChange={this.inputNewName}/>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.handleSubmit} disabled={!this.state.isSubmitBtnActive}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
}
}
NewWikiDialog.propTypes = propTypes;
export default NewWikiDialog;