PR feedback
This commit is contained in:
@ -1,39 +1,43 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React, { Component } from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import ReactModal from 'react-modal';
|
import ReactModal from 'react-modal';
|
||||||
import { modalFadeIn } from 'styles/animations';
|
import { modalFadeIn } from 'styles/animations';
|
||||||
|
|
||||||
import CloseIcon from '../Icon/CloseIcon';
|
import CloseIcon from 'components/Icon/CloseIcon';
|
||||||
import Flex from '../Flex';
|
import Flex from 'components/Flex';
|
||||||
|
|
||||||
class Modal extends Component {
|
type Props = {
|
||||||
render() {
|
children?: React$Element<any>,
|
||||||
const {
|
isOpen: boolean,
|
||||||
children,
|
title?: string,
|
||||||
isOpen,
|
onRequestClose: () => void,
|
||||||
title = 'Untitled Modal',
|
};
|
||||||
onRequestClose,
|
|
||||||
...rest
|
|
||||||
} = this.props;
|
|
||||||
if (!isOpen) return null;
|
|
||||||
|
|
||||||
return (
|
const Modal = ({
|
||||||
<StyledModal
|
children,
|
||||||
contentLabel={title}
|
isOpen,
|
||||||
onRequestClose={onRequestClose}
|
title = 'Untitled Modal',
|
||||||
isOpen={isOpen}
|
onRequestClose,
|
||||||
{...rest}
|
...rest
|
||||||
>
|
}: Props) => {
|
||||||
<Content column>
|
if (!isOpen) return null;
|
||||||
<h1>{title}</h1>
|
|
||||||
<Close onClick={onRequestClose}><CloseIcon /></Close>
|
return (
|
||||||
{children}
|
<StyledModal
|
||||||
</Content>
|
contentLabel={title}
|
||||||
</StyledModal>
|
onRequestClose={onRequestClose}
|
||||||
);
|
isOpen={isOpen}
|
||||||
}
|
{...rest}
|
||||||
}
|
>
|
||||||
|
<Content column>
|
||||||
|
{title && <h1>{title}</h1>}
|
||||||
|
<Close onClick={onRequestClose}><CloseIcon /></Close>
|
||||||
|
{children}
|
||||||
|
</Content>
|
||||||
|
</StyledModal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const Content = styled(Flex)`
|
const Content = styled(Flex)`
|
||||||
width: 640px;
|
width: 640px;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
import { observable } from 'mobx';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
import Button from 'components/Button';
|
import Button from 'components/Button';
|
||||||
import Input from 'components/Input';
|
import Input from 'components/Input';
|
||||||
import HelpText from 'components/HelpText';
|
import HelpText from 'components/HelpText';
|
||||||
@ -13,48 +15,40 @@ type Props = {
|
|||||||
onCollectionCreated: () => void,
|
onCollectionCreated: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
class CollectionNew extends Component {
|
@observer class CollectionNew extends Component {
|
||||||
props: Props;
|
props: Props;
|
||||||
state: { collection: Collection, name: string, isSaving: boolean };
|
@observable collection: Collection;
|
||||||
|
@observable name: string = '';
|
||||||
|
@observable isSaving: boolean;
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.collection = new Collection();
|
||||||
this.state = {
|
|
||||||
name: '',
|
|
||||||
isSaving: false,
|
|
||||||
collection: new Collection(),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit = async (ev: SyntheticEvent) => {
|
handleSubmit = async (ev: SyntheticEvent) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
this.setState({ isSaving: true });
|
this.isSaving = true;
|
||||||
const { collection } = this.state;
|
this.collection.updateData({ name: this.name });
|
||||||
const { collections } = this.props;
|
const success = await this.collection.save();
|
||||||
|
|
||||||
collection.updateData(this.state);
|
|
||||||
const success = await collection.save();
|
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
collections.add(collection);
|
this.props.collections.add(this.collection);
|
||||||
this.props.onCollectionCreated();
|
this.props.onCollectionCreated();
|
||||||
this.props.history.push(collection.url);
|
this.props.history.push(this.collection.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({ isSaving: false });
|
this.isSaving = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
handleNameChange = (ev: SyntheticInputEvent) => {
|
handleNameChange = (ev: SyntheticInputEvent) => {
|
||||||
this.setState({ name: ev.target.value });
|
this.name = ev.target.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { collection } = this.state;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={this.handleSubmit}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
{collection.errors.errors.map(error => <span>{error}</span>)}
|
{this.collection.errors.errors.map(error => <span>{error}</span>)}
|
||||||
<HelpText>
|
<HelpText>
|
||||||
Collections are for grouping your Atlas. They work best when organized
|
Collections are for grouping your Atlas. They work best when organized
|
||||||
around a topic or internal team — Product or Engineering for example.
|
around a topic or internal team — Product or Engineering for example.
|
||||||
@ -63,15 +57,12 @@ class CollectionNew extends Component {
|
|||||||
type="text"
|
type="text"
|
||||||
label="Name"
|
label="Name"
|
||||||
onChange={this.handleNameChange}
|
onChange={this.handleNameChange}
|
||||||
value={this.state.name}
|
value={this.name}
|
||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button type="submit" disabled={this.isSaving || !this.name}>
|
||||||
type="submit"
|
{this.isSaving ? 'Creating…' : 'Create'}
|
||||||
disabled={this.state.isSaving || !this.state.name}
|
|
||||||
>
|
|
||||||
{this.state.isSaving ? 'Creating…' : 'Create'}
|
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user