1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-11 20:01:10 +00:00
Files
seahub/frontend/src/components/dialog/file-participant-dialog.js

142 lines
4.4 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
2019-06-10 18:05:03 +08:00
import PropTypes from 'prop-types';
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
2019-06-10 18:05:03 +08:00
import UserSelect from '../user-select';
import toaster from '../toast';
import { Utils } from '../../utils/utils';
2019-06-28 10:23:22 +08:00
import '../../css/participants-list.css';
2019-06-10 18:05:03 +08:00
const fileParticipantListItemPropTypes = {
participant: PropTypes.object.isRequired,
deleteFileParticipant: PropTypes.func.isRequired,
};
2019-06-10 18:05:03 +08:00
class FileParticipantListItem extends Component {
constructor(props) {
super(props);
this.state = {
isOperationShow: false,
};
}
onMouseOver = () => {
this.setState({ isOperationShow: true });
2019-06-10 18:05:03 +08:00
};
onMouseLeave = () => {
this.setState({ isOperationShow: false });
2019-06-10 18:05:03 +08:00
};
render() {
const { participant } = this.props;
2019-06-10 18:05:03 +08:00
return (
2019-06-28 10:23:22 +08:00
<div className="participant-select-info" onMouseOver={this.onMouseOver} onMouseLeave={this.onMouseLeave}>
<div className="d-flex" style={{maxWidth: '90%'}}>
2019-06-28 10:23:22 +08:00
<img className="avatar participant-select-avatar" src={participant.avatar_url} alt=""/>
<span className="participant-select-name ellipsis">{participant.name}</span>
2019-06-10 18:05:03 +08:00
</div>
2019-06-28 10:23:22 +08:00
<i
className={`action-icon sf2-icon-x3 ${!this.state.isOperationShow &&'o-hidden'}`}
title={gettext('Delete')}
onClick={this.props.deleteFileParticipant.bind(this, participant.email)}
></i>
2019-06-10 18:05:03 +08:00
</div>
);
}
}
FileParticipantListItem.propTypes = fileParticipantListItemPropTypes;
const fileParticipantDialogPropTypes = {
repoID: PropTypes.string.isRequired,
filePath: PropTypes.string.isRequired,
toggleFileParticipantDialog: PropTypes.func.isRequired,
fileParticipantList: PropTypes.array.isRequired,
onParticipantsChange: PropTypes.func,
};
2019-06-10 18:05:03 +08:00
class FileParticipantDialog extends Component {
constructor(props) {
super(props);
this.state = {
selectedOption: null,
};
}
handleSelectChange = (option) => {
this.setState({ selectedOption: option });
2019-06-10 18:05:03 +08:00
};
deleteFileParticipant = (email) => {
2019-06-28 10:23:22 +08:00
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);
2019-06-10 18:05:03 +08:00
});
this.refs.userSelect.clearSelect();
};
addFileParticipant = () => {
const { selectedOption } = this.state;
2019-06-28 10:23:22 +08:00
const { repoID, filePath } = this.props;
if (!selectedOption || selectedOption.length === 0) {
2019-06-10 18:05:03 +08:00
return;
}
2019-06-29 11:24:18 +08:00
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);
2019-06-29 11:24:18 +08:00
});
}
this.setState({ selectedOption: null });
2019-06-10 18:05:03 +08:00
this.refs.userSelect.clearSelect();
};
render() {
const renderParticipantList = this.props.fileParticipantList.map((participant, index) => {
return (
<FileParticipantListItem
key={index}
participant={participant}
deleteFileParticipant={this.deleteFileParticipant}
/>
);
});
return (
<Modal isOpen={true} toggle={this.props.toggleFileParticipantDialog}>
<ModalHeader toggle={this.props.toggleFileParticipantDialog}>{gettext('Participants')}</ModalHeader>
<ModalBody>
2019-06-28 10:23:22 +08:00
<div className="participant-add">
<UserSelect
ref="userSelect"
2019-06-29 11:24:18 +08:00
isMulti={true}
2019-06-28 10:23:22 +08:00
className="participant-select"
placeholder={gettext('Select users...')}
onSelectChange={this.handleSelectChange}
/>
<Button className="btn btn-secondary ml-2" onClick={this.addFileParticipant}>{gettext('Add')}</Button>
2019-06-10 18:05:03 +08:00
</div>
{renderParticipantList}
2019-06-10 18:05:03 +08:00
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggleFileParticipantDialog}>{gettext('Close')}</Button>
</ModalFooter>
2019-06-10 18:05:03 +08:00
</Modal>
);
}
}
FileParticipantDialog.propTypes = fileParticipantDialogPropTypes;
export default FileParticipantDialog;