Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Integrate global messages with product detail view
dominik-zeglen60fe7966b0b7
diff --git a/saleor/static/dashboard-next/components/messages/MessageManager.tsx b/saleor/static/dashboard-next/components/messages/MessageManager.tsxindex 19eab61c1a..33983aa076 100644--- a/saleor/static/dashboard-next/components/messages/MessageManager.tsx+++ b/saleor/static/dashboard-next/components/messages/MessageManager.tsx@@ -36,7 +36,7 @@ export class MessageManager extends React.Component<this.processQueue();};- pushMessage = (message: Message) => (event: any) => {+ pushMessage = (message: Message) => {this.queue.push({key: new Date().getTime(),...message@@ -69,7 +69,7 @@ export class MessageManager extends React.Component<vertical: "top"}}open={this.state.opened}- autoHideDuration={5000}+ autoHideDuration={3000}onClose={this.handleClose}onExited={this.handleExited}ContentProps={{diff --git a/saleor/static/dashboard-next/components/messages/index.ts b/saleor/static/dashboard-next/components/messages/index.tsindex e53a37d920..c671ee3362 100644--- a/saleor/static/dashboard-next/components/messages/index.ts+++ b/saleor/static/dashboard-next/components/messages/index.ts@@ -4,10 +4,7 @@ export interface IMessage {text: string;onUndo?: () => void;}-export const MessageContext = createContext(- (message: IMessage) => (event: any) => {}-);+export const MessageContext = createContext((message: IMessage) => {});export * from "./MessageManager";-export * from "./withMessages";-export { default } from "./withMessages";+export default MessageContext.Consumer;diff --git a/saleor/static/dashboard-next/components/messages/withMessages.tsx b/saleor/static/dashboard-next/components/messages/withMessages.tsxdeleted file mode 100644index 66ab74dd77..0000000000--- a/saleor/static/dashboard-next/components/messages/withMessages.tsx+++ /dev/null@@ -1,18 +0,0 @@-import * as React from "react";--import { IMessage, MessageContext } from ".";--type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;-type Subtract<T, K> = Omit<T, keyof K>;-interface InjectorProps {- pushMessage: (message: IMessage) => (event: any) => 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/index.tsx b/saleor/static/dashboard-next/index.tsxindex 7848bca428..1e8faede35 100644--- a/saleor/static/dashboard-next/index.tsx+++ b/saleor/static/dashboard-next/index.tsx@@ -13,6 +13,7 @@ import * as Cookies from "universal-cookie";import AppRoot from "./AppRoot";import CategorySection from "./categories";+import { MessageManager } from "./components/messages";import "./i18n";import PageSection from "./pages";import ProductSection from "./products";@@ -37,14 +38,16 @@ render(<ApolloProvider client={apolloClient}><BrowserRouter basename="/dashboard/next/"><MuiThemeProvider theme={theme}>- <CssBaseline />- <AppRoot>- <Switch>- <Route path="/categories" component={CategorySection} />- <Route path="/pages" component={PageSection} />- <Route path="/products" component={ProductSection} />- </Switch>- </AppRoot>+ <MessageManager>+ <CssBaseline />+ <AppRoot>+ <Switch>+ <Route path="/categories" component={CategorySection} />+ <Route path="/pages" component={PageSection} />+ <Route path="/products" component={ProductSection} />+ </Switch>+ </AppRoot>+ </MessageManager></MuiThemeProvider></BrowserRouter></ApolloProvider>@@ -66,12 +69,31 @@ export interface PageListProps extends ListProps {onAdd: () => void;}-export interface MutationProviderChildrenRenderProps<+export interface MutationProviderProps<T extends {}> {+ onSuccess?: (data: T) => void;+ onError?: (error: ApolloError) => void;+}+export interface MutationProviderPartialOutput<+ TData extends {} = {},+ TVariables extends {} = {}+> {+ data: TData;+ loading: boolean;+ mutate: (variables: TVariables) => void;+}+export interface MutationProviderOutput<+ TData extends {} = {},+ TVariables extends {} = {}+> extends MutationProviderPartialOutput<TData, TVariables> {+ error: ApolloError;+}++export interface MutationProviderRenderProps<TData extends {} = {},TVariables extends {} = {}> {+ data: TData;loading: boolean;- called: boolean;error?: ApolloError;mutate: MutationFn<TData, TVariables>;}diff --git a/saleor/static/dashboard-next/products/containers/ProductImagesReorder.tsx b/saleor/static/dashboard-next/products/containers/ProductImagesReorder.tsxindex 5d1ca16bca..c322673bb1 100644--- a/saleor/static/dashboard-next/products/containers/ProductImagesReorder.tsx+++ b/saleor/static/dashboard-next/products/containers/ProductImagesReorder.tsx@@ -8,13 +8,14 @@ import {} from "../../gql-types";import { productImagesReorder, TypedProductImagesReorder } from "../mutations";-import { MutationProviderChildrenRenderProps } from "../..";+import { MutationProviderProps, MutationProviderRenderProps } from "../..";import { productDetailsQuery } from "../queries";-interface ProductImagesReorderProviderProps {+interface ProductImagesReorderProviderProps+ extends MutationProviderProps<ProductImageReorderMutation> {productId: string;children: ((- props: MutationProviderChildrenRenderProps<+ props: MutationProviderRenderProps<ProductImageReorderMutation,ProductImageReorderMutationVariables>@@ -23,9 +24,11 @@ interface ProductImagesReorderProviderProps {const ProductImagesReorderProvider: React.StatelessComponent<ProductImagesReorderProviderProps-> = ({ productId, children }) => (+> = ({ productId, children, onError, onSuccess }) => (<TypedProductImagesReordermutation={productImagesReorder}+ onCompleted={onSuccess}+ onError={onError}update={(cache, { data: { productImageReorder } }) => {const data: ProductDetailsQuery = cache.readQuery({query: productDetailsQuery,@@ -37,12 +40,12 @@ const ProductImagesReorderProvider: React.StatelessComponent<cache.writeQuery({ query: productDetailsQuery, data });}}>- {(mutate, { called, error, loading }) => {+ {(mutate, { data, error, loading }) => {if (error) {return <ErrorMessageCard message={error.message} />;}return children({- called,+ data,error,loading,mutatediff --git a/saleor/static/dashboard-next/products/containers/ProductUpdate.tsx b/saleor/static/dashboard-next/products/containers/ProductUpdate.tsxindex 38eeef9266..110538be44 100644--- a/saleor/static/dashboard-next/products/containers/ProductUpdate.tsx+++ b/saleor/static/dashboard-next/products/containers/ProductUpdate.tsx@@ -1,6 +1,6 @@import * as React from "react";-import { MutationProviderChildrenRenderProps } from "../..";+import { MutationProviderProps, MutationProviderRenderProps } from "../..";import ErrorMessageCard from "../../components/ErrorMessageCard";import {ProductDetailsQuery,@@ -13,10 +13,11 @@ import {} from "../mutations";import { productDetailsQuery } from "../queries";-interface ProductUpdateProviderProps {+interface ProductUpdateProviderProps+ extends MutationProviderProps<ProductUpdateMutation> {productId: string;children: ((- props: MutationProviderChildrenRenderProps<+ props: MutationProviderRenderProps<ProductUpdateMutation,ProductUpdateMutationVariables>@@ -25,9 +26,11 @@ interface ProductUpdateProviderProps {const ProductUpdateProvider: React.StatelessComponent<ProductUpdateProviderProps-> = ({ productId, children }) => (+> = ({ productId, children, onError, onSuccess }) => (<TypedProductUpdateMutationmutation={productUpdateMutation}+ onCompleted={onSuccess}+ onError={onError}update={(cache, { data: { productUpdate } }) => {const data: ProductDetailsQuery = cache.readQuery({query: productDetailsQuery,@@ -37,12 +40,12 @@ const ProductUpdateProvider: React.StatelessComponent<cache.writeQuery({ query: productDetailsQuery, data });}}>- {(mutate, { called, error, loading }) => {+ {(mutate, { data, error, loading }) => {if (error) {return <ErrorMessageCard message={error.message} />;}return children({- called,+ data,error,loading,mutatediff --git a/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx b/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsxindex c6541b3a3d..4fc39cc8a4 100644--- a/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx+++ b/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx@@ -1,8 +1,10 @@import * as React from "react";-import { Redirect } from "react-router-dom";-import { ApolloError } from "apollo-client";-import { MutationProviderChildrenRenderProps } from "../..";+import {+ MutationProviderPartialOutput,+ MutationProviderProps,+ MutationProviderRenderProps+} from "../..";import ErrorMessageCard from "../../components/ErrorMessageCard";import {ProductDeleteMutation,@@ -10,10 +12,11 @@ import {ProductDetailsQuery,ProductImageCreateMutation,ProductImageCreateMutationVariables,+ ProductImageReorderMutation,ProductImageReorderMutationVariables,+ ProductUpdateMutation,ProductUpdateMutationVariables} from "../../gql-types";-import { productListUrl } from "../index";import {productDeleteMutation,productImageCreateMutation,@@ -24,10 +27,11 @@ import { productDetailsQuery } from "../queries";import ProductImagesReorderProvider from "./ProductImagesReorder";import ProductUpdateProvider from "./ProductUpdate";-interface ProductDeleteProviderProps {+interface ProductDeleteProviderProps+ extends MutationProviderProps<ProductDeleteMutation> {productId: string;children: ((- props: MutationProviderChildrenRenderProps<+ props: MutationProviderRenderProps<ProductDeleteMutation,ProductDeleteMutationVariables>@@ -36,20 +40,19 @@ interface ProductDeleteProviderProps {const ProductDeleteProvider: React.StatelessComponent<ProductDeleteProviderProps-> = ({ productId, children }) => (+> = ({ productId, children, onError, onSuccess }) => (<TypedProductDeleteMutationmutation={productDeleteMutation}variables={{ id: productId }}+ onCompleted={onSuccess}+ onError={onError}>- {(mutate, { called, error, loading }) => {+ {(mutate, { data, error, loading }) => {if (error) {return <ErrorMessageCard message={error.message} />;}- if (called && !loading) {- return <Redirect to={productListUrl} push={false} />;- }return children({- called,+ data,error,loading,mutate@@ -58,10 +61,11 @@ const ProductDeleteProvider: React.StatelessComponent<</TypedProductDeleteMutation>);-interface ProductImageCreateProviderProps {+interface ProductImageCreateProviderProps+ extends MutationProviderProps<ProductImageCreateMutation> {productId: string;children: ((- props: MutationProviderChildrenRenderProps<+ props: MutationProviderRenderProps<ProductImageCreateMutation,ProductImageCreateMutationVariables>@@ -70,7 +74,7 @@ interface ProductImageCreateProviderProps {const ProductImageCreateProvider: React.StatelessComponent<ProductImageCreateProviderProps-> = ({ productId, children }) => (+> = ({ productId, children, onError, onSuccess }) => (<TypedProductImageCreateMutationmutation={productImageCreateMutation}update={(cache, { data: { productImageCreate } }) => {@@ -85,13 +89,15 @@ const ProductImageCreateProvider: React.StatelessComponent<data.product.images.edges.push(edge);cache.writeQuery({ query: productDetailsQuery, data });}}+ onCompleted={onSuccess}+ onError={onError}>- {(mutate, { called, error, loading }) => {+ {(mutate, { data, error, loading }) => {if (error) {return <ErrorMessageCard message={error.message} />;}return children({- called,+ data,error,loading,mutate@@ -100,76 +106,110 @@ const ProductImageCreateProvider: React.StatelessComponent<</TypedProductImageCreateMutation>);-interface ProductUpdateOperationsProps {+interface ProductUpdateOperationsProps+ extends MutationProviderProps<ProductImageCreateMutation> {product?: ProductDetailsQuery["product"];children: (props: {- error: ApolloError;- loading: boolean;- createProductImage(variables: ProductImageCreateMutationVariables): void;- deleteProduct(): void;- reorderProductImages(- variables: ProductImageReorderMutationVariables- ): void;- updateProduct(variables: ProductUpdateMutationVariables): void;+ createProductImage: MutationProviderPartialOutput<+ ProductImageCreateMutation,+ ProductImageCreateMutationVariables+ >;+ deleteProduct: MutationProviderPartialOutput;+ reorderProductImages: Exclude<+ MutationProviderPartialOutput<+ ProductImageReorderMutation,+ ProductImageReorderMutationVariables+ >,+ { error: any }+ >;+ updateProduct: MutationProviderPartialOutput<+ ProductUpdateMutation,+ ProductUpdateMutationVariables+ >;}) => React.ReactElement<any>;+ onDelete?: (data: ProductDeleteMutation) => void;+ onImageCreate?: (data: ProductImageCreateMutation) => void;+ onImageReorder?: (data: ProductImageReorderMutation) => void;+ onUpdate?: (data: ProductUpdateMutation) => void;}const ProductUpdateOperations: React.StatelessComponent<ProductUpdateOperationsProps-> = ({ product, children }) => {+> = ({+ product,+ children,+ onDelete,+ onImageCreate,+ onImageReorder,+ onUpdate+}) => {const productId = product ? product.id : "";return (- <ProductUpdateProvider productId={productId}>+ <ProductUpdateProvider productId={productId} onSuccess={onUpdate}>{updateProduct => (- <ProductImagesReorderProvider productId={productId}>+ <ProductImagesReorderProvider+ productId={productId}+ onSuccess={onImageReorder}+ >{reorderProductImages => (- <ProductImageCreateProvider productId={productId}>+ <ProductImageCreateProvider+ productId={productId}+ onSuccess={onImageCreate}+ >{createProductImage => (- <ProductDeleteProvider productId={productId}>+ <ProductDeleteProvider+ productId={productId}+ onSuccess={onDelete}+ >{deleteProduct =>children({- createProductImage: variables =>- createProductImage.mutate({ variables }),- deleteProduct: deleteProduct.mutate,- error:- updateProduct.error ||- reorderProductImages.error ||- createProductImage.error ||- deleteProduct.error,- loading:- updateProduct.loading ||- reorderProductImages.loading ||- createProductImage.loading ||- deleteProduct.loading,- reorderProductImages: variables => {- const imagesMap = {};- product.images.edges.forEach(edge => {- const image = edge.node;- imagesMap[image.id] = image;- });- const productImages = variables.imagesIds.map(- (id, index) => ({- __typename: "ProductImage",- ...imagesMap[id],- sortOrder: index- })- );- const optimisticResponse = {- productImageReorder: {- __typename: "ProductImageReorder",- errors: null,- productImages- }- };- reorderProductImages.mutate({- optimisticResponse,- variables- });+ createProductImage: {+ data: createProductImage.data,+ loading: createProductImage.loading,+ mutate: variables =>+ createProductImage.mutate({ variables })+ },+ deleteProduct: {+ data: deleteProduct.data,+ loading: deleteProduct.loading,+ mutate: deleteProduct.mutate+ },+ reorderProductImages: {+ data: reorderProductImages.data,+ loading: reorderProductImages.loading,+ mutate: variables => {+ const imagesMap = {};+ product.images.edges.forEach(edge => {+ const image = edge.node;+ imagesMap[image.id] = image;+ });+ const productImages = variables.imagesIds.map(+ (id, index) => ({+ __typename: "ProductImage",+ ...imagesMap[id],+ sortOrder: index+ })+ );+ const optimisticResponse = {+ productImageReorder: {+ __typename: "ProductImageReorder",+ errors: null,+ productImages+ }+ };+ reorderProductImages.mutate({+ optimisticResponse,+ variables+ });+ }},- updateProduct: variables =>- updateProduct.mutate({ variables })+ updateProduct: {+ data: updateProduct.data,+ loading: updateProduct.loading,+ mutate: variables => updateProduct.mutate({ variables })+ }})}</ProductDeleteProvider>diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsxindex ce14894202..35c97f512b 100644--- a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx@@ -2,8 +2,11 @@ import * as React from "react";import { arrayMove } from "react-sortable-hoc";import * as placeholderImg from "../../../images/placeholder255x255.png";+import { categoryShowUrl } from "../../categories";import ErrorMessageCard from "../../components/ErrorMessageCard";+import Messages from "../../components/messages";import Navigator from "../../components/Navigator";+import i18n from "../../i18n";import ProductUpdatePage from "../components/ProductUpdatePage";import ProductUpdateOperations from "../containers/ProductUpdateOperations";import { productListUrl, productVariantEditUrl } from "../index";@@ -16,141 +19,172 @@ interface ProductUpdateProps {export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({id}) => (- <Navigator>- {navigate => {+ <Messages>+ {pushMessage => {return (- <TypedProductDetailsQuery- query={productDetailsQuery}- variables={{ id }}- fetchPolicy="network-only"- >- {({ data, loading, error, fetchMore }) => {- if (error) {- return <ErrorMessageCard message="Something went wrong" />;- }+ <Navigator>+ {navigate => {+ return (+ <TypedProductDetailsQuery+ query={productDetailsQuery}+ variables={{ id }}+ fetchPolicy="network-only"+ >+ {({ data, loading, error, fetchMore }) => {+ if (error) {+ return <ErrorMessageCard message="Something went wrong" />;+ }- const product = data ? data.product : undefined;- const allCollections =- data && data.collections- ? data.collections.edges.map(edge => edge.node)- : [];- const allCategories =- data && data.categories- ? data.categories.edges.map(edge => edge.node)- : [];- const images =- data && data.product- ? data.product.images.edges.map(edge => edge.node)- : undefined;+ const handleDelete = () => {+ pushMessage({ text: i18n.t("Product removed") });+ navigate(categoryShowUrl(data.product.category.id));+ };+ const handleUpdate = () =>+ pushMessage({ text: i18n.t("Saved changes") });+ const handleImageCreate = () =>+ pushMessage({+ text: i18n.t("Image successfully uploaded")+ });+ const product = data ? data.product : undefined;+ const allCollections =+ data && data.collections+ ? data.collections.edges.map(edge => edge.node)+ : [];+ const allCategories =+ data && data.categories+ ? data.categories.edges.map(edge => edge.node)+ : [];+ const images =+ data && data.product+ ? data.product.images.edges.map(edge => edge.node)+ : undefined;- return (- <ProductUpdateOperations product={product}>- {({- createProductImage,- deleteProduct,- error,- loading,- reorderProductImages,- updateProduct- }) => {return (- <ProductUpdatePage- categories={allCategories}- collections={allCollections}- disabled={loading}- saveButtonBarState={loading ? "loading" : "idle"}- images={images}- placeholderImage={placeholderImg}+ <ProductUpdateOperationsproduct={product}- productCollections={- product && product.collections- ? product.collections.edges.map(edge => edge.node)- : undefined- }- variants={- product && product.variants- ? product.variants.edges.map(edge => edge.node)- : undefined- }- onBack={() => {- navigate(productListUrl);- }}- onDelete={deleteProduct}- onProductShow={() => {- if (product) {- window.open(product.url);- }- }}- onImageReorder={({ newIndex, oldIndex }) => {- if (product) {- let ids = images.map(image => image.id);- ids = arrayMove(ids, oldIndex, newIndex);- reorderProductImages({- imagesIds: ids,- productId: product.id- });- }- }}- onSubmit={data => {- if (product) {- const attributes = product.attributes- .map(item => ({- slug: item.attribute.slug,- values: item.attribute.values- }))- .map(({ slug, values }) => {- const valueSlug = data[slug];- const value = values.filter(- item => item.slug === valueSlug- );- return {- slug,- value: value ? value[0].name : valueSlug- };- });+ onDelete={handleDelete}+ onImageCreate={handleImageCreate}+ onUpdate={handleUpdate}+ >+ {({+ createProductImage,+ deleteProduct,+ reorderProductImages,+ updateProduct+ }) => {+ const disableFormSave =+ createProductImage.loading ||+ deleteProduct.loading ||+ reorderProductImages.loading ||+ updateProduct.loading;+ const formSubmitState = disableFormSave+ ? "loading"+ : "idle";+ return (+ <ProductUpdatePage+ categories={allCategories}+ collections={allCollections}+ disabled={disableFormSave}+ saveButtonBarState={formSubmitState}+ images={images}+ placeholderImage={placeholderImg}+ product={product}+ productCollections={+ product && product.collections+ ? product.collections.edges.map(+ edge => edge.node+ )+ : undefined+ }+ variants={+ product && product.variants+ ? product.variants.edges.map(edge => edge.node)+ : undefined+ }+ onBack={() => {+ navigate(productListUrl);+ }}+ onDelete={deleteProduct.mutate}+ onProductShow={() => {+ if (product) {+ window.open(product.url);+ }+ }}+ onImageReorder={({ newIndex, oldIndex }) => {+ if (product) {+ let ids = images.map(image => image.id);+ ids = arrayMove(ids, oldIndex, newIndex);+ reorderProductImages.mutate({+ imagesIds: ids,+ productId: product.id+ });+ }+ }}+ onSubmit={data => {+ if (product) {+ const attributes = product.attributes+ .map(item => ({+ slug: item.attribute.slug,+ values: item.attribute.values+ }))+ .map(({ slug, values }) => {+ const valueSlug = data[slug];+ const value = values.filter(+ item => item.slug === valueSlug+ );+ return {+ slug,+ value: value ? value[0].name : valueSlug+ };+ });- updateProduct({- attributes,- availableOn:- data.availableOn !== "" ? data.availableOn : null,- category: data.category,- chargeTaxes: data.chargeTaxes,- collections: data.collections,- description: data.description,- id: product.id,- isFeatured: data.featured,- isPublished: data.available,- name: data.name,- price: data.price- });- }- }}- onVariantAdd={() => {}}- onVariantShow={variantId => {- if (product) {- navigate(- productVariantEditUrl(product.id, variantId)- );- }- }}- onImageUpload={event => {- if (product) {- createProductImage({- alt: "",- image: event.target.files[0],- product: product.id- });- }+ updateProduct.mutate({+ attributes,+ availableOn:+ data.availableOn !== ""+ ? data.availableOn+ : null,+ category: data.category,+ chargeTaxes: data.chargeTaxes,+ collections: data.collections,+ description: data.description,+ id: product.id,+ isFeatured: data.featured,+ isPublished: data.available,+ name: data.name,+ price: data.price+ });+ }+ }}+ onVariantAdd={() => {}}+ onVariantShow={variantId => {+ if (product) {+ navigate(+ productVariantEditUrl(product.id, variantId)+ );+ }+ }}+ onImageUpload={event => {+ if (product) {+ createProductImage.mutate({+ alt: "",+ image: event.target.files[0],+ product: product.id+ });+ }+ }}+ />+ );}}- />+ </ProductUpdateOperations>);}}- </ProductUpdateOperations>+ </TypedProductDetailsQuery>);}}- </TypedProductDetailsQuery>+ </Navigator>);}}- </Navigator>+ </Messages>);export default ProductUpdate;diff --git a/saleor/static/dashboard-next/storybook/stories/components/messages.tsx b/saleor/static/dashboard-next/storybook/stories/components/messages.tsxindex 8e46e9afed..f5e752f69e 100644--- a/saleor/static/dashboard-next/storybook/stories/components/messages.tsx+++ b/saleor/static/dashboard-next/storybook/stories/components/messages.tsx@@ -2,32 +2,36 @@ import Button from "@material-ui/core/Button";import { storiesOf } from "@storybook/react";import * as React from "react";-import withMessages from "../../../components/messages";+import Messages from "../../../components/messages";import Decorator from "../../Decorator";storiesOf("Generics / Global messages", module).addDecorator(Decorator)- .add(- "default",- withMessages(({ pushMessage }) => (- <Button- color="primary"- variant="raised"- onClick={pushMessage({ text: "This is message" })}- >- Push message- </Button>- ))- )- .add(- "with undo action",- withMessages(({ pushMessage }) => (- <Button- color="primary"- variant="raised"- onClick={pushMessage({ text: "This is message", onUndo: () => {} })}- >- Push message- </Button>- ))- );+ .add("default", () => (+ <Messages>+ {pushMessage => (+ <Button+ color="primary"+ variant="raised"+ onClick={() => pushMessage({ text: "This is message" })}+ >+ Push message+ </Button>+ )}+ </Messages>+ ))+ .add("with undo action", () => (+ <Messages>+ {pushMessage => (+ <Button+ color="primary"+ variant="raised"+ onClick={() =>+ pushMessage({ text: "This is message", onUndo: () => {} })+ }+ >+ Push message+ </Button>+ )}+ </Messages>+ ));