2019-10-15 05:41:41 +00:00
|
|
|
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: '',
|
|
|
|
errMessage: '',
|
|
|
|
isSubmitBtnActive: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRepoNameChange = (e) => {
|
|
|
|
if (!e.target.value.trim()) {
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ isSubmitBtnActive: false });
|
2019-10-15 05:41:41 +00:00
|
|
|
} else {
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ isSubmitBtnActive: true });
|
2019-10-15 05:41:41 +00:00
|
|
|
}
|
|
|
|
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ groupName: e.target.value });
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-10-15 05:41:41 +00:00
|
|
|
|
|
|
|
handleSubmit = () => {
|
|
|
|
let groupName = this.state.groupName.trim();
|
|
|
|
this.props.createGroup(groupName, this.state.ownerEmail);
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-10-15 05:41:41 +00:00
|
|
|
|
|
|
|
handleSelectChange = (option) => {
|
2024-08-15 08:17:38 +00:00
|
|
|
// option can be `null`, `[{...}]`, or `[]`
|
2019-10-15 05:41:41 +00:00
|
|
|
this.setState({
|
2024-08-15 08:17:38 +00:00
|
|
|
ownerEmail: option && option.length ? option[0].email : ''
|
2019-10-15 05:41:41 +00:00
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-10-15 05:41:41 +00:00
|
|
|
|
2023-11-14 12:25:25 +00:00
|
|
|
handleKeyDown = (e) => {
|
2019-10-15 05:41:41 +00:00
|
|
|
if (e.key === 'Enter') {
|
|
|
|
this.handleSubmit();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-10-15 05:41:41 +00:00
|
|
|
|
|
|
|
toggle = () => {
|
|
|
|
this.props.toggleDialog();
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-10-15 05:41:41 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-12-24 02:41:34 +00:00
|
|
|
<Modal isOpen={true} toggle={this.toggle} autoFocus={false}>
|
2019-10-15 05:41:41 +00:00
|
|
|
<ModalHeader toggle={this.toggle}>{gettext('New Group')}</ModalHeader>
|
|
|
|
<ModalBody>
|
|
|
|
<Form>
|
|
|
|
<FormGroup>
|
|
|
|
<Label for="groupName">{gettext('Name')}</Label>
|
2020-11-02 05:56:35 +00:00
|
|
|
<Input
|
2019-10-15 05:41:41 +00:00
|
|
|
id="groupName"
|
2023-11-14 12:25:25 +00:00
|
|
|
onKeyDown={this.handleKeyDown}
|
2020-11-02 05:56:35 +00:00
|
|
|
value={this.state.groupName}
|
2019-10-15 05:41:41 +00:00
|
|
|
onChange={this.handleRepoNameChange}
|
2022-12-24 02:41:34 +00:00
|
|
|
autoFocus={true}
|
2019-10-15 05:41:41 +00:00
|
|
|
/>
|
|
|
|
<Label className="mt-2">
|
|
|
|
{gettext('Owner')}
|
|
|
|
<span className="small text-secondary">{gettext('(If left blank, owner will be admin)')}</span>
|
|
|
|
</Label>
|
|
|
|
<UserSelect
|
|
|
|
isMulti={false}
|
|
|
|
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;
|