1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-15 07:52:14 +00:00

Merge pull request #2643 from haiwen/fix-add-group

fix-create-group
This commit is contained in:
Daniel Pan 2018-12-14 18:09:47 +08:00 committed by GitHub
commit f003f94e48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 7 deletions

View File

@ -10,6 +10,7 @@ class CreateGroupDialog extends React.Component {
super(props); super(props);
this.state = { this.state = {
groupName: '', groupName: '',
errorMsg: '',
}; };
} }
@ -18,6 +19,11 @@ class CreateGroupDialog extends React.Component {
this.setState({ this.setState({
groupName: name groupName: name
}); });
if (this.state.errorMsg) {
this.setState({
errorMsg: ''
})
}
} }
handleSubmitGroup = () => { handleSubmitGroup = () => {
@ -25,13 +31,23 @@ class CreateGroupDialog extends React.Component {
if (name) { if (name) {
let that = this; let that = this;
seafileAPI.createGroup(name).then((res)=> { seafileAPI.createGroup(name).then((res)=> {
that.props.listGroups(); that.props.onCreateGroup();
}).catch((error) => {
let errorMsg = gettext(error.response.data.error_msg);
this.setState({
errorMsg: errorMsg
});
}); });
} }
this.setState({ this.setState({
groupName: '', groupName: '',
}); });
this.props.toggleAddGroupModal(); }
handleKeyDown = (e) => {
if (e.keyCode === 13) {
this.handleSubmitGroup();
}
} }
render() { render() {
@ -40,11 +56,13 @@ class CreateGroupDialog extends React.Component {
<ModalHeader toggle={this.toggle}>{gettext('New group')}</ModalHeader> <ModalHeader toggle={this.toggle}>{gettext('New group')}</ModalHeader>
<ModalBody> <ModalBody>
<label htmlFor="groupName">{gettext('Name')}</label> <label htmlFor="groupName">{gettext('Name')}</label>
<Input type="text" id="groupName" value={this.state.groupName} onChange={this.handleGroupChange}/> <Input type="text" id="groupName" value={this.state.groupName}
onChange={this.handleGroupChange} onKeyDown={this.handleKeyDown}/>
<span className="error">{this.state.errorMsg}</span>
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<Button color="primary" onClick={this.handleSubmitGroup}>{gettext('Submit')}</Button>
<Button color="secondary" onClick={this.props.toggleAddGroupModal}>{gettext('Cancel')}</Button> <Button color="secondary" onClick={this.props.toggleAddGroupModal}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.handleSubmitGroup}>{gettext('Submit')}</Button>
</ModalFooter> </ModalFooter>
</Modal> </Modal>
); );
@ -53,7 +71,7 @@ class CreateGroupDialog extends React.Component {
const CreateGroupDialogPropTypes = { const CreateGroupDialogPropTypes = {
toggleAddGroupModal: PropTypes.func.isRequired, toggleAddGroupModal: PropTypes.func.isRequired,
listGroups: PropTypes.func.isRequired, onCreateGroup: PropTypes.func.isRequired,
showAddGroupModal: PropTypes.bool.isRequired, showAddGroupModal: PropTypes.bool.isRequired,
}; };

View File

@ -21,7 +21,7 @@ class GroupsToolbar extends React.Component {
let { onShowSidePanel, onSearchedClick } = this.props; let { onShowSidePanel, onSearchedClick } = this.props;
return ( return (
<div className="main-panel-north"> <div className="main-panel-north">
<div className="cur-view-toolbar"> <div className="cur-view-toolbar border-left-show">
<div className="operation"> <div className="operation">
<Button color="btn btn-secondary operation-item" onClick={this.props.toggleAddGroupModal}> <Button color="btn btn-secondary operation-item" onClick={this.props.toggleAddGroupModal}>
<i className="fas fa-plus-square op-icon"></i>{gettext("New Group")} <i className="fas fa-plus-square op-icon"></i>{gettext("New Group")}

View File

@ -122,6 +122,15 @@ class GroupsView extends React.Component {
}); });
} }
onCreateGroup = () => {
this.setState({
showAddGroupModal: false,
isLoading: true,
groupList: [],
});
this.listGroups();
}
componentDidMount() { componentDidMount() {
this.listGroups(); this.listGroups();
} }
@ -154,7 +163,7 @@ class GroupsView extends React.Component {
{ this.state.showAddGroupModal && { this.state.showAddGroupModal &&
<CreateGroupDialog <CreateGroupDialog
toggleAddGroupModal={this.toggleAddGroupModal} toggleAddGroupModal={this.toggleAddGroupModal}
listGroups={this.listGroups} onCreateGroup={this.onCreateGroup}
showAddGroupModal={this.state.showAddGroupModal} showAddGroupModal={this.state.showAddGroupModal}
/> />
} }