2018-12-12 10:24:47 +00:00
|
|
|
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';
|
2019-07-16 02:01:09 +00:00
|
|
|
import { Utils } from '../../utils/utils';
|
2018-12-12 10:24:47 +00:00
|
|
|
|
|
|
|
class CreateGroupDialog extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
groupName: '',
|
2018-12-13 09:55:22 +00:00
|
|
|
errorMsg: '',
|
2019-05-17 03:09:05 +00:00
|
|
|
isSubmitBtnActive: false,
|
2018-12-12 10:24:47 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleGroupChange = (event) => {
|
2019-04-08 03:46:57 +00:00
|
|
|
let name = event.target.value;
|
2019-05-17 03:09:05 +00:00
|
|
|
|
|
|
|
if (!name.trim()) {
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ isSubmitBtnActive: false });
|
2019-05-17 03:09:05 +00:00
|
|
|
} else {
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ isSubmitBtnActive: true });
|
2019-05-17 03:09:05 +00:00
|
|
|
}
|
2018-12-12 10:24:47 +00:00
|
|
|
this.setState({
|
|
|
|
groupName: name
|
|
|
|
});
|
2018-12-13 09:55:22 +00:00
|
|
|
if (this.state.errorMsg) {
|
|
|
|
this.setState({
|
|
|
|
errorMsg: ''
|
2019-01-31 09:37:02 +00:00
|
|
|
});
|
2018-12-13 09:55:22 +00:00
|
|
|
}
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2018-12-12 10:24:47 +00:00
|
|
|
|
|
|
|
handleSubmitGroup = () => {
|
|
|
|
let name = this.state.groupName.trim();
|
|
|
|
if (name) {
|
|
|
|
let that = this;
|
2024-07-18 03:58:42 +00:00
|
|
|
seafileAPI.createGroup(name).then((res) => {
|
2024-04-19 06:51:41 +00:00
|
|
|
that.props.onCreateGroup(res.data);
|
|
|
|
this.props.toggleDialog();
|
2018-12-13 09:55:22 +00:00
|
|
|
}).catch((error) => {
|
2019-07-16 02:01:09 +00:00
|
|
|
let errorMsg = Utils.getErrorMsg(error);
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ errorMsg: errorMsg });
|
2018-12-12 10:24:47 +00:00
|
|
|
});
|
2019-04-08 03:46:57 +00:00
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
errorMsg: gettext('Name is required')
|
|
|
|
});
|
2018-12-12 10:24:47 +00:00
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
groupName: '',
|
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2018-12-13 09:55:22 +00:00
|
|
|
|
|
|
|
handleKeyDown = (e) => {
|
|
|
|
if (e.keyCode === 13) {
|
|
|
|
this.handleSubmitGroup();
|
2019-05-08 07:34:23 +00:00
|
|
|
e.preventDefault();
|
2018-12-13 09:55:22 +00:00
|
|
|
}
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2018-12-12 10:24:47 +00:00
|
|
|
|
|
|
|
render() {
|
2024-07-18 03:58:42 +00:00
|
|
|
return (
|
2024-04-19 06:51:41 +00:00
|
|
|
<Modal isOpen={true} toggle={this.props.toggleDialog} autoFocus={false}>
|
|
|
|
<ModalHeader toggle={this.props.toggleDialog}>{gettext('New Group')}</ModalHeader>
|
2018-12-12 10:24:47 +00:00
|
|
|
<ModalBody>
|
|
|
|
<label htmlFor="groupName">{gettext('Name')}</label>
|
2019-05-08 07:34:23 +00:00
|
|
|
<Input
|
|
|
|
type="text"
|
|
|
|
id="groupName"
|
|
|
|
value={this.state.groupName}
|
|
|
|
onChange={this.handleGroupChange}
|
|
|
|
onKeyDown={this.handleKeyDown}
|
2022-12-24 02:41:34 +00:00
|
|
|
autoFocus={true}
|
2019-05-08 07:34:23 +00:00
|
|
|
/>
|
2018-12-13 09:55:22 +00:00
|
|
|
<span className="error">{this.state.errorMsg}</span>
|
2018-12-12 10:24:47 +00:00
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
2024-04-19 06:51:41 +00:00
|
|
|
<Button color="secondary" onClick={this.props.toggleDialog}>{gettext('Cancel')}</Button>
|
2019-05-17 03:09:05 +00:00
|
|
|
<Button color="primary" onClick={this.handleSubmitGroup} disabled={!this.state.isSubmitBtnActive}>{gettext('Submit')}</Button>
|
2018-12-12 10:24:47 +00:00
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const CreateGroupDialogPropTypes = {
|
2024-04-19 06:51:41 +00:00
|
|
|
toggleDialog: PropTypes.func.isRequired,
|
|
|
|
onCreateGroup: PropTypes.func.isRequired
|
2018-12-12 10:24:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CreateGroupDialog.propTypes = CreateGroupDialogPropTypes;
|
|
|
|
|
2023-09-13 00:40:50 +00:00
|
|
|
export default CreateGroupDialog;
|