diff --git a/client/src/components/form-fields-changed-alert/form-fields-changed-alert.component.jsx b/client/src/components/form-fields-changed-alert/form-fields-changed-alert.component.jsx
index 333766bd6..7e3555039 100644
--- a/client/src/components/form-fields-changed-alert/form-fields-changed-alert.component.jsx
+++ b/client/src/components/form-fields-changed-alert/form-fields-changed-alert.component.jsx
@@ -2,7 +2,6 @@ import React from "react";
import { Form, Space } from "antd";
import { useTranslation } from "react-i18next";
import AlertComponent from "../alert/alert.component";
-import {useLocation } from "react-router-dom";
import "./form-fields-changed.styles.scss";
import Prompt from "../../utils/prompt";
@@ -12,7 +11,6 @@ export default function FormsFieldChanged({ form, skipPrompt }) {
const handleReset = () => {
form.resetFields();
};
- const loc = useLocation();
//if (!form.isFieldsTouched()) return <>>;
return (
{
- if (loc.pathname === location.pathname) return false;
- return t("general.messages.unsavedchangespopup");
- }}
+ message={t("general.messages.unsavedchangespopup")}
/>
{
+ // This has been put in, so it does not affect transitions between the same page
+ if (location.currentLocation.pathname === location.nextLocation.pathname) {
+ return false;
+ }
+ return typeof message === "string" ? !window.confirm(message) : false;
+ },
+ [message]
+ )
+ );
-let blocker = useBlocker(
- React.useCallback(
- () => (typeof message === "string" ? !window.confirm(message) : false),
- [message]
- )
-);
-let prevState = React.useRef(blocker.state);
+ let prevState = useRef(blocker.state);
-React.useEffect(() => {
- if (blocker.state === "blocked") {
- blocker.reset();
- }
- prevState.current = blocker.state;
-}, [blocker]);
+ useEffect(() => {
+ if (blocker.state === "blocked") {
+ blocker.reset();
+ }
+ prevState.current = blocker.state;
+ }, [blocker]);
-useBeforeUnload(
- React.useCallback(
- (event) => {
- if (beforeUnload && typeof message === "string") {
- event.preventDefault();
- event.returnValue = message;
- }
- },
- [message, beforeUnload]
- ),
- { capture: true }
-);
+ useBeforeUnload(
+ useCallback(
+ (event) => {
+ if (beforeUnload && typeof message === "string") {
+ event.preventDefault();
+ event.returnValue = message;
+ }
+ },
+ [message, beforeUnload]
+ ),
+ {capture: true}
+ );
}
-function Prompt({ when, message, ...props }) {
+function Prompt({when, message, ...props}) {
usePrompt(when ? message : false, props);
return null;
}