2020-06-24 11:44:35 +00:00
|
|
|
import { IMessage } from "@saleor/components/messages";
|
2020-06-30 17:41:43 +00:00
|
|
|
import { IMessageContext, MessageContext } from "@saleor/components/messages";
|
2020-06-30 19:32:20 +00:00
|
|
|
import { useContext } from "react";
|
2020-06-30 17:41:43 +00:00
|
|
|
|
|
|
|
export type UseNotifierResult = IMessageContext;
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
function useNotifier(): UseNotifierResult {
|
2020-06-30 17:41:43 +00:00
|
|
|
const notificationContext = useContext(MessageContext);
|
|
|
|
|
2020-06-24 11:44:35 +00:00
|
|
|
const notify = (options: IMessage) => {
|
2020-07-02 12:44:03 +00:00
|
|
|
const timeout = options.status === "error" ? null : options.autohide;
|
|
|
|
notificationContext.show(options, timeout);
|
2020-06-24 11:44:35 +00:00
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
return notify;
|
|
|
|
}
|
|
|
|
export default useNotifier;
|