1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-22 03:47:09 +00:00
Files
seahub/frontend/src/components/dialog/create-group-dialog.js
llj 4eab55fdf9 Files (#5881)
* [side nav] redesigned it: added a new item 'Files', and made 'My Libraries' and some other items as its sub nav items

* ['Files'] added new page 'Files'(added 'My Libraries' to it)

* ['Files'] added 'Shared with me' to it

* ['Files'] added 'Shared with all' to it

* ['Files'] added 'Shared with groups' to it (removed 'details' for 'department')
2024-04-19 14:51:41 +08:00

98 lines
2.6 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';
import { Utils } from '../../utils/utils';
class CreateGroupDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
groupName: '',
errorMsg: '',
isSubmitBtnActive: false,
};
}
handleGroupChange = (event) => {
let name = event.target.value;
if (!name.trim()) {
this.setState({isSubmitBtnActive: false});
} else {
this.setState({isSubmitBtnActive: true});
}
this.setState({
groupName: name
});
if (this.state.errorMsg) {
this.setState({
errorMsg: ''
});
}
};
handleSubmitGroup = () => {
let name = this.state.groupName.trim();
if (name) {
let that = this;
seafileAPI.createGroup(name).then((res)=> {
that.props.onCreateGroup(res.data);
this.props.toggleDialog();
}).catch((error) => {
let errorMsg = Utils.getErrorMsg(error);
this.setState({errorMsg: errorMsg});
});
} else {
this.setState({
errorMsg: gettext('Name is required')
});
}
this.setState({
groupName: '',
});
};
handleKeyDown = (e) => {
if (e.keyCode === 13) {
this.handleSubmitGroup();
e.preventDefault();
}
};
render() {
return(
<Modal isOpen={true} toggle={this.props.toggleDialog} autoFocus={false}>
<ModalHeader toggle={this.props.toggleDialog}>{gettext('New Group')}</ModalHeader>
<ModalBody>
<label htmlFor="groupName">{gettext('Name')}</label>
<Input
type="text"
id="groupName"
value={this.state.groupName}
onChange={this.handleGroupChange}
onKeyDown={this.handleKeyDown}
autoFocus={true}
/>
<span className="error">{this.state.errorMsg}</span>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggleDialog}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.handleSubmitGroup} disabled={!this.state.isSubmitBtnActive}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
}
}
const CreateGroupDialogPropTypes = {
toggleDialog: PropTypes.func.isRequired,
onCreateGroup: PropTypes.func.isRequired
};
CreateGroupDialog.propTypes = CreateGroupDialogPropTypes;
export default CreateGroupDialog;