mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 01:52:22 +00:00
Addressed PR suggestions
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { useCallback } from "react";
|
||||
import { useBlocker } from "@tanstack/react-router";
|
||||
|
||||
type TNavigationBlockerReturn = {
|
||||
isBlocked: boolean;
|
||||
};
|
||||
|
||||
export const useNavigationBlocker = (
|
||||
shouldBlock: boolean,
|
||||
message: string = "Are you sure you want to leave? You may have unsaved changes."
|
||||
): TNavigationBlockerReturn => {
|
||||
const blockerFn = useCallback(() => {
|
||||
if (!shouldBlock) return false;
|
||||
|
||||
// eslint-disable-next-line no-alert
|
||||
const confirmed = window.confirm(message);
|
||||
|
||||
return !confirmed;
|
||||
}, [shouldBlock, message]);
|
||||
|
||||
useBlocker(blockerFn);
|
||||
|
||||
return {
|
||||
isBlocked: shouldBlock
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user