2024-08-16 02:17:54 +00:00
|
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2024-11-11 04:30:11 +00:00
|
|
|
|
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
|
2024-08-16 02:17:54 +00:00
|
|
|
|
import CreatableSelect from 'react-select/creatable';
|
2024-11-11 04:30:11 +00:00
|
|
|
|
import { MenuSelectStyle } from '../common/select/seahub-select-style';
|
2024-08-16 02:17:54 +00:00
|
|
|
|
import { gettext } from '../../utils/constants';
|
|
|
|
|
import { Utils } from '../../utils/utils';
|
|
|
|
|
import toaster from '../toast';
|
|
|
|
|
import wikiAPI from '../../utils/wiki-api';
|
|
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
|
wikiId: PropTypes.string.isRequired,
|
|
|
|
|
refreshTrash: PropTypes.func.isRequired,
|
|
|
|
|
toggleDialog: PropTypes.func.isRequired
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class WikiCleanTrash extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.options = [
|
|
|
|
|
{ label: gettext('3 days ago'), value: 3 },
|
|
|
|
|
{ label: gettext('1 week ago'), value: 7 },
|
|
|
|
|
{ label: gettext('1 month ago'), value: 30 },
|
|
|
|
|
{ label: gettext('all'), value: 0 }
|
|
|
|
|
];
|
|
|
|
|
this.state = {
|
|
|
|
|
inputValue: this.options[0],
|
|
|
|
|
submitBtnDisabled: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleInputChange = (value) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
inputValue: value
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
formSubmit = () => {
|
|
|
|
|
const inputValue = this.state.inputValue;
|
|
|
|
|
const { wikiId } = this.props;
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
submitBtnDisabled: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
wikiAPI.cleanWikiTrash(wikiId, inputValue.value).then((res) => {
|
|
|
|
|
toaster.success(gettext('Clean succeeded.'));
|
|
|
|
|
this.props.refreshTrash();
|
|
|
|
|
this.props.toggleDialog();
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
let errorMsg = Utils.getErrorMsg(error);
|
|
|
|
|
this.setState({
|
|
|
|
|
formErrorMsg: errorMsg,
|
|
|
|
|
submitBtnDisabled: false
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { formErrorMsg } = this.state;
|
|
|
|
|
return (
|
2024-11-11 04:30:11 +00:00
|
|
|
|
<Modal isOpen={true} toggle={this.props.toggleDialog}>
|
2024-08-16 02:17:54 +00:00
|
|
|
|
<ModalHeader toggle={this.props.toggleDialog}>{gettext('Clean')}</ModalHeader>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<p>{gettext('Clear files in trash and history:')}</p>
|
|
|
|
|
<CreatableSelect
|
|
|
|
|
defaultValue={this.options[0]}
|
|
|
|
|
options={this.options}
|
|
|
|
|
autoFocus={false}
|
|
|
|
|
onChange={this.handleInputChange}
|
|
|
|
|
placeholder=''
|
2024-11-11 04:30:11 +00:00
|
|
|
|
styles={MenuSelectStyle}
|
2024-08-16 02:17:54 +00:00
|
|
|
|
/>
|
|
|
|
|
{formErrorMsg && <p className="error m-0 mt-2">{formErrorMsg}</p>}
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
</ModalBody>
|
|
|
|
|
<ModalFooter>
|
2024-11-11 04:30:11 +00:00
|
|
|
|
<Button color="secondary" onClick={this.props.toggleDialog}>{gettext('Cancel')}</Button>
|
|
|
|
|
<Button color="primary" disabled={this.state.submitBtnDisabled} onClick={this.formSubmit}>{gettext('Submit')}</Button>
|
2024-08-16 02:17:54 +00:00
|
|
|
|
</ModalFooter>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WikiCleanTrash.propTypes = propTypes;
|
|
|
|
|
|
|
|
|
|
export default WikiCleanTrash;
|