mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
Close panel when inviting user (#960)
* Close panel when inviting user * Move success invite user message to admin panel list user
This commit is contained in:
parent
9f7b11413c
commit
45a59e0b20
@ -15,24 +15,24 @@ import Icon from 'core-components/icon';
|
|||||||
import ModalContainer from 'app-components/modal-container';
|
import ModalContainer from 'app-components/modal-container';
|
||||||
import InviteUserWidget from 'app/admin/panel/users/invite-user-widget';
|
import InviteUserWidget from 'app/admin/panel/users/invite-user-widget';
|
||||||
|
|
||||||
|
const DEFAULT_USERS_PARAMS = {
|
||||||
|
page: 1,
|
||||||
|
orderBy: 'id',
|
||||||
|
desc: true,
|
||||||
|
search: ''
|
||||||
|
}
|
||||||
|
|
||||||
class AdminPanelListUsers extends React.Component {
|
class AdminPanelListUsers extends React.Component {
|
||||||
state = {
|
state = {
|
||||||
loading: true,
|
loading: true,
|
||||||
users: [],
|
users: [],
|
||||||
orderBy: 'id',
|
usersParams: DEFAULT_USERS_PARAMS,
|
||||||
desc: true,
|
|
||||||
error: false,
|
error: false,
|
||||||
page: 1,
|
|
||||||
pages: 1
|
pages: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.retrieveUsers({
|
this.retrieveUsers(DEFAULT_USERS_PARAMS);
|
||||||
page: 1,
|
|
||||||
orderBy: 'id',
|
|
||||||
desc: true,
|
|
||||||
search: ''
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -48,6 +48,7 @@ class AdminPanelListUsers extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<SearchBox className="admin-panel-list-users__search-box" placeholder={i18n('SEARCH_USERS')} onSearch={this.onSearch.bind(this)} />
|
<SearchBox className="admin-panel-list-users__search-box" placeholder={i18n('SEARCH_USERS')} onSearch={this.onSearch.bind(this)} />
|
||||||
|
{this.state.message === 'success' ? <Message className="admin-panel-list-users__success-message" type="success">{i18n('INVITE_USER_SUCCESS')}</Message> : null}
|
||||||
<Table {...this.getTableProps()} />
|
<Table {...this.getTableProps()} />
|
||||||
<div style={{textAlign: 'right', marginTop: 10}}>
|
<div style={{textAlign: 'right', marginTop: 10}}>
|
||||||
<Button onClick={this.onInviteUser.bind(this)} type="secondary" size="medium">
|
<Button onClick={this.onInviteUser.bind(this)} type="secondary" size="medium">
|
||||||
@ -59,14 +60,16 @@ class AdminPanelListUsers extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTableProps() {
|
getTableProps() {
|
||||||
|
const {loading, users, usersParams, pages } = this.state;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
className: 'admin-panel-list-users__table',
|
className: 'admin-panel-list-users__table',
|
||||||
loading: this.state.loading,
|
loading,
|
||||||
headers: this.getTableHeaders(),
|
headers: this.getTableHeaders(),
|
||||||
rows: this.state.users.map(this.getUserRow.bind(this)),
|
rows: users.map(this.getUserRow.bind(this)),
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
page: this.state.page,
|
page: usersParams.page,
|
||||||
pages: this.state.pages,
|
pages,
|
||||||
onPageChange: this.onPageChange.bind(this)
|
onPageChange: this.onPageChange.bind(this)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -129,44 +132,57 @@ class AdminPanelListUsers extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSearch(query) {
|
onSearch(query) {
|
||||||
this.retrieveUsers({
|
const newUsersParams = {
|
||||||
page: 1,
|
...this.state.usersParams,
|
||||||
orderBy: 'id',
|
page: DEFAULT_USERS_PARAMS.page,
|
||||||
desc: true,
|
|
||||||
search: query
|
search: query
|
||||||
|
}
|
||||||
|
|
||||||
|
this.retrieveUsers(newUsersParams);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
usersParams: newUsersParams
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onPageChange(event) {
|
onPageChange(event) {
|
||||||
const {
|
const newUsersParams = {
|
||||||
orderBy,
|
...this.state.usersParams,
|
||||||
desc,
|
|
||||||
search
|
|
||||||
} = this.state;
|
|
||||||
|
|
||||||
this.retrieveUsers({
|
|
||||||
page: event.target.value,
|
page: event.target.value,
|
||||||
orderBy,
|
}
|
||||||
desc,
|
|
||||||
search
|
this.retrieveUsers(newUsersParams);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
usersParams: newUsersParams
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
orderByTickets(desc) {
|
orderByTickets(desc) {
|
||||||
this.retrieveUsers({
|
const newUsersParams = {
|
||||||
page: 1,
|
...this.state.usersParams,
|
||||||
orderBy: 'tickets',
|
orderBy: 'tickets',
|
||||||
desc: desc,
|
desc: desc
|
||||||
search: this.state.search
|
}
|
||||||
|
|
||||||
|
this.retrieveUsers(newUsersParams);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
usersParams: newUsersParams
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
orderById(desc) {
|
orderById(desc) {
|
||||||
this.retrieveUsers({
|
const newUsersParams = {
|
||||||
page: 1,
|
...this.state.usersParams,
|
||||||
orderBy: 'id',
|
orderBy: 'id',
|
||||||
desc: desc,
|
desc: desc
|
||||||
search: this.state.search
|
}
|
||||||
|
|
||||||
|
this.retrieveUsers(newUsersParams);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
usersParams: newUsersParams
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,21 +200,42 @@ class AdminPanelListUsers extends React.Component {
|
|||||||
onInviteUser(user) {
|
onInviteUser(user) {
|
||||||
ModalContainer.openModal(
|
ModalContainer.openModal(
|
||||||
<div className="admin-panel-list-users__invite-user-form">
|
<div className="admin-panel-list-users__invite-user-form">
|
||||||
<InviteUserWidget onSuccess={this.onInviteUserSuccess.bind(this)} />
|
<InviteUserWidget
|
||||||
</div>
|
onSuccess={this.onInviteUserSuccess.bind(this)}
|
||||||
|
onChangeMessage={this.onChangeMessage.bind(this)} />
|
||||||
|
</div>,
|
||||||
|
{
|
||||||
|
closeButton: {
|
||||||
|
showCloseButton: true
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onChangeMessage(message) {
|
||||||
|
this.setState({
|
||||||
|
message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onInviteUserSuccess() {
|
onInviteUserSuccess() {
|
||||||
ModalContainer.closeModal();
|
ModalContainer.closeModal();
|
||||||
|
|
||||||
|
this.retrieveUsers(DEFAULT_USERS_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUsersRetrieved(result) {
|
onUsersRetrieved(result) {
|
||||||
|
const { page, pages, users, orderBy, desc } = result.data;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
page: result.data.page * 1,
|
usersParams: {
|
||||||
pages: result.data.pages * 1,
|
...this.state.usersParams,
|
||||||
users: result.data.users,
|
page: page*1,
|
||||||
orderBy: result.data.orderBy,
|
orderBy: orderBy,
|
||||||
desc: (result.data.desc*1),
|
desc: desc*1,
|
||||||
|
},
|
||||||
|
pages: pages*1,
|
||||||
|
users: users,
|
||||||
error: false,
|
error: false,
|
||||||
loading: false
|
loading: false
|
||||||
});
|
});
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__success-message {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
&__add-user-form {
|
&__add-user-form {
|
||||||
max-width: 500px;
|
max-width: 500px;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@ class InviteUserWidget extends React.Component {
|
|||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
onSuccess: React.PropTypes.func,
|
onSuccess: React.PropTypes.func,
|
||||||
className: React.PropTypes.string
|
className: React.PropTypes.string,
|
||||||
|
onChangeMessage: React.PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -153,17 +154,28 @@ class InviteUserWidget extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onInviteUserSuccess() {
|
onInviteUserSuccess() {
|
||||||
|
const { onSuccess, onChangeMessage } = this.props;
|
||||||
|
const message = 'success';
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
message: 'success'
|
message
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onChangeMessage && onChangeMessage(message);
|
||||||
|
onSuccess && onSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
onInviteUserFail() {
|
onInviteUserFail() {
|
||||||
|
const { onChangeMessage } = this.props;
|
||||||
|
const message = 'fail';
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
message: 'fail'
|
message
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onChangeMessage && onChangeMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user