react-toastify
parent
432efcffe3
commit
5e1ff70533
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue