@totalsoft/rocket-ui
Version:
A set of reusable and composable React components built on top of Material UI core for developing fast and friendly web applications interfaces.
30 lines • 1.46 kB
JavaScript
// Copyright (c) TotalSoft.
// This source code is licensed under the MIT license.
import { useCallback } from 'react';
import { toast } from 'react-toastify';
import { classes } from './ToastStyles';
import { getTransitionType } from './types';
const usePromiseToast = () => {
return useCallback(
/**
*
* @param {Promise} promise The promise function
* @param {(String|Object)} pending The message to be shown while promise in pending or the entire object with all the configurations
* @param {(String|Object)} success The message to be shown when promise completed successfully or the entire object with all the configurations
* @param {(String|Object)} error The message to be shown when promise was rejected or the entire object with all the configurations
* @param {ToastOptions} options Additional options passed to the toast
*/
(promise, pending, success, error, { transitionType, ...restOptions } = {}) => {
const localOptions = {
...restOptions,
transition: getTransitionType(transitionType)
};
toast.promise(promise, { pending, success, error }, {
className: `${classes.default} ${classes.success} ${classes.info} ${classes.error} ${classes.warning} ${classes.toastWrapper} `,
closeButton: true,
...localOptions,
});
}, []);
};
export default usePromiseToast;
//# sourceMappingURL=usePromiseToast.js.map