forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseFlash.ts
More file actions
26 lines (21 loc) · 883 Bytes
/
useFlash.ts
File metadata and controls
26 lines (21 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Actions, useStoreActions } from 'easy-peasy';
import { FlashStore } from '@/state/flashes';
import { ApplicationStore } from '@/state';
interface KeyedFlashStore {
addError: (message: string, title?: string) => void;
clearFlashes: () => void;
clearAndAddHttpError: (error?: Error | string | null) => void;
}
const useFlash = (): Actions<FlashStore> => {
return useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
};
const useFlashKey = (key: string): KeyedFlashStore => {
const { addFlash, clearFlashes, clearAndAddHttpError } = useFlash();
return {
addError: (message, title) => addFlash({ key, message, title, type: 'error' }),
clearFlashes: () => clearFlashes(key),
clearAndAddHttpError: (error) => clearAndAddHttpError({ key, error }),
};
};
export { useFlashKey };
export default useFlash;