2022-02-13 20:44:19 +00:00
|
|
|
import { Actions } from 'easy-peasy';
|
2020-04-04 17:59:25 +00:00
|
|
|
import { FlashStore } from '@/state/flashes';
|
2022-02-13 20:44:19 +00:00
|
|
|
import { useStoreActions } from '@/state/hooks';
|
2020-04-04 17:59:25 +00:00
|
|
|
|
|
|
|
const useFlash = (): Actions<FlashStore> => {
|
2022-02-13 20:44:19 +00:00
|
|
|
return useStoreActions(actions => actions.flashes);
|
2020-04-04 17:59:25 +00:00
|
|
|
};
|
|
|
|
|
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 };
|
2020-04-04 17:59:25 +00:00
|
|
|
export default useFlash;
|