From bbfaae210c902e967e59fe4f114be73948205388 Mon Sep 17 00:00:00 2001 From: Nar -- <28705606+finnar-bin@users.noreply.github.com> Date: Tue, 7 Jan 2025 08:38:28 +0800 Subject: [PATCH] [Blocks] Navigate to created block on successful creation (#3121) Resolves https://github.com/zesty-io/manager-ui/pull/3112#issuecomment-2573794037 --- .../schema/src/app/components/CreateModelDialogue.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/apps/schema/src/app/components/CreateModelDialogue.tsx b/src/apps/schema/src/app/components/CreateModelDialogue.tsx index 709d6abed..a26e63b05 100644 --- a/src/apps/schema/src/app/components/CreateModelDialogue.tsx +++ b/src/apps/schema/src/app/components/CreateModelDialogue.tsx @@ -35,7 +35,7 @@ import { ContentModel, User } from "../../../../../shell/services/types"; import { notify } from "../../../../../shell/store/notifications"; import { useDispatch, useSelector } from "react-redux"; import { LoadingButton } from "@mui/lab"; -import { useHistory } from "react-router"; +import { useHistory, useLocation } from "react-router"; import { modelIconMap } from "../utils"; import { withCursorPosition } from "../../../../../shell/components/withCursorPosition"; import { formatPathPart } from "../../../../../utility/formatPathPart"; @@ -86,6 +86,7 @@ export const CreateModelDialogue = ({ onClose, modelType = "" }: Props) => { const [type, setType] = useState(modelType); const dispatch = useDispatch(); const history = useHistory(); + const { pathname } = useLocation(); const [model, updateModel] = useReducer( (prev: Partial, next: any) => { const newModel = { ...prev, ...next }; @@ -181,7 +182,6 @@ export const CreateModelDialogue = ({ onClose, modelType = "" }: Props) => { sort: 9999, }, }); - onClose(); } else { history.push(`/schema/${createModelData.data.ZUID}`); onClose(); @@ -192,7 +192,9 @@ export const CreateModelDialogue = ({ onClose, modelType = "" }: Props) => { useEffect(() => { // Only navigate to schema page once initial content is created for templateset & og_image field is created for block if ((isContentItemCreated || isOgImageFieldCreated) && createModelData) { - history.push(`/schema/${createModelData.data.ZUID}`); + history.push( + `/${pathname?.split("/")?.[1] || "schema"}/${createModelData.data.ZUID}` + ); onClose(); } }, [isContentItemCreated, createModelData, isOgImageFieldCreated]);