qcast-front/src/hooks/useToast.js

36 lines
870 B
JavaScript

import { toast } from 'react-toastify'
const toastDefaultOptions = {
position: 'top-right',
autoClose: 3000,
draggable: false,
hideProgressBar: false,
rtl: false,
pauseOnFocusLoss: true,
pauseOnHover: true,
theme: 'light',
limit: 2,
closeOnClick: true,
}
const toastUp = (props) => {
// type TypeOptions = 'info' | 'success' | 'warning' | 'error' | 'default'
const { message, type = 'info', options } = props
const customOptions = { ...toastDefaultOptions, ...options }
switch (type) {
case 'info':
return toast.info(message, customOptions)
case 'success':
return toast.success(message, customOptions)
case 'warning':
return toast.warn(message, customOptions)
case 'error':
return toast.error(message, customOptions)
default:
return toast(message, customOptions)
}
}
export { toastUp }