react-toastify

master
Tudor Stanciu 2020-05-20 03:49:05 +03:00
parent 432efcffe3
commit 5e1ff70533
2 changed files with 13 additions and 3 deletions

View File

@ -6,10 +6,11 @@ export function saveMessageForAuthor(messageContent) {
return async function (dispatch, getState) { return async function (dispatch, getState) {
try { try {
const sessionId = getState().frontendSession.sessionId; const sessionId = getState().frontendSession.sessionId;
const data = await dispatch( const event = await dispatch(
sendHttpRequest(api.saveMessageForAuthor(sessionId, messageContent)) 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) { } catch (error) {
throw error; throw error;
} }

View File

@ -4,6 +4,7 @@ import { bindActionCreators } from "redux";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import MessageForAuthorDialog from "./MessageForAuthorDialog"; import MessageForAuthorDialog from "./MessageForAuthorDialog";
import { saveMessageForAuthor } from "../actionCreators"; import { saveMessageForAuthor } from "../actionCreators";
import { toast } from "react-toastify"; //replace with https://material-ui.com/components/snackbars/
const MessageForAuthorContainer = ({ actions, open, handleClose }) => { const MessageForAuthorContainer = ({ actions, open, handleClose }) => {
const [messageForAuthor, setMessageForAuthor] = useState(""); const [messageForAuthor, setMessageForAuthor] = useState("");
@ -14,7 +15,15 @@ const MessageForAuthorContainer = ({ actions, open, handleClose }) => {
}; };
const saveMessage = () => { 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(""); setMessageForAuthor("");
handleClose(); handleClose();
}; };