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

73 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-09-10 05:51:22 +00:00
// @flow
import * as React from "react";
import { withRouter, type RouterHistory } from "react-router-dom";
import { observable } from "mobx";
import { inject, observer } from "mobx-react";
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";
import UiStore from "stores/UiStore";
import { collectionUrl } from "utils/routeHelpers";
2017-09-10 05:51:22 +00:00
type Props = {
history: RouterHistory,
2017-09-10 05:51:22 +00:00
document: Document,
documents: DocumentsStore,
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 DocumentDelete extends React.Component<Props> {
2017-09-10 05:51:22 +00:00
@observable isDeleting: boolean;
handleSubmit = async (ev: SyntheticEvent<>) => {
2017-09-10 05:51:22 +00:00
ev.preventDefault();
this.isDeleting = true;
try {
await this.props.document.delete();
if (this.props.ui.activeDocumentId === this.props.document.id) {
this.props.history.push(
collectionUrl(this.props.document.collectionId)
);
}
2017-09-10 05:51:22 +00:00
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 { document } = this.props;
return (
<Flex column>
<form onSubmit={this.handleSubmit}>
<HelpText>
Are you sure about that? Deleting the{" "}
<strong>{document.titleWithDefault}</strong> {document.noun} will
delete all of its history
{document.isTemplate ? "" : ", and any nested documents"}.
2017-09-10 05:51:22 +00:00
</HelpText>
{!document.isDraft && !document.isArchived && (
<HelpText>
If youd like the option of referencing or restoring this{" "}
{document.noun} in the future, consider archiving it instead.
</HelpText>
)}
2017-09-10 05:51:22 +00:00
<Button type="submit" danger>
{this.isDeleting ? "Deleting…" : "Im sure  Delete"}
2017-09-10 05:51:22 +00:00
</Button>
</form>
</Flex>
);
}
}
export default inject("documents", "ui")(withRouter(DocumentDelete));