2024-11-05 10:03:53 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2024-12-24 03:20:40 +00:00
|
|
|
import { Button, Modal, ModalBody, ModalFooter, Input, Label } from 'reactstrap';
|
2024-11-05 10:03:53 +00:00
|
|
|
import { gettext, isPro } from '../../utils/constants';
|
|
|
|
import wikiAPI from '../../utils/wiki-api';
|
|
|
|
import { Utils } from '../../utils/utils';
|
|
|
|
import toaster from '../toast';
|
2024-12-14 05:17:21 +00:00
|
|
|
import { SeahubSelect } from '../common/select';
|
2024-12-24 03:20:40 +00:00
|
|
|
import SeahubModalHeader from '@/components/common/seahub-modal-header';
|
2024-11-05 10:03:53 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
toggleCancel: PropTypes.func.isRequired,
|
|
|
|
convertWiki: PropTypes.func.isRequired,
|
|
|
|
wiki: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConvertWikiDialog extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
name: '',
|
|
|
|
isSubmitBtnActive: false,
|
|
|
|
selectedOption: null,
|
|
|
|
options: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (!isPro) return;
|
|
|
|
wikiAPI.listWikiDepartments().then(res => {
|
|
|
|
const departments = res.data.sort((a, b) => {
|
|
|
|
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
|
|
|
|
});
|
|
|
|
let options = [];
|
|
|
|
for (let i = 0 ; i < departments.length; i++) {
|
|
|
|
let obj = {};
|
|
|
|
obj.value = departments[i].name;
|
|
|
|
obj.id = departments[i].id;
|
|
|
|
obj.email = departments[i].email;
|
|
|
|
obj.label = departments[i].name;
|
|
|
|
options.push(obj);
|
|
|
|
}
|
|
|
|
this.setState({ options });
|
|
|
|
}).catch(error => {
|
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errMessage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
inputNewName = (e) => {
|
|
|
|
this.setState({
|
|
|
|
name: e.target.value,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
handleKeyDown = (e) => {
|
|
|
|
if (e.key === 'Enter') {
|
|
|
|
this.handleSubmit(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSubmit = (e) => {
|
|
|
|
const wikiName = this.state.name.trim();
|
|
|
|
const departmentID = this.state.selectedOption ? this.state.selectedOption.id : null;
|
|
|
|
if (!wikiName) return;
|
|
|
|
this.props.convertWiki(this.props.wiki, wikiName, departmentID);
|
|
|
|
this.props.toggleCancel(e);
|
|
|
|
};
|
|
|
|
|
|
|
|
toggle = () => {
|
|
|
|
this.props.toggleCancel();
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSelectChange = (option) => {
|
|
|
|
this.setState({ selectedOption: option });
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Modal isOpen={true} autoFocus={false} toggle={this.toggle}>
|
2024-12-24 03:20:40 +00:00
|
|
|
<SeahubModalHeader toggle={this.toggle}>{gettext('Convert Wiki')}</SeahubModalHeader>
|
2024-11-05 10:03:53 +00:00
|
|
|
<ModalBody>
|
|
|
|
<Label>{gettext('Name')}</Label>
|
2025-01-22 08:10:19 +00:00
|
|
|
<Input
|
|
|
|
name="wiki-name"
|
|
|
|
onKeyDown={this.handleKeyDown}
|
|
|
|
autoFocus={true}
|
|
|
|
value={this.state.name}
|
|
|
|
onChange={this.inputNewName}
|
|
|
|
/>
|
2024-11-05 10:03:53 +00:00
|
|
|
{isPro &&
|
|
|
|
<>
|
|
|
|
<Label className='mt-4'>{gettext('Wiki owner')} ({gettext('Optional')})</Label>
|
|
|
|
<SeahubSelect
|
|
|
|
onChange={this.handleSelectChange}
|
|
|
|
options={this.state.options}
|
|
|
|
hideSelectedOptions={true}
|
|
|
|
placeholder={gettext('Select a department')}
|
|
|
|
maxMenuHeight={200}
|
|
|
|
value={this.state.selectedOption}
|
|
|
|
noOptionsMessage={() => {return gettext('No options available');}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
|
|
|
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
|
|
|
<Button color="primary" onClick={this.handleSubmit} disabled={!this.state.name.trim()}>{gettext('Submit')}</Button>
|
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConvertWikiDialog.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default ConvertWikiDialog;
|