1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/contexts/UIContext.ts
2022-03-28 09:49:59 +01:00

38 lines
908 B
TypeScript

import React from 'react';
import { IToast } from 'interfaces/toast';
interface IUIContext {
toastData: IToast;
setToast: React.Dispatch<React.SetStateAction<IToast>>;
showFeedback: boolean;
setShowFeedback: React.Dispatch<React.SetStateAction<boolean>>;
}
export const createEmptyToast = (): IToast => {
return {
title: '',
text: '',
components: [],
show: false,
persist: false,
type: '',
};
};
const setToastPlaceholder = () => {
throw new Error('setToast called outside UIContext');
};
const setShowFeedbackPlaceholder = () => {
throw new Error('setShowFeedback called outside UIContext');
};
const UIContext = React.createContext<IUIContext>({
toastData: createEmptyToast(),
setToast: setToastPlaceholder,
showFeedback: false,
setShowFeedback: setShowFeedbackPlaceholder,
});
export default UIContext;