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( {gettext('Rename Group')} ); } } 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;