misc_pterodactyl-panel/resources/scripts/plugins/useFlash.ts

25 lines
687 B
TypeScript
Raw Normal View History

2022-02-13 20:44:19 +00:00
import { Actions } from 'easy-peasy';
import { FlashStore } from '@/state/flashes';
2022-02-13 20:44:19 +00:00
import { useStoreActions } from '@/state/hooks';
const useFlash = (): Actions<FlashStore> => {
2022-02-13 20:44:19 +00:00
return useStoreActions(actions => actions.flashes);
};
2022-02-13 20:44:19 +00:00
interface KeyedFlashStore {
clearFlashes: () => void;
clearAndAddHttpError: (error?: Error | string | null) => void;
}
const useFlashKey = (key: string): KeyedFlashStore => {
const { clearFlashes, clearAndAddHttpError } = useFlash();
return {
clearFlashes: () => clearFlashes(key),
clearAndAddHttpError: (error) => clearAndAddHttpError({ key, error }),
};
};
export { useFlashKey };
export default useFlash;