mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-10 20:02:26 +00:00
update url to prevent page redirect
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user