mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-10 11:21:29 +00:00
sysadmin reconstruct groups page (#4036)
* sysadmin reconstruct groups page * [system admin] groups: fixup & improvement * [system admin] groups: fixup & improvement
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Form, FormGroup, Label, Alert } from 'reactstrap';
|
||||
import { gettext } from '../../../utils/constants';
|
||||
import UserSelect from '../../user-select';
|
||||
|
||||
|
||||
const propTypes = {
|
||||
createGroup: PropTypes.func.isRequired,
|
||||
toggleDialog: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
class SysAdminCreateGroupDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
groupName: '',
|
||||
ownerEmail: '',
|
||||
disabled: true,
|
||||
errMessage: '',
|
||||
isSubmitBtnActive: false
|
||||
};
|
||||
this.newInput = React.createRef();
|
||||
}
|
||||
|
||||
handleRepoNameChange = (e) => {
|
||||
if (!e.target.value.trim()) {
|
||||
this.setState({isSubmitBtnActive: false});
|
||||
} else {
|
||||
this.setState({isSubmitBtnActive: true});
|
||||
}
|
||||
|
||||
this.setState({groupName: e.target.value});
|
||||
}
|
||||
|
||||
handleSubmit = () => {
|
||||
let groupName = this.state.groupName.trim();
|
||||
this.props.createGroup(groupName, this.state.ownerEmail);
|
||||
}
|
||||
|
||||
handleSelectChange = (option) => {
|
||||
// option can be null
|
||||
this.setState({
|
||||
ownerEmail: option ? option.email : ''
|
||||
});
|
||||
}
|
||||
|
||||
handleKeyPress = (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
this.handleSubmit();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
toggle = () => {
|
||||
this.props.toggleDialog();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.newInput.focus();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal isOpen={true} toggle={this.toggle}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('New Group')}</ModalHeader>
|
||||
<ModalBody>
|
||||
<Form>
|
||||
<FormGroup>
|
||||
<Label for="groupName">{gettext('Name')}</Label>
|
||||
<Input
|
||||
id="groupName"
|
||||
onKeyPress={this.handleKeyPress}
|
||||
innerRef={input => {this.newInput = input;}}
|
||||
value={this.state.groupName}
|
||||
onChange={this.handleRepoNameChange}
|
||||
/>
|
||||
<Label className="mt-2">
|
||||
{gettext('Owner')}
|
||||
<span className="small text-secondary">{gettext('(If left blank, owner will be admin)')}</span>
|
||||
</Label>
|
||||
<UserSelect
|
||||
isMulti={false}
|
||||
className="reviewer-select"
|
||||
placeholder={gettext('Select a user')}
|
||||
onSelectChange={this.handleSelectChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
</Form>
|
||||
{this.state.errMessage && <Alert color="danger">{this.state.errMessage}</Alert>}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
||||
<Button color="primary" onClick={this.handleSubmit} disabled={!this.state.isSubmitBtnActive}>{gettext('Submit')}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SysAdminCreateGroupDialog.propTypes = propTypes;
|
||||
|
||||
export default SysAdminCreateGroupDialog;
|
Reference in New Issue
Block a user