* Big upgrades * WIP: Stash * Stash, 30 flow errors left * Downgrade mobx * WIP * When I understand the difference between class and instance methods * 💚 * Fixes: File import Model saving edge cases pinning and starring docs Collection editing Upgrade mobx devtools * Notification settings saving works * Disabled settings * Document mailer * Working notifications * Colletion created notification Ensure not notified for own actions * Tidy up * Document updated event only for document creation Add indexes Notification setting on user creation * Commentary * Fixed: Notification setting on signup * Fix document move / duplicate stale data Add BaseModel.refresh method * Fixes: Title in sidebar not updated after editing document * 💚 * Improve / restore error handling Better handle offline errors * 👕
99 lines
2.6 KiB
JavaScript
99 lines
2.6 KiB
JavaScript
// @flow
|
|
import * as React from 'react';
|
|
import { withRouter } from 'react-router-dom';
|
|
import { observable } from 'mobx';
|
|
import { inject, observer } from 'mobx-react';
|
|
import Button from 'components/Button';
|
|
import Input from 'components/Input';
|
|
import InputRich from 'components/InputRich';
|
|
import ColorPicker from 'components/ColorPicker';
|
|
import HelpText from 'components/HelpText';
|
|
|
|
import Collection from 'models/Collection';
|
|
import CollectionsStore from 'stores/CollectionsStore';
|
|
import UiStore from 'stores/UiStore';
|
|
|
|
type Props = {
|
|
history: Object,
|
|
ui: UiStore,
|
|
collections: CollectionsStore,
|
|
onSubmit: () => void,
|
|
};
|
|
|
|
@observer
|
|
class CollectionNew extends React.Component<Props> {
|
|
@observable name: string = '';
|
|
@observable description: string = '';
|
|
@observable color: string = '';
|
|
@observable isSaving: boolean;
|
|
|
|
handleSubmit = async (ev: SyntheticEvent<*>) => {
|
|
ev.preventDefault();
|
|
this.isSaving = true;
|
|
const collection = new Collection(
|
|
{
|
|
name: this.name,
|
|
description: this.description,
|
|
color: this.color,
|
|
},
|
|
this.props.collections
|
|
);
|
|
|
|
try {
|
|
await collection.save();
|
|
this.props.onSubmit();
|
|
this.props.history.push(collection.url);
|
|
} catch (err) {
|
|
this.props.ui.showToast(err.message);
|
|
} finally {
|
|
this.isSaving = false;
|
|
}
|
|
};
|
|
|
|
handleNameChange = (ev: SyntheticInputEvent<*>) => {
|
|
this.name = ev.target.value;
|
|
};
|
|
|
|
handleDescriptionChange = getValue => {
|
|
this.description = getValue();
|
|
};
|
|
|
|
handleColor = (color: string) => {
|
|
this.color = color;
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<form onSubmit={this.handleSubmit}>
|
|
<HelpText>
|
|
Collections are for grouping your knowledge base. They work best when
|
|
organized around a topic or internal team — Product or Engineering for
|
|
example.
|
|
</HelpText>
|
|
<Input
|
|
type="text"
|
|
label="Name"
|
|
onChange={this.handleNameChange}
|
|
value={this.name}
|
|
required
|
|
autoFocus
|
|
/>
|
|
<InputRich
|
|
label="Description"
|
|
onChange={this.handleDescriptionChange}
|
|
defaultValue={this.description || ''}
|
|
placeholder="More details about this collection…"
|
|
minHeight={68}
|
|
maxHeight={200}
|
|
/>
|
|
<ColorPicker onSelect={this.handleColor} />
|
|
<Button type="submit" disabled={this.isSaving || !this.name}>
|
|
{this.isSaving ? 'Creating…' : 'Create'}
|
|
</Button>
|
|
</form>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default inject('collections', 'ui')(withRouter(CollectionNew));
|