Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/plugins/useFlash.ts
7458 views
1
import { Actions, useStoreActions } from 'easy-peasy';
2
import { FlashStore } from '@/state/flashes';
3
import { ApplicationStore } from '@/state';
4
5
interface KeyedFlashStore {
6
addError: (message: string, title?: string) => void;
7
clearFlashes: () => void;
8
clearAndAddHttpError: (error?: Error | string | null) => void;
9
}
10
11
const useFlash = (): Actions<FlashStore> => {
12
return useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
13
};
14
15
const useFlashKey = (key: string): KeyedFlashStore => {
16
const { addFlash, clearFlashes, clearAndAddHttpError } = useFlash();
17
18
return {
19
addError: (message, title) => addFlash({ key, message, title, type: 'error' }),
20
clearFlashes: () => clearFlashes(key),
21
clearAndAddHttpError: (error) => clearAndAddHttpError({ key, error }),
22
};
23
};
24
25
export { useFlashKey };
26
export default useFlash;
27
28