2018-12-07 16:01:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { gettext } from '../../utils/constants';
|
2024-05-15 03:57:30 +00:00
|
|
|
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input, Label } from 'reactstrap';
|
2018-12-07 16:01:23 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
toggleCancel: PropTypes.func.isRequired,
|
|
|
|
addWiki: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2024-05-15 03:57:30 +00:00
|
|
|
class AddWikiDialog extends React.Component {
|
2018-12-07 16:01:23 +00:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-12-11 05:44:09 +00:00
|
|
|
name: '',
|
2019-05-17 03:11:59 +00:00
|
|
|
isSubmitBtnActive: false,
|
2018-12-07 16:01:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
inputNewName = (e) => {
|
|
|
|
this.setState({
|
|
|
|
name: e.target.value,
|
2024-05-15 03:57:30 +00:00
|
|
|
isSubmitBtnActive: !!e.target.value.trim(),
|
2018-12-07 16:01:23 +00:00
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2018-12-07 16:01:23 +00:00
|
|
|
|
2023-11-14 12:25:25 +00:00
|
|
|
handleKeyDown = (e) => {
|
2018-12-07 16:01:23 +00:00
|
|
|
if (e.key === 'Enter') {
|
|
|
|
this.handleSubmit();
|
2020-11-02 05:56:35 +00:00
|
|
|
}
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2018-12-07 16:01:23 +00:00
|
|
|
|
|
|
|
handleSubmit = () => {
|
2024-05-15 03:57:30 +00:00
|
|
|
const wikiName = this.state.name.trim();
|
|
|
|
if (!wikiName) return;
|
|
|
|
this.props.addWiki(wikiName);
|
2018-12-07 16:01:23 +00:00
|
|
|
this.props.toggleCancel();
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2018-12-07 16:01:23 +00:00
|
|
|
|
|
|
|
toggle = () => {
|
|
|
|
this.props.toggleCancel();
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2018-12-07 16:01:23 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2023-11-30 05:58:06 +00:00
|
|
|
<Modal isOpen={true} autoFocus={false} toggle={this.toggle}>
|
2024-05-15 03:57:30 +00:00
|
|
|
<ModalHeader toggle={this.toggle}>{gettext('Add Wiki')}</ModalHeader>
|
2018-12-07 16:01:23 +00:00
|
|
|
<ModalBody>
|
2024-05-15 03:57:30 +00:00
|
|
|
<Label>{gettext('Name')}</Label>
|
2023-11-14 12:25:25 +00:00
|
|
|
<Input onKeyDown={this.handleKeyDown} autoFocus={true} value={this.state.name} onChange={this.inputNewName}/>
|
2018-12-07 16:01:23 +00:00
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
2018-12-08 05:31:41 +00:00
|
|
|
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
2019-05-17 03:11:59 +00:00
|
|
|
<Button color="primary" onClick={this.handleSubmit} disabled={!this.state.isSubmitBtnActive}>{gettext('Submit')}</Button>
|
2018-12-07 16:01:23 +00:00
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-15 03:57:30 +00:00
|
|
|
AddWikiDialog.propTypes = propTypes;
|
2018-12-07 16:01:23 +00:00
|
|
|
|
2024-05-15 03:57:30 +00:00
|
|
|
export default AddWikiDialog;
|