fix: replace window.location with Next.js router for client-side navigation

- Replace window.location.href with router.push() + router.refresh() in UserDropdown logout
- Replace window.location.href with router.push() in CreateSearchSpaceDialog
- Replace window.location.reload() with router.refresh() in login page retry action
- Prevents full page reloads and preserves React state during in-app navigation
This commit is contained in:
SohamBhattacharjee2003 2026-04-08 04:28:41 +05:30
parent 0cd997f673
commit baada1457a
3 changed files with 12 additions and 9 deletions

View file

@ -2,6 +2,7 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useAtomValue } from "jotai";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { useForm } from "react-hook-form";
@ -43,6 +44,7 @@ interface CreateSearchSpaceDialogProps {
export function CreateSearchSpaceDialog({ open, onOpenChange }: CreateSearchSpaceDialogProps) {
const t = useTranslations("searchSpace");
const tCommon = useTranslations("common");
const router = useRouter();
const [isSubmitting, setIsSubmitting] = useState(false);
const { mutateAsync: createSearchSpace } = useAtomValue(createSearchSpaceMutationAtom);
@ -65,8 +67,7 @@ export function CreateSearchSpaceDialog({ open, onOpenChange }: CreateSearchSpac
trackSearchSpaceCreated(result.id, values.name);
// Hard redirect to ensure fresh state
window.location.href = `/dashboard/${result.id}/onboard`;
router.push(`/dashboard/${result.id}/onboard`);
} catch (error) {
console.error("Failed to create search space:", error);
setIsSubmitting(false);