Split modals, document delete
This commit is contained in:
@ -75,11 +75,11 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleCreateCollection = () => {
|
handleCreateCollection = () => {
|
||||||
this.props.ui.setActiveModal('create-collection');
|
this.props.ui.setActiveModal('collection-new');
|
||||||
};
|
};
|
||||||
|
|
||||||
handleEditCollection = () => {
|
handleEditCollection = () => {
|
||||||
this.props.ui.setActiveModal('edit-collection');
|
this.props.ui.setActiveModal('collection-edit');
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -5,6 +5,8 @@ import Modal from 'components/Modal';
|
|||||||
import UiStore from 'stores/UiStore';
|
import UiStore from 'stores/UiStore';
|
||||||
import CollectionNew from 'scenes/CollectionNew';
|
import CollectionNew from 'scenes/CollectionNew';
|
||||||
import CollectionEdit from 'scenes/CollectionEdit';
|
import CollectionEdit from 'scenes/CollectionEdit';
|
||||||
|
import CollectionDelete from 'scenes/CollectionDelete';
|
||||||
|
import DocumentDelete from 'scenes/DocumentDelete';
|
||||||
import KeyboardShortcuts from 'scenes/KeyboardShortcuts';
|
import KeyboardShortcuts from 'scenes/KeyboardShortcuts';
|
||||||
import Settings from 'scenes/Settings';
|
import Settings from 'scenes/Settings';
|
||||||
|
|
||||||
@ -23,19 +25,33 @@ import Settings from 'scenes/Settings';
|
|||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
<Modal
|
<Modal
|
||||||
isOpen={activeModalName === 'create-collection'}
|
isOpen={activeModalName === 'collection-new'}
|
||||||
onRequestClose={this.handleClose}
|
onRequestClose={this.handleClose}
|
||||||
title="Create a collection"
|
title="Create a collection"
|
||||||
>
|
>
|
||||||
<CollectionNew onSubmit={this.handleClose} {...activeModalProps} />
|
<CollectionNew onSubmit={this.handleClose} {...activeModalProps} />
|
||||||
</Modal>
|
</Modal>
|
||||||
<Modal
|
<Modal
|
||||||
isOpen={activeModalName === 'edit-collection'}
|
isOpen={activeModalName === 'collection-edit'}
|
||||||
onRequestClose={this.handleClose}
|
onRequestClose={this.handleClose}
|
||||||
title="Edit collection"
|
title="Edit collection"
|
||||||
>
|
>
|
||||||
<CollectionEdit onSubmit={this.handleClose} {...activeModalProps} />
|
<CollectionEdit onSubmit={this.handleClose} {...activeModalProps} />
|
||||||
</Modal>
|
</Modal>
|
||||||
|
<Modal
|
||||||
|
isOpen={activeModalName === 'collection-delete'}
|
||||||
|
onRequestClose={this.handleClose}
|
||||||
|
title="Delete collection"
|
||||||
|
>
|
||||||
|
<CollectionDelete onSubmit={this.handleClose} {...activeModalProps} />
|
||||||
|
</Modal>
|
||||||
|
<Modal
|
||||||
|
isOpen={activeModalName === 'document-delete'}
|
||||||
|
onRequestClose={this.handleClose}
|
||||||
|
title="Delete document"
|
||||||
|
>
|
||||||
|
<DocumentDelete onSubmit={this.handleClose} {...activeModalProps} />
|
||||||
|
</Modal>
|
||||||
<Modal
|
<Modal
|
||||||
isOpen={activeModalName === 'keyboard-shortcuts'}
|
isOpen={activeModalName === 'keyboard-shortcuts'}
|
||||||
onRequestClose={this.handleClose}
|
onRequestClose={this.handleClose}
|
||||||
|
@ -17,12 +17,12 @@ import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
|
|||||||
|
|
||||||
onEdit = () => {
|
onEdit = () => {
|
||||||
const { collection } = this.props;
|
const { collection } = this.props;
|
||||||
this.props.ui.setActiveModal('edit-collection', { collection });
|
this.props.ui.setActiveModal('collection-edit', { collection });
|
||||||
};
|
};
|
||||||
|
|
||||||
onDelete = () => {
|
onDelete = () => {
|
||||||
const { collection } = this.props;
|
const { collection } = this.props;
|
||||||
this.props.ui.setActiveModal('delete-collection', { collection });
|
this.props.ui.setActiveModal('collection-delete', { collection });
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -25,7 +25,7 @@ import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
|
|||||||
|
|
||||||
onDelete = () => {
|
onDelete = () => {
|
||||||
const { document } = this.props;
|
const { document } = this.props;
|
||||||
this.props.ui.setActiveModal('delete-document', { document });
|
this.props.ui.setActiveModal('document-delete', { document });
|
||||||
};
|
};
|
||||||
|
|
||||||
onExport = () => {
|
onExport = () => {
|
||||||
|
60
frontend/scenes/CollectionDelete/CollectionDelete.js
Normal file
60
frontend/scenes/CollectionDelete/CollectionDelete.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// @flow
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { observable } from 'mobx';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
import { homeUrl } from 'utils/routeHelpers';
|
||||||
|
import Button from 'components/Button';
|
||||||
|
import Flex from 'components/Flex';
|
||||||
|
import HelpText from 'components/HelpText';
|
||||||
|
import Collection from 'models/Collection';
|
||||||
|
import CollectionsStore from 'stores/CollectionsStore';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
history: Object,
|
||||||
|
collection: Collection,
|
||||||
|
collections: CollectionsStore,
|
||||||
|
onSubmit: () => void,
|
||||||
|
};
|
||||||
|
|
||||||
|
@observer class CollectionDelete extends Component {
|
||||||
|
props: Props;
|
||||||
|
@observable isDeleting: boolean;
|
||||||
|
|
||||||
|
handleSubmit = async (ev: SyntheticEvent) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
this.isDeleting = true;
|
||||||
|
const success = await this.props.collection.delete();
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
this.props.collections.remove(this.props.collection.id);
|
||||||
|
this.props.history.push(homeUrl());
|
||||||
|
this.props.onSubmit();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isDeleting = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { collection } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex column>
|
||||||
|
<form onSubmit={this.handleSubmit}>
|
||||||
|
<HelpText>
|
||||||
|
Are you sure? Deleting the
|
||||||
|
{' '}
|
||||||
|
<strong>{collection.name}</strong>
|
||||||
|
{' '}
|
||||||
|
collection is permanant and will also delete all of the documents within
|
||||||
|
it, so be careful with that.
|
||||||
|
</HelpText>
|
||||||
|
<Button type="submit" danger>
|
||||||
|
{this.isDeleting ? 'Deleting…' : 'Delete'}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CollectionDelete;
|
3
frontend/scenes/CollectionDelete/index.js
Normal file
3
frontend/scenes/CollectionDelete/index.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// @flow
|
||||||
|
import CollectionDelete from './CollectionDelete';
|
||||||
|
export default CollectionDelete;
|
@ -2,7 +2,6 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { observable } from 'mobx';
|
import { observable } from 'mobx';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { homeUrl } from 'utils/routeHelpers';
|
|
||||||
import Button from 'components/Button';
|
import Button from 'components/Button';
|
||||||
import Input from 'components/Input';
|
import Input from 'components/Input';
|
||||||
import Flex from 'components/Flex';
|
import Flex from 'components/Flex';
|
||||||
@ -20,8 +19,6 @@ type Props = {
|
|||||||
@observer class CollectionEdit extends Component {
|
@observer class CollectionEdit extends Component {
|
||||||
props: Props;
|
props: Props;
|
||||||
@observable name: string;
|
@observable name: string;
|
||||||
@observable isConfirming: boolean;
|
|
||||||
@observable isDeleting: boolean;
|
|
||||||
@observable isSaving: boolean;
|
@observable isSaving: boolean;
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
@ -46,34 +43,12 @@ type Props = {
|
|||||||
this.name = ev.target.value;
|
this.name = ev.target.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
confirmDelete = () => {
|
|
||||||
this.isConfirming = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
cancelDelete = () => {
|
|
||||||
this.isConfirming = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
confirmedDelete = async (ev: SyntheticEvent) => {
|
|
||||||
ev.preventDefault();
|
|
||||||
this.isDeleting = true;
|
|
||||||
const success = await this.props.collection.delete();
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
this.props.collections.remove(this.props.collection.id);
|
|
||||||
this.props.history.push(homeUrl());
|
|
||||||
this.props.onSubmit();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isDeleting = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Flex column>
|
<Flex column>
|
||||||
<form onSubmit={this.handleSubmit}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
<HelpText>
|
<HelpText>
|
||||||
You can edit a collection name at any time, but doing so might
|
You can edit a collections name at any time, however doing so might
|
||||||
confuse your team mates.
|
confuse your team mates.
|
||||||
</HelpText>
|
</HelpText>
|
||||||
<Input
|
<Input
|
||||||
@ -91,26 +66,6 @@ type Props = {
|
|||||||
{this.isSaving ? 'Saving…' : 'Save'}
|
{this.isSaving ? 'Saving…' : 'Save'}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
<hr />
|
|
||||||
<form>
|
|
||||||
<HelpText>
|
|
||||||
Deleting a collection will also delete all of the documents within
|
|
||||||
it, so be careful with that.
|
|
||||||
</HelpText>
|
|
||||||
{!this.isConfirming &&
|
|
||||||
<Button type="submit" onClick={this.confirmDelete} neutral>
|
|
||||||
Delete…
|
|
||||||
</Button>}
|
|
||||||
{this.isConfirming &&
|
|
||||||
<span>
|
|
||||||
<Button type="submit" onClick={this.cancelDelete} neutral>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button type="submit" onClick={this.confirmedDelete} danger>
|
|
||||||
{this.isDeleting ? 'Deleting…' : 'Confirm Delete'}
|
|
||||||
</Button>
|
|
||||||
</span>}
|
|
||||||
</form>
|
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
59
frontend/scenes/DocumentDelete/DocumentDelete.js
Normal file
59
frontend/scenes/DocumentDelete/DocumentDelete.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// @flow
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { observable } from 'mobx';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
import { homeUrl } from 'utils/routeHelpers';
|
||||||
|
import Button from 'components/Button';
|
||||||
|
import Flex from 'components/Flex';
|
||||||
|
import HelpText from 'components/HelpText';
|
||||||
|
import Document from 'models/Document';
|
||||||
|
import DocumentsStore from 'stores/DocumentsStore';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
history: Object,
|
||||||
|
document: Document,
|
||||||
|
documents: DocumentsStore,
|
||||||
|
onSubmit: () => void,
|
||||||
|
};
|
||||||
|
|
||||||
|
@observer class DocumentDelete extends Component {
|
||||||
|
props: Props;
|
||||||
|
@observable isDeleting: boolean;
|
||||||
|
|
||||||
|
handleSubmit = async (ev: SyntheticEvent) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
this.isDeleting = true;
|
||||||
|
const success = await this.props.document.delete();
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
this.props.documents.remove(this.props.document.id);
|
||||||
|
this.props.history.push(homeUrl());
|
||||||
|
this.props.onSubmit();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isDeleting = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { document } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex column>
|
||||||
|
<form onSubmit={this.handleSubmit}>
|
||||||
|
<HelpText>
|
||||||
|
Are you sure? Deleting the
|
||||||
|
{' '}
|
||||||
|
<strong>{document.title}</strong>
|
||||||
|
{' '}
|
||||||
|
document is permanant and will also delete all of its history.
|
||||||
|
</HelpText>
|
||||||
|
<Button type="submit" danger>
|
||||||
|
{this.isDeleting ? 'Deleting…' : 'Delete'}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DocumentDelete;
|
3
frontend/scenes/DocumentDelete/index.js
Normal file
3
frontend/scenes/DocumentDelete/index.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// @flow
|
||||||
|
import DocumentDelete from './DocumentDelete';
|
||||||
|
export default DocumentDelete;
|
Reference in New Issue
Block a user