mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
27 lines
582 B
TypeScript
27 lines
582 B
TypeScript
import React from "react";
|
|
import { useBlocker } from "@remix-run/react";
|
|
|
|
import type { PromptProps } from "@refinedev/core";
|
|
|
|
export const Prompt: React.FC<PromptProps> = ({
|
|
message,
|
|
when,
|
|
setWarnWhen,
|
|
}) => {
|
|
const blocker = React.useCallback(() => {
|
|
if (when) {
|
|
if (window.confirm(message)) {
|
|
setWarnWhen?.(false);
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}, [when, message, setWarnWhen]);
|
|
|
|
useBlocker(blocker);
|
|
|
|
return null;
|
|
};
|