Skip to content

Commit

Permalink
Merge pull request #119 from not-byte/109-fix-form-refresh
Browse files Browse the repository at this point in the history
fix(form): fix page refreshing behaviour when closing the form dialog
  • Loading branch information
pawelos231 authored Nov 4, 2024
2 parents e23331e + 6186c69 commit 329382a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/UI/Dialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use client";

import React, { useCallback } from "react";
import { usePathname, useSearchParams } from "next/navigation";
import { useSearchParams } from "next/navigation";
import { useRef, useEffect } from "react";
import { redirectToPage } from "./close";
import DialogContext from "./dialogContext";
import { FaTimesCircle } from "react-icons/fa";

Expand All @@ -17,13 +16,15 @@ export default function Dialog({ title, onClose, children }: Props) {
const searchParams = useSearchParams();
const dialogRef = useRef<null | HTMLDialogElement>(null);
const showDialog = searchParams.get("showDialog");
const pathname = usePathname();

const closeDialog = useCallback(() => {
dialogRef.current?.close();
redirectToPage(pathname);
const newUrl = new URL(window.location.href);
newUrl.searchParams.delete("showDialog");
window.history.replaceState(null, "", newUrl.toString());

onClose();
}, [onClose, pathname]);
}, [onClose]);

useEffect(() => {
if (showDialog === "y") {
Expand Down

0 comments on commit 329382a

Please sign in to comment.