fix: Separate toasts storage to own MobX store (#2339)

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Saumya Pandey
2021-07-20 14:36:10 +05:30
committed by GitHub
parent f64ab37d3c
commit fdb85ec195
45 changed files with 297 additions and 231 deletions

View File

@@ -11,6 +11,7 @@ import type { RouterHistory, Match } from "react-router-dom";
import styled from "styled-components";
import breakpoint from "styled-components-breakpoint";
import AuthStore from "stores/AuthStore";
import ToastsStore from "stores/ToastsStore";
import UiStore from "stores/UiStore";
import Document from "models/Document";
import Revision from "models/Revision";
@@ -59,6 +60,7 @@ type Props = {
theme: Theme,
auth: AuthStore,
ui: UiStore,
toasts: ToastsStore,
t: TFunction,
};
@@ -89,8 +91,10 @@ class DocumentScene extends React.Component<Props> {
}
} else if (prevProps.document.revision !== this.lastRevision) {
if (auth.user && document.updatedBy.id !== auth.user.id) {
this.props.ui.showToast(
t(`Document updated by ${document.updatedBy.name}`),
this.props.toasts.showToast(
t(`Document updated by {{userName}}`, {
userName: document.updatedBy.name,
}),
{
timeout: 30 * 1000,
type: "warning",
@@ -230,7 +234,7 @@ class DocumentScene extends React.Component<Props> {
this.props.ui.setActiveDocument(savedDocument);
}
} catch (err) {
this.props.ui.showToast(err.message, { type: "error" });
this.props.toasts.showToast(err.message, { type: "error" });
} finally {
this.isSaving = false;
this.isPublishing = false;
@@ -525,6 +529,6 @@ const MaxWidth = styled(Flex)`
export default withRouter(
withTranslation()<DocumentScene>(
inject("ui", "auth", "policies", "revisions")(DocumentScene)
inject("ui", "auth", "policies", "revisions", "toasts")(DocumentScene)
)
);