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/CollectionDelete.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-09-10 05:51:22 +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-09-10 05:51:22 +00:00
import { observable } from 'mobx';
2017-09-12 06:41:12 +00:00
import { inject, observer } from 'mobx-react';
2017-09-10 05:51:22 +00:00
import { homeUrl } from 'utils/routeHelpers';
import Button from 'components/Button';
import Flex from 'shared/components/Flex';
2017-09-10 05:51:22 +00:00
import HelpText from 'components/HelpText';
import Collection from 'models/Collection';
import CollectionsStore from 'stores/CollectionsStore';
import UiStore from 'stores/UiStore';
2017-09-10 05:51:22 +00:00
type Props = {
history: Object,
collection: Collection,
collections: CollectionsStore,
ui: UiStore,
2017-09-10 05:51:22 +00:00
onSubmit: () => void,
};
2017-11-10 22:14:30 +00:00
@observer
2018-05-05 23:16:08 +00:00
class CollectionDelete extends React.Component<Props> {
2017-09-10 05:51:22 +00:00
@observable isDeleting: boolean;
2018-05-05 23:16:08 +00:00
handleSubmit = async (ev: SyntheticEvent<*>) => {
2017-09-10 05:51:22 +00:00
ev.preventDefault();
this.isDeleting = true;
try {
await this.props.collection.delete();
2017-09-10 05:51:22 +00:00
this.props.history.push(homeUrl());
this.props.onSubmit();
} catch (err) {
this.props.ui.showToast(err.message);
} finally {
this.isDeleting = false;
2017-09-10 05:51:22 +00:00
}
};
render() {
const { collection } = this.props;
return (
<Flex column>
<form onSubmit={this.handleSubmit}>
<HelpText>
Are you sure about that? Deleting the{' '}
<strong>{collection.name}</strong> collection is permanent and will
also delete all of the documents within it, so be extra careful.
2017-09-10 05:51:22 +00:00
</HelpText>
<Button type="submit" danger>
{this.isDeleting ? 'Deleting…' : 'Im sure  Delete'}
2017-09-10 05:51:22 +00:00
</Button>
</form>
</Flex>
);
}
}
export default inject('collections', 'ui')(withRouter(CollectionDelete));