mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 02:10:24 +00:00
migrate old wiki to new wiki (#6987)
* migrate old wiki to new wiki * change style --------- Co-authored-by: Michael An <2331806369@qq.com>
This commit is contained in:
114
frontend/src/components/dialog/convert-wiki-dialog.js
Normal file
114
frontend/src/components/dialog/convert-wiki-dialog.js
Normal file
@@ -0,0 +1,114 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input, Label } from 'reactstrap';
|
||||
import { gettext, isPro } from '../../utils/constants';
|
||||
import wikiAPI from '../../utils/wiki-api';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import toaster from '../toast';
|
||||
import { SeahubSelect, NoOptionsStyle } from '../common/select';
|
||||
|
||||
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}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Convert Wiki')}</ModalHeader>
|
||||
<ModalBody>
|
||||
<Label>{gettext('Name')}</Label>
|
||||
<Input onKeyDown={this.handleKeyDown} autoFocus={true} value={this.state.name} onChange={this.inputNewName}/>
|
||||
{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}
|
||||
components={{ NoOptionsMessage: (
|
||||
<div style={NoOptionsStyle}>{gettext('No department')}</div>
|
||||
) }}
|
||||
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;
|
Reference in New Issue
Block a user