| 1 |
import { toast } from "react-toastify"; |
| 2 |
|
| 3 |
export const toastDefaultArgs = { |
| 4 |
position: "bottom-right", |
| 5 |
autoClose: 3000, |
| 6 |
hideProgressBar: false, |
| 7 |
closeOnClick: true, |
| 8 |
pauseOnHover: true, |
| 9 |
draggable: true, |
| 10 |
progress: undefined, |
| 11 |
icon: false, |
| 12 |
}; |
| 13 |
|
| 14 |
const toastAlert = (type, message, args) => { |
| 15 |
type = type || null; |
| 16 |
message = message || null; |
| 17 |
const promise = new Promise((resolve, reject) => { |
| 18 |
args = args || {}; |
| 19 |
const defaultArgs = { ...toastDefaultArgs, ...args, onClose: resolve }; |
| 20 |
if (type == "success") { |
| 21 |
toast.success(message, defaultArgs); |
| 22 |
} |
| 23 |
if (type == "error") { |
| 24 |
toast.error(message, defaultArgs); |
| 25 |
} |
| 26 |
if (type == "info") { |
| 27 |
toast.info(message, defaultArgs); |
| 28 |
} |
| 29 |
if (type == "warning") { |
| 30 |
toast.warning(message, defaultArgs); |
| 31 |
} |
| 32 |
if (!type) { |
| 33 |
reject(); |
| 34 |
} |
| 35 |
}); |
| 36 |
return promise; |
| 37 |
}; |
| 38 |
|
| 39 |
export default toastAlert; |
| 40 |
|