1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-28 19:51:34 +00:00
seahub/frontend/src/components/dialog/rename-group-dialog.js
Michael An 9cc48e8502 fix-style-bug (#2734)
Fix style bug in group dialogs.
2018-12-29 11:43:07 +08:00

73 lines
2.2 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import { Modal, ModalHeader, ModalBody, ModalFooter, Input, Button } from 'reactstrap';
class RenameGroupDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
newGroupName: this.props.currentGroupName,
};
}
handleGroupNameChange = (event) => {
let name = event.target.value;
this.setState({
newGroupName: name
});
}
renameGroup = () => {
let name = this.state.newGroupName.trim();
if (name) {
let that = this;
seafileAPI.renameGroup(this.props.groupID, name).then((res)=> {
that.props.loadGroup(this.props.groupID);
that.props.onGroupChanged(res.data.id);
});
}
this.setState({
newGroupName: '',
});
this.props.toggleRenameGroupDialog();
}
handleKeyDown = (event) => {
if (event.keyCode === 13) {
this.renameGroup();
}
}
render() {
return(
<Modal isOpen={this.props.showRenameGroupDialog} toggle={this.props.toggleRenameGroupDialog}>
<ModalHeader>{gettext('Rename Group')}</ModalHeader>
<ModalBody>
<label htmlFor="newGroupName">{gettext('Rename group to')}</label>
<Input type="text" id="newGroupName" value={this.state.newGroupName}
onChange={this.handleGroupNameChange} onKeyDown={this.handleKeyDown}/>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggleRenameGroupDialog}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.renameGroup}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
}
}
const RenameGroupDialogPropTypes = {
showRenameGroupDialog: PropTypes.bool.isRequired,
toggleRenameGroupDialog: PropTypes.func.isRequired,
loadGroup: PropTypes.func.isRequired,
groupID: PropTypes.string.isRequired,
onGroupChanged: PropTypes.func.isRequired,
currentGroupName: PropTypes.string.isRequired,
};
RenameGroupDialog.propTypes = RenameGroupDialogPropTypes;
export default RenameGroupDialog;