From ac5fe1486a5dd4d0005e4317b968545cdb179abf Mon Sep 17 00:00:00 2001 From: Pallavi Kumari Date: Wed, 29 Oct 2025 20:10:37 +0530 Subject: [PATCH] update url to prevent page redirect --- src/components/ResourceInfoBox.tsx | 7 +++++++ src/components/SiteInfoCard.tsx | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/components/ResourceInfoBox.tsx b/src/components/ResourceInfoBox.tsx index 04f4f558..d16c4bae 100644 --- a/src/components/ResourceInfoBox.tsx +++ b/src/components/ResourceInfoBox.tsx @@ -21,6 +21,7 @@ import { useState } from "react"; import { useToast } from "@app/hooks/useToast"; import { UpdateResourceResponse } from "@server/routers/resource"; import { AxiosResponse } from "axios"; +import { useRouter, usePathname } from "next/navigation"; type ResourceInfoBoxType = {}; @@ -28,6 +29,8 @@ export default function ResourceInfoBox({ }: ResourceInfoBoxType) { const { resource, authInfo, updateResource } = useResourceContext(); const { env } = useEnvContext(); const api = createApiClient(useEnvContext()); + const router = useRouter(); + const pathname = usePathname(); const [isEditing, setIsEditing] = useState(false); const [niceId, setNiceId] = useState(resource.niceId); @@ -83,6 +86,10 @@ export default function ResourceInfoBox({ }: ResourceInfoBoxType) { niceId: tempNiceId.trim() }); + // update the URL to reflect the new niceId + const newPath = pathname.replace(`/resources/${niceId}`, `/resources/${tempNiceId.trim()}`); + router.replace(newPath); + toast({ title: t("niceIdUpdated"), description: t("niceIdUpdatedSuccessfully") diff --git a/src/components/SiteInfoCard.tsx b/src/components/SiteInfoCard.tsx index 5e3e1194..08519b22 100644 --- a/src/components/SiteInfoCard.tsx +++ b/src/components/SiteInfoCard.tsx @@ -16,6 +16,7 @@ import { Button } from "./ui/button"; import { useState } from "react"; import { useToast } from "@app/hooks/useToast"; import { createApiClient, formatAxiosError } from "@app/lib/api"; +import { useRouter, usePathname } from "next/navigation"; type SiteInfoCardProps = {}; @@ -24,6 +25,8 @@ export default function SiteInfoCard({ }: SiteInfoCardProps) { const t = useTranslations(); const { env } = useEnvContext(); const api = createApiClient(useEnvContext()); + const router = useRouter(); + const pathname = usePathname(); const [isEditing, setIsEditing] = useState(false); const [niceId, setNiceId] = useState(site.niceId); @@ -82,6 +85,10 @@ export default function SiteInfoCard({ }: SiteInfoCardProps) { niceId: tempNiceId.trim() }); + // update the URL to reflect the new niceId + const newPath = pathname.replace(`/sites/${niceId}`, `/sites/${tempNiceId.trim()}`); + router.replace(newPath); + toast({ title: t("niceIdUpdated"), description: t("niceIdUpdatedSuccessfully")