Skip to content

Saleor Core: the high performance, composable, headless commerce API.

wip

dominik-zeglen8416a2eabb70
diff --git a/saleor/static/dashboard-next/components/messages/MessageManager.tsx b/saleor/static/dashboard-next/components/messages/MessageManager.tsx
index bbb88c6b44..d09cf5ea6e 100644
--- a/saleor/static/dashboard-next/components/messages/MessageManager.tsx
+++ b/saleor/static/dashboard-next/components/messages/MessageManager.tsx
@@ -29,21 +29,21 @@ export class MessageManager extends React.Component<
if (reason === "clickaway") {
return;
}
- this.setState({ open: false });
+ this.setState({ opened: false });
};
handleExited = () => {
this.processQueue();
};
- pushMessage = (message: Message) => {
+ pushMessage = (message: Message) => () => {
this.queue.push({
key: new Date().getTime(),
message
});
if (this.state.opened) {
- this.setState({ open: false });
+ this.setState({ opened: false });
} else {
this.processQueue();
}
@@ -65,8 +65,8 @@ export class MessageManager extends React.Component<
<Snackbar
key={key}
anchorOrigin={{
- vertical: "top",
- horizontal: "right"
+ horizontal: "right",
+ vertical: "top"
}}
open={this.state.opened}
autoHideDuration={6000}
@@ -81,7 +81,7 @@ export class MessageManager extends React.Component<
key="undo"
color="secondary"
size="small"
- onClick={this.handleClose}
+ onClick={this.handleClose as any}
>
UNDO
</Button>,
@@ -89,8 +89,8 @@ export class MessageManager extends React.Component<
key="close"
aria-label="Close"
color="inherit"
- className={classes.close}
- onClick={this.handleClose}
+ // className={classes.close}
+ onClick={this.handleClose as any}
>
<CloseIcon />
</IconButton>
diff --git a/saleor/static/dashboard-next/components/messages/withMessages.tsx b/saleor/static/dashboard-next/components/messages/withMessages.tsx
index 08869a9f62..b0c3ecb94d 100644
--- a/saleor/static/dashboard-next/components/messages/withMessages.tsx
+++ b/saleor/static/dashboard-next/components/messages/withMessages.tsx
@@ -1,9 +1,18 @@
import * as React from "react";
-import { MessageContext } from ".";
+import { IMessage, MessageContext } from ".";
-export const withMessages = (Component: React.ReactNode) => props => (
+type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
+type Subtract<T, K> = Omit<T, keyof K>;
+interface InjectorProps {
+ pushMessage: (message: IMessage) => void;
+}
+
+export const withMessages = <T extends InjectorProps>(
+ Component: React.ComponentType<T>
+): React.StatelessComponent<Subtract<T, InjectorProps>> => props => (
<MessageContext.Consumer>
{pushMessage => <Component {...props} pushMessage={pushMessage} />}
</MessageContext.Consumer>
);
+export default withMessages;
diff --git a/saleor/static/dashboard-next/storybook/Decorator.tsx b/saleor/static/dashboard-next/storybook/Decorator.tsx
index ebf930826a..c483a2d0d0 100644
--- a/saleor/static/dashboard-next/storybook/Decorator.tsx
+++ b/saleor/static/dashboard-next/storybook/Decorator.tsx
@@ -2,12 +2,15 @@ import CssBaseline from "@material-ui/core/CssBaseline";
import MuiThemeProvider from "@material-ui/core/styles/MuiThemeProvider";
import * as React from "react";
+import { MessageManager } from "../components/messages";
import theme from "../theme";
export const Decorator = storyFn => (
- <MuiThemeProvider theme={theme}>
- <CssBaseline />
- {storyFn()}
- </MuiThemeProvider>
+ <MessageManager>
+ <MuiThemeProvider theme={theme}>
+ <CssBaseline />
+ {storyFn()}
+ </MuiThemeProvider>
+ </MessageManager>
);
export default Decorator;
diff --git a/saleor/static/dashboard-next/storybook/stories/components/messages.tsx b/saleor/static/dashboard-next/storybook/stories/components/messages.tsx
index 32748e4598..17918d66fc 100644
--- a/saleor/static/dashboard-next/storybook/stories/components/messages.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/components/messages.tsx
@@ -1,10 +1,29 @@
+import Button from "@material-ui/core/Button";
import { storiesOf } from "@storybook/react";
import * as React from "react";
-import messages from "../../../components/messages";
+import withMessages from "../../../components/messages";
import Decorator from "../../Decorator";
storiesOf("Components / messages", module)
.addDecorator(Decorator)
- .add("default", () => <messages />)
- .add("other", () => <messages />);
+ .add("default", () =>
+ withMessages(pushMessage => (
+ <Button
+ onClick={pushMessage({ text: "This is message" })}
+ variant="raised"
+ >
+ Push message
+ </Button>
+ ))
+ )
+ .add("other", () =>
+ withMessages(pushMessage => (
+ <Button
+ onClick={pushMessage({ text: "This is message", onUndo: () => {} })}
+ variant="raised"
+ >
+ Push message
+ </Button>
+ ))
+ );