This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/scenes/CollectionNew.js

81 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-07-09 17:27:29 +00:00
// @flow
2018-05-05 23:16:08 +00:00
import * as React from 'react';
2017-09-12 06:41:12 +00:00
import { withRouter } from 'react-router-dom';
2017-07-10 06:53:35 +00:00
import { observable } from 'mobx';
2017-09-12 06:41:12 +00:00
import { inject, observer } from 'mobx-react';
2017-07-09 17:27:29 +00:00
import Button from 'components/Button';
import Input from 'components/Input';
2017-10-30 06:22:46 +00:00
import ColorPicker from 'components/ColorPicker';
2017-07-10 03:02:10 +00:00
import HelpText from 'components/HelpText';
2017-07-09 17:27:29 +00:00
import Collection from 'models/Collection';
2017-07-10 03:02:10 +00:00
import CollectionsStore from 'stores/CollectionsStore';
2017-07-09 17:27:29 +00:00
2017-07-10 03:56:36 +00:00
type Props = {
history: Object,
collections: CollectionsStore,
onSubmit: () => void,
2017-07-10 03:56:36 +00:00
};
2017-07-10 03:02:10 +00:00
2017-11-10 22:14:30 +00:00
@observer
2018-05-05 23:16:08 +00:00
class CollectionNew extends React.Component<Props> {
2017-07-10 06:53:35 +00:00
@observable collection: Collection;
@observable name: string = '';
2017-10-30 06:22:46 +00:00
@observable color: string = '';
2017-07-10 06:53:35 +00:00
@observable isSaving: boolean;
2017-07-10 03:56:36 +00:00
constructor(props: Props) {
super(props);
2017-07-10 06:53:35 +00:00
this.collection = new Collection();
2017-07-10 03:56:36 +00:00
}
2017-07-09 17:27:29 +00:00
2018-05-05 23:16:08 +00:00
handleSubmit = async (ev: SyntheticEvent<*>) => {
2017-07-09 17:27:29 +00:00
ev.preventDefault();
2017-07-10 06:53:35 +00:00
this.isSaving = true;
2017-10-30 06:22:46 +00:00
this.collection.updateData({ name: this.name, color: this.color });
2017-07-10 06:53:35 +00:00
const success = await this.collection.save();
2017-07-10 03:56:36 +00:00
if (success) {
2017-07-10 06:53:35 +00:00
this.props.collections.add(this.collection);
this.props.onSubmit();
2017-07-10 06:53:35 +00:00
this.props.history.push(this.collection.url);
2017-07-10 03:56:36 +00:00
}
2017-07-10 03:02:10 +00:00
2017-07-10 06:53:35 +00:00
this.isSaving = false;
2017-07-09 17:27:29 +00:00
};
2018-05-05 23:16:08 +00:00
handleNameChange = (ev: SyntheticInputEvent<*>) => {
2017-07-10 06:53:35 +00:00
this.name = ev.target.value;
2017-07-09 17:27:29 +00:00
};
2017-10-30 06:22:46 +00:00
handleColor = (color: string) => {
this.color = color;
};
2017-07-09 17:27:29 +00:00
render() {
return (
<form onSubmit={this.handleSubmit}>
2017-07-10 03:02:10 +00:00
<HelpText>
2018-08-07 06:22:20 +00:00
Collections are for grouping your knowledge base. They work best when
2017-11-10 22:14:30 +00:00
organized around a topic or internal team Product or Engineering for
example.
2017-07-10 03:02:10 +00:00
</HelpText>
2017-07-09 17:27:29 +00:00
<Input
type="text"
2017-07-10 03:02:10 +00:00
label="Name"
2017-07-09 17:27:29 +00:00
onChange={this.handleNameChange}
2017-07-10 06:53:35 +00:00
value={this.name}
2017-07-10 03:02:10 +00:00
required
2017-07-09 17:27:29 +00:00
autoFocus
/>
2017-10-30 06:22:46 +00:00
<ColorPicker onSelect={this.handleColor} />
2017-07-10 06:53:35 +00:00
<Button type="submit" disabled={this.isSaving || !this.name}>
{this.isSaving ? 'Creating…' : 'Create'}
2017-07-09 17:27:29 +00:00
</Button>
</form>
);
}
}
2017-09-12 06:41:12 +00:00
export default inject('collections')(withRouter(CollectionNew));