mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-10 20:56:39 +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 { useToast } from "@app/hooks/useToast";
|
||||||
import { UpdateResourceResponse } from "@server/routers/resource";
|
import { UpdateResourceResponse } from "@server/routers/resource";
|
||||||
import { AxiosResponse } from "axios";
|
import { AxiosResponse } from "axios";
|
||||||
|
import { useRouter, usePathname } from "next/navigation";
|
||||||
|
|
||||||
type ResourceInfoBoxType = {};
|
type ResourceInfoBoxType = {};
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ export default function ResourceInfoBox({ }: ResourceInfoBoxType) {
|
|||||||
const { resource, authInfo, updateResource } = useResourceContext();
|
const { resource, authInfo, updateResource } = useResourceContext();
|
||||||
const { env } = useEnvContext();
|
const { env } = useEnvContext();
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [niceId, setNiceId] = useState(resource.niceId);
|
const [niceId, setNiceId] = useState(resource.niceId);
|
||||||
@@ -83,6 +86,10 @@ export default function ResourceInfoBox({ }: ResourceInfoBoxType) {
|
|||||||
niceId: tempNiceId.trim()
|
niceId: tempNiceId.trim()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// update the URL to reflect the new niceId
|
||||||
|
const newPath = pathname.replace(`/resources/${niceId}`, `/resources/${tempNiceId.trim()}`);
|
||||||
|
router.replace(newPath);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("niceIdUpdated"),
|
title: t("niceIdUpdated"),
|
||||||
description: t("niceIdUpdatedSuccessfully")
|
description: t("niceIdUpdatedSuccessfully")
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { Button } from "./ui/button";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useToast } from "@app/hooks/useToast";
|
import { useToast } from "@app/hooks/useToast";
|
||||||
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
|
import { useRouter, usePathname } from "next/navigation";
|
||||||
|
|
||||||
type SiteInfoCardProps = {};
|
type SiteInfoCardProps = {};
|
||||||
|
|
||||||
@@ -24,6 +25,8 @@ export default function SiteInfoCard({ }: SiteInfoCardProps) {
|
|||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const { env } = useEnvContext();
|
const { env } = useEnvContext();
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [niceId, setNiceId] = useState(site.niceId);
|
const [niceId, setNiceId] = useState(site.niceId);
|
||||||
@@ -82,6 +85,10 @@ export default function SiteInfoCard({ }: SiteInfoCardProps) {
|
|||||||
niceId: tempNiceId.trim()
|
niceId: tempNiceId.trim()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// update the URL to reflect the new niceId
|
||||||
|
const newPath = pathname.replace(`/sites/${niceId}`, `/sites/${tempNiceId.trim()}`);
|
||||||
|
router.replace(newPath);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("niceIdUpdated"),
|
title: t("niceIdUpdated"),
|
||||||
description: t("niceIdUpdatedSuccessfully")
|
description: t("niceIdUpdatedSuccessfully")
|
||||||
|
|||||||
Reference in New Issue
Block a user