From 5e1ff70533522d56d3c718c16b9960168650379b Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 20 May 2020 03:49:05 +0300 Subject: [PATCH] react-toastify --- src/features/messageForAuthor/actionCreators.js | 5 +++-- .../components/MessageForAuthorContainer.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/features/messageForAuthor/actionCreators.js b/src/features/messageForAuthor/actionCreators.js index d7dd6df..2a5a351 100644 --- a/src/features/messageForAuthor/actionCreators.js +++ b/src/features/messageForAuthor/actionCreators.js @@ -6,10 +6,11 @@ export function saveMessageForAuthor(messageContent) { return async function (dispatch, getState) { try { const sessionId = getState().frontendSession.sessionId; - const data = await dispatch( + const event = await dispatch( sendHttpRequest(api.saveMessageForAuthor(sessionId, messageContent)) ); - dispatch({ type: types.SAVE_MESSAGE_FOR_AUTHOR_SUCCESS, payload: data }); + dispatch({ type: types.SAVE_MESSAGE_FOR_AUTHOR_SUCCESS, payload: event }); + return event; } catch (error) { throw error; } diff --git a/src/features/messageForAuthor/components/MessageForAuthorContainer.js b/src/features/messageForAuthor/components/MessageForAuthorContainer.js index 440a0cd..e2a721a 100644 --- a/src/features/messageForAuthor/components/MessageForAuthorContainer.js +++ b/src/features/messageForAuthor/components/MessageForAuthorContainer.js @@ -4,6 +4,7 @@ import { bindActionCreators } from "redux"; import PropTypes from "prop-types"; import MessageForAuthorDialog from "./MessageForAuthorDialog"; import { saveMessageForAuthor } from "../actionCreators"; +import { toast } from "react-toastify"; //replace with https://material-ui.com/components/snackbars/ const MessageForAuthorContainer = ({ actions, open, handleClose }) => { const [messageForAuthor, setMessageForAuthor] = useState(""); @@ -14,7 +15,15 @@ const MessageForAuthorContainer = ({ actions, open, handleClose }) => { }; const saveMessage = () => { - actions.saveMessageForAuthor(messageForAuthor); + actions + .saveMessageForAuthor(messageForAuthor) + .then((event) => { + if (event.success) toast.success("Message saved."); + else toast.error(event.message); + }) + .catch((error) => { + toast.error(error); + }); setMessageForAuthor(""); handleClose(); };