2019-11-05 09:46:06 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2024-12-24 03:20:40 +00:00
|
|
|
import { Button, Form, FormGroup, Label, Input, Modal, ModalBody, ModalFooter, Alert } from 'reactstrap';
|
2019-11-05 09:46:06 +00:00
|
|
|
import { gettext } from '../../utils/constants';
|
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
|
|
|
import toaster from '../toast';
|
2024-12-24 03:20:40 +00:00
|
|
|
import SeahubModalHeader from '@/components/common/seahub-modal-header';
|
2019-11-05 09:46:06 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
sharedToken: PropTypes.string.isRequired,
|
|
|
|
filePath: PropTypes.string.isRequired,
|
|
|
|
toggleAddAbuseReportDialog: PropTypes.func.isRequired,
|
|
|
|
isAddAbuseReportDialogOpen: PropTypes.bool.isRequired,
|
|
|
|
contactEmail: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
class AddAbuseReportDialog extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
abuseType: 'copyright',
|
|
|
|
description: '',
|
|
|
|
reporter: this.props.contactEmail,
|
|
|
|
errMessage: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onAbuseReport = () => {
|
|
|
|
if (!this.state.reporter) {
|
|
|
|
this.setState({
|
|
|
|
errMessage: gettext('Contact information is required.')
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
seafileAPI.addAbuseReport(this.props.sharedToken, this.state.abuseType, this.state.description, this.state.reporter, this.props.filePath).then((res) => {
|
|
|
|
this.props.toggleAddAbuseReportDialog();
|
2024-10-16 06:09:14 +00:00
|
|
|
toaster.success(gettext('Abuse report added'), { duration: 2 });
|
2019-11-05 09:46:06 +00:00
|
|
|
}).catch((error) => {
|
|
|
|
if (error.response) {
|
|
|
|
this.setState({
|
|
|
|
errMessage: error.response.data.error_msg
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
onAbuseTypeChange = (event) => {
|
|
|
|
let type = event.target.value;
|
|
|
|
if (type === this.state.abuseType) {
|
|
|
|
return;
|
|
|
|
}
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ abuseType: type });
|
2019-11-05 09:46:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
setReporter = (event) => {
|
|
|
|
let reporter = event.target.value.trim();
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ reporter: reporter });
|
2019-11-05 09:46:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
setDescription = (event) => {
|
|
|
|
let desc = event.target.value.trim();
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ description: desc });
|
2019-11-05 09:46:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Modal isOpen={this.props.isAddAbuseReportDialogOpen} toggle={this.props.toggleAddAbuseReportDialog}>
|
2024-12-24 03:20:40 +00:00
|
|
|
<SeahubModalHeader toggle={this.props.toggleAddAbuseReportDialog}>{gettext('Report Abuse')}</SeahubModalHeader>
|
2019-11-05 09:46:06 +00:00
|
|
|
<ModalBody>
|
|
|
|
<Form>
|
|
|
|
<FormGroup>
|
|
|
|
<Label for="abuse-type-select">{gettext('Abuse Type')}</Label>
|
|
|
|
<Input type="select" id="abuse-type-select" onChange={(event) => this.onAbuseTypeChange(event)}>
|
|
|
|
<option value='copyright'>{gettext('Copyright Infringement')}</option>
|
|
|
|
<option value='virus'>{gettext('Virus')}</option>
|
|
|
|
<option value='abuse_content'>{gettext('Abuse Content')}</option>
|
|
|
|
<option value='other'>{gettext('Other')}</option>
|
|
|
|
</Input>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
2019-11-12 06:43:33 +00:00
|
|
|
<Label>{gettext('Contact Information')}</Label>
|
2019-11-05 09:46:06 +00:00
|
|
|
<Input type="text" value={this.state.reporter} onChange={(event) => this.setReporter(event)}/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
2019-11-12 06:43:33 +00:00
|
|
|
<Label>{gettext('Description')}</Label>
|
2019-11-05 09:46:06 +00:00
|
|
|
<Input type="textarea" onChange={(event) => this.setDescription(event)}/>
|
|
|
|
</FormGroup>
|
|
|
|
</Form>
|
|
|
|
{this.state.errMessage && <Alert color="danger">{this.state.errMessage}</Alert>}
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
|
|
|
<Button color="secondary" onClick={this.props.toggleAddAbuseReportDialog}>{gettext('Cancel')}</Button>
|
|
|
|
<Button color="primary" onClick={this.onAbuseReport}>{gettext('Submit')}</Button>
|
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddAbuseReportDialog.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default AddAbuseReportDialog;
|