mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
4167a60588
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome to the frontend as well. ![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65) Added a few `biome-ignore` to speed up the process but we may want to check and fix them in the future.
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { useCallback, useContext } from 'react';
|
|
import UIContext from '../contexts/UIContext';
|
|
import { 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({
|
|
title: 'Something went wrong',
|
|
text,
|
|
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;
|