Skip to content

Commit

Permalink
Dont block navigation onSave
Browse files Browse the repository at this point in the history
  • Loading branch information
Onitoxan committed Jan 17, 2025
1 parent 6f36152 commit 9e85338
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions apps/hpc-ftsadmin/src/app/components/flow-form/flow-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,23 @@ const FlowAmountButton = ({
return <C.Button color="primary" {...buttonProps} className="text-end" />;
};

const BlockNavigationOnUnsavedChanges = ({ dirty }: { dirty: boolean }) => {
const BlockNavigationOnUnsavedChanges = ({
dirty,
submitLoading,
rejectLoading,
deleteLoading,
}: {
dirty: boolean;
submitLoading: boolean;
rejectLoading: boolean;
deleteLoading: boolean;
}) => {
const { lang } = getContext();
const message = t.t(lang, (s) => s.components.flowForm.blockNavigation);

const isSubmitting = submitLoading || rejectLoading || deleteLoading;
// User reloading or closing tab
useBeforeUnload((event) => {
if (dirty) {
if (dirty && !isSubmitting) {
event.preventDefault();
// Message will not always show ours, depends on browser
return message;
Expand All @@ -417,7 +427,7 @@ const BlockNavigationOnUnsavedChanges = ({ dirty }: { dirty: boolean }) => {

// User navigating away
useBlocker(() => {
if (dirty) {
if (dirty && !isSubmitting) {
return !window.confirm(message);
}
return false;
Expand Down Expand Up @@ -920,7 +930,9 @@ export const FlowForm = (props: FlowFormProps) => {
);
return (
<Form>
<BlockNavigationOnUnsavedChanges {...{ dirty }} />
<BlockNavigationOnUnsavedChanges
{...{ dirty, submitLoading, rejectLoading, deleteLoading }}
/>
{!isDisabled && (
<C.CheckBox
name="restricted"
Expand Down

0 comments on commit 9e85338

Please sign in to comment.