1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 02:42:47 +00:00

change system admin department UI (#7010)

This commit is contained in:
Michael An
2024-11-15 20:50:16 +08:00
committed by GitHub
parent d4fc55b76d
commit f40ea0540c
17 changed files with 1914 additions and 16 deletions

View File

@@ -0,0 +1,99 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Form, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import toaster from '../../toast';
import { gettext } from '../../../utils/constants';
import { Utils, validateName } from '../../../utils/utils';
import { systemAdminAPI } from '../../../utils/system-admin-api';
const propTypes = {
parentNode: PropTypes.object,
addDepartment: PropTypes.func,
toggle: PropTypes.func,
setRootNode: PropTypes.func
};
class AddDepartmentV2Dialog extends React.Component {
constructor(props) {
super(props);
this.state = {
departName: '',
isSubmitBtnActive: false
};
}
onKeyDown = (e) => {
if (e.key === 'Enter') {
this.handleSubmit();
e.preventDefault();
}
};
handleChange = (e) => {
this.setState({
departName: e.target.value
}, () => {
this.setState({ isSubmitBtnActive: !!this.state.departName.trim() });
});
};
handleSubmit = () => {
let response = validateName(this.state.departName.trim());
if (!response.isValid) {
this.setState({ errMessage: response.message });
return;
}
const { parentNode } = this.props;
const parentNodeId = parentNode ? parentNode.id : -1;
systemAdminAPI.sysAdminAddNewDepartment(parentNodeId, this.state.departName.trim()).then((res) => {
if (parentNode) {
this.props.addDepartment(parentNode, res.data);
} else {
this.props.setRootNode(res.data);
}
this.props.toggle();
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
};
render() {
const { parentNode } = this.props;
const { isSubmitBtnActive } = this.state;
let title;
if (parentNode) {
title = gettext('Add department at') + ' ' + parentNode.name;
} else {
title = gettext('Create top department');
}
return (
<Modal isOpen={true} toggle={this.props.toggle} autoFocus={false}>
<ModalHeader toggle={this.props.toggle}>{title}</ModalHeader>
<ModalBody>
<Form>
<FormGroup>
<Label for="departmentName">{gettext('Name')}</Label>
<Input
id="departmentName"
onKeyDown={this.onKeyDown}
value={this.state.departName}
onChange={this.handleChange}
autoFocus
/>
</FormGroup>
</Form>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggle}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.handleSubmit} disabled={!isSubmitBtnActive}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
}
}
AddDepartmentV2Dialog.propTypes = propTypes;
export default AddDepartmentV2Dialog;

View File

@@ -0,0 +1,34 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalBody, ModalFooter, ModalHeader, Button } from 'reactstrap';
import { gettext } from '../../../utils/constants';
const propTypes = {
node: PropTypes.object,
toggle: PropTypes.func,
onDelete: PropTypes.func
};
class DeleteDepartmentV2ConfirmDialog extends React.Component {
render() {
const { node, toggle } = this.props;
return (
<Modal isOpen={true} toggle={toggle}>
<ModalHeader toggle={toggle}>
{gettext('Delete department')}
</ModalHeader>
<ModalBody>
<p>{gettext('Are you sure to delete')}{' '}<b>{node.name}</b> ?</p>
</ModalBody>
<ModalFooter>
<Button color="secondary" onMouseDown={toggle}>{gettext('Cancel')}</Button>
<Button color="primary" onMouseDown={this.props.onDelete}>{gettext('Delete')}</Button>
</ModalFooter>
</Modal>
);
}
}
DeleteDepartmentV2ConfirmDialog.propTypes = propTypes;
export default DeleteDepartmentV2ConfirmDialog;

View File

@@ -0,0 +1,87 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Form, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import toaster from '../../toast';
import { gettext } from '../../../utils/constants';
import { Utils, validateName } from '../../../utils/utils';
import { systemAdminAPI } from '../../../utils/system-admin-api';
const propTypes = {
node: PropTypes.object,
renameDepartment: PropTypes.func,
toggle: PropTypes.func
};
class RenameDepartmentV2Dialog extends React.Component {
constructor(props) {
super(props);
this.state = {
departName: props.node.name,
isSubmitBtnActive: false
};
}
onKeyDown = (e) => {
if (e.key === 'Enter') {
this.handleSubmit();
e.preventDefault();
}
};
handleChange = (e) => {
const value = e.target.value;
this.setState({
departName: value
}, () => {
this.setState({ isSubmitBtnActive: !!this.state.departName.trim() });
});
};
handleSubmit = () => {
let response = validateName(this.state.departName.trim());
if (!response.isValid) {
this.setState({ errMessage: response.message });
return;
}
const { node } = this.props;
systemAdminAPI.sysAdminRenameDepartment(node.id, this.state.departName.trim()).then((res) => {
this.props.renameDepartment(node, res.data);
this.props.toggle();
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
};
render() {
const { isSubmitBtnActive } = this.state;
return (
<Modal isOpen={true} toggle={this.props.toggle} autoFocus={false}>
<ModalHeader toggle={this.props.toggle}>{gettext('Rename')}</ModalHeader>
<ModalBody>
<Form>
<FormGroup>
<Label for="departmentName">{gettext('Name')}</Label>
<Input
id="departmentName"
onKeyDown={this.onKeyDown}
value={this.state.departName}
onChange={this.handleChange}
autoFocus
/>
</FormGroup>
</Form>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggle}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.handleSubmit} disabled={!isSubmitBtnActive}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
}
}
RenameDepartmentV2Dialog.propTypes = propTypes;
export default RenameDepartmentV2Dialog;

View File

@@ -0,0 +1,67 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { gettext } from '../../../utils/constants';
import { systemAdminAPI } from '../../../utils/system-admin-api';
import { Utils } from '../../../utils/utils';
import UserSelect from '../../user-select';
export default class AddDepartMemberV2Dialog extends React.Component {
static propTypes = {
toggle: PropTypes.func.isRequired,
nodeId: PropTypes.number.isRequired,
onMemberChanged: PropTypes.func.isRequired
};
constructor(props) {
super(props);
this.state = {
selectedOptions: [],
errMessage: '',
};
}
handleSelectChange = (options) => {
this.setState({ selectedOptions: options });
};
handleSubmit = () => {
const emails = this.state.selectedOptions.map(option => option.email);
if (emails.length === 0) return;
this.setState({ errMessage: '' });
systemAdminAPI.sysAdminAddGroupMember(this.props.nodeId, emails).then((res) => {
this.setState({ selectedOptions: [] });
if (res.data.failed.length > 0) {
this.setState({ errMessage: res.data.failed[0].error_msg });
}
if (res.data.success.length > 0) {
this.props.onMemberChanged();
this.props.toggle();
}
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
this.setState({ errMessage });
});
};
render() {
return (
<Modal isOpen={true} toggle={this.props.toggle}>
<ModalHeader toggle={this.props.toggle}>{gettext('Add member')}</ModalHeader>
<ModalBody>
<UserSelect
placeholder={gettext('Search users')}
onSelectChange={this.handleSelectChange}
isMulti={true}
/>
{this.state.errMessage && <p className="error mt-2">{this.state.errMessage}</p> }
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggle}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.handleSubmit}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
}
}