import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap'; import { gettext } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import UserSelect from '../user-select'; import toaster from '../toast'; import { Utils } from '../../utils/utils'; import '../../css/participants-list.css'; const fileParticipantListItemPropTypes = { participant: PropTypes.object.isRequired, deleteFileParticipant: PropTypes.func.isRequired, }; class FileParticipantListItem extends Component { constructor(props) { super(props); this.state = { isOperationShow: false, }; } onMouseOver = () => { this.setState({ isOperationShow: true }); }; onMouseLeave = () => { this.setState({ isOperationShow: false }); }; render() { const { participant } = this.props; return (
{participant.name}
); } } FileParticipantListItem.propTypes = fileParticipantListItemPropTypes; const fileParticipantDialogPropTypes = { repoID: PropTypes.string.isRequired, filePath: PropTypes.string.isRequired, toggleFileParticipantDialog: PropTypes.func.isRequired, fileParticipantList: PropTypes.array.isRequired, onParticipantsChange: PropTypes.func, }; class FileParticipantDialog extends Component { constructor(props) { super(props); this.state = { selectedOption: null, }; } handleSelectChange = (option) => { this.setState({ selectedOption: option }); }; deleteFileParticipant = (email) => { const { repoID, filePath } = this.props; seafileAPI.deleteFileParticipant(repoID, filePath, email).then((res) => { this.props.onParticipantsChange(repoID, filePath); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); this.refs.userSelect.clearSelect(); }; addFileParticipant = () => { const { selectedOption } = this.state; const { repoID, filePath } = this.props; if (!selectedOption || selectedOption.length === 0) { return; } for (let i = 0; i < selectedOption.length; i++) { seafileAPI.addFileParticipant(repoID, filePath, selectedOption[i].email).then((res) => { this.props.onParticipantsChange(repoID, filePath); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } this.setState({ selectedOption: null }); this.refs.userSelect.clearSelect(); }; render() { const renderParticipantList = this.props.fileParticipantList.map((participant, index) => { return ( ); }); return ( {gettext('Participants')}
{renderParticipantList}
); } } FileParticipantDialog.propTypes = fileParticipantDialogPropTypes; export default FileParticipantDialog;