mirror of
https://github.com/getredash/redash.git
synced 2026-05-09 21:02:27 -04:00
* Create React version for the EmailSettingsWarning * Migrate the Create User Page * Migrate UserProfile to React * Add /users/me to the routes (Percy ftw) * Fix UserShow test spec * Remove Error Messages component * Show invitation link if email server not setup (#3519) * return invite link to client if e-mail server is not set up * add a couple of tests to make sure invite links are only returned when neccessary * show invite link when e-mail is not configured * remove "an e-mail has been sent" when there's no e-mail configured * return invite_url in re-invites as well. Also refactor to reuse the code. * Use CreateUserDialog instead of Page * Render invite link on Resend Invitation click * Add email validation to DynamicForm * Fix EmailWarning position + update user list with user creation success * Fix console error on UserProfile * Redirect from /users/new + rename createUser -> showCreateUserDialog * Use alert instead of toastr for user creation errors * Remove logic from CreateUserDialog * CR * Use Promise.reject instead of throw to avoid console error
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import Modal from 'antd/lib/modal';
|
|
import Alert from 'antd/lib/alert';
|
|
import { DynamicForm } from '@/components/dynamic-form/DynamicForm';
|
|
import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper';
|
|
import recordEvent from '@/services/recordEvent';
|
|
|
|
class CreateUserDialog extends React.Component {
|
|
static propTypes = {
|
|
dialog: DialogPropType.isRequired,
|
|
onCreate: PropTypes.func.isRequired,
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = { savingUser: false, errorMessage: null };
|
|
this.form = React.createRef();
|
|
}
|
|
|
|
componentDidMount() {
|
|
recordEvent('view', 'page', 'users/new');
|
|
}
|
|
|
|
createUser = () => {
|
|
this.form.current.validateFieldsAndScroll((err, values) => {
|
|
if (!err) {
|
|
this.setState({ savingUser: true });
|
|
this.props.onCreate(values).then(() => {
|
|
this.props.dialog.close();
|
|
}).catch((error) => {
|
|
this.setState({ savingUser: false, errorMessage: error.message });
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
render() {
|
|
const { savingUser, errorMessage } = this.state;
|
|
const formFields = [
|
|
{ name: 'name', title: 'Name', type: 'text' },
|
|
{ name: 'email', title: 'Email', type: 'email' },
|
|
].map(field => ({ required: true, props: { onPressEnter: this.createUser }, ...field }));
|
|
|
|
return (
|
|
<Modal
|
|
{...this.props.dialog.props}
|
|
title="Create a New User"
|
|
okText="Create"
|
|
okButtonProps={{ loading: savingUser }}
|
|
onOk={() => this.createUser()}
|
|
>
|
|
<DynamicForm fields={formFields} ref={this.form} hideSubmitButton />
|
|
{errorMessage && <Alert message={errorMessage} type="error" showIcon />}
|
|
</Modal>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default wrapDialog(CreateUserDialog);
|