Files
redash/client/app/components/users/CreateUserDialog.jsx
Gabriel Dutra f9cc230227 Migrate Data Sources and Alert Destinations pages to React (#3470)
* Migrate TypePicker to React

* Migrate DataSources and Destinations List

* Fixes to DestinationsList

* Add CreateDataSource (testing with Steps)

* Render the form after type selection

* Add HELP_LINKS to CreateDataSource

* Add Done behavior

* Add scrollToTop to CreateDataSource

* TypePicker styling adjusts

* Add CreateDestination

* Update resouce gets to componentDidMount

* Create EditForm components

* Migrate Edit pages

* Remove angular logic from DynamicForm

* Add actions to EditPages

* TypePicker title style adjustments

* Add Empty and Loading state

* UX improvements

* Review changes

* Styling updates on TypePicker, forms background fix

* Add blank line removed by mistaken

* Reorganize TypePicker

* Hide Search on List Pages

* Fix spacing in Forms

* Update Create Data Source and Destination to be a Dialog

* Remove max-height from the form

* Fix DynamicForm import in CreateUserDialog

* Route /new to open CreateSourceDialog

* Add HelpTrigger + refine styling and Edit Pages

* Remove help links from data source resource

* Update Cypress specs

* TypePicker -> CardsList

* Remove old TypePicker styling and change CardsList styling to less

* Test if Percy shows Dialogs

* Personal review cleanup

* CR

* Remove unnecessary query on dialog success

* Handle resource errors in Edit Pages

* Add CreateDestination policy

* Add placeholder and separator to the Name field

* Use cy.click instead of cy.wait

* Revert "Use cy.click instead of cy.wait" (Didn't work)

This reverts commit 77285d9fa3.

* Align help trigger on the right and rename Steps

* Refine behavior for long names

* Update toastr calls to use notification instead

* Redirect to target after creation

* Remove autoFocus on DynamicForm for Edit Pages

* Add eslint-disable for cy.wait
2019-03-28 10:06:46 +02:00

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', autoFocus: true },
{ 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);