1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-19 00:15:43 +01:00
unleash.unleash/frontend/src/hooks/useToast.tsx
Thomas Heartman b2c58102dd
chore(unl-204): remove uses of toast text and confetti (#8941)
As of PR #8935, we no longer support both text and title, and confetti
has been removed.

This PR:
- removes `confetti` from the toast interface
- merges `text` and `title` into `text` and updates its uses across the
codebase.
- readjusts the text where necessary.
2024-12-10 13:38:04 +00:00

42 lines
1.1 KiB
TypeScript

import { useCallback, useContext } from 'react';
import UIContext from '../contexts/UIContext';
import type { IToast } from '../interfaces/toast';
const useToast = () => {
const { setToast } = useContext(UIContext);
const hideToast = () =>
setToast((prev: IToast) => ({
...prev,
show: false,
}));
const setToastApiError = useCallback(
(text: string, overrides?: IToast) => {
setToast({
text: text || 'Something went wrong.',
type: 'error',
show: true,
autoHideDuration: 12000,
...overrides,
});
},
[setToast],
);
const setToastData = useCallback(
(toast: IToast) => {
if (toast.persist) {
setToast({ ...toast, show: true });
} else {
setToast({ autoHideDuration: 6000, ...toast, show: true });
}
},
[setToast],
);
return { setToastData, setToastApiError, hideToast };
};
export default useToast;