Skip to content

Commit 8bcfdb8

Browse files
update url to prevent page redirect
1 parent d8c3f4d commit 8bcfdb8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/components/ResourceInfoBox.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ import { useState } from "react";
2222
import { useToast } from "@app/hooks/useToast";
2323
import { UpdateResourceResponse } from "@server/routers/resource";
2424
import { AxiosResponse } from "axios";
25+
import { useRouter, usePathname } from "next/navigation";
2526

2627
type ResourceInfoBoxType = {};
2728

2829
export default function ResourceInfoBox({ }: ResourceInfoBoxType) {
2930
const { resource, authInfo, updateResource } = useResourceContext();
3031
const { env } = useEnvContext();
3132
const api = createApiClient(useEnvContext());
33+
const router = useRouter();
34+
const pathname = usePathname();
3235

3336
const [isEditing, setIsEditing] = useState(false);
3437
const [niceId, setNiceId] = useState(resource.niceId);
@@ -84,6 +87,10 @@ export default function ResourceInfoBox({ }: ResourceInfoBoxType) {
8487
niceId: tempNiceId.trim()
8588
});
8689

90+
// update the URL to reflect the new niceId
91+
const newPath = pathname.replace(`/resources/${niceId}`, `/resources/${tempNiceId.trim()}`);
92+
router.replace(newPath);
93+
8794
toast({
8895
title: t("niceIdUpdated"),
8996
description: t("niceIdUpdatedSuccessfully")

src/components/SiteInfoCard.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Button } from "./ui/button";
1616
import { useState } from "react";
1717
import { useToast } from "@app/hooks/useToast";
1818
import { createApiClient, formatAxiosError } from "@app/lib/api";
19+
import { useRouter, usePathname } from "next/navigation";
1920

2021
type SiteInfoCardProps = {};
2122

@@ -24,6 +25,8 @@ export default function SiteInfoCard({ }: SiteInfoCardProps) {
2425
const t = useTranslations();
2526
const { env } = useEnvContext();
2627
const api = createApiClient(useEnvContext());
28+
const router = useRouter();
29+
const pathname = usePathname();
2730

2831
const [isEditing, setIsEditing] = useState(false);
2932
const [niceId, setNiceId] = useState(site.niceId);
@@ -82,6 +85,10 @@ export default function SiteInfoCard({ }: SiteInfoCardProps) {
8285
niceId: tempNiceId.trim()
8386
});
8487

88+
// update the URL to reflect the new niceId
89+
const newPath = pathname.replace(`/sites/${niceId}`, `/sites/${tempNiceId.trim()}`);
90+
router.replace(newPath);
91+
8592
toast({
8693
title: t("niceIdUpdated"),
8794
description: t("niceIdUpdatedSuccessfully")

0 commit comments

Comments
 (0)