Skip to content

Commit

Permalink
[Blocks] Navigate to created block on successful creation (#3121)
Browse files Browse the repository at this point in the history
  • Loading branch information
finnar-bin authored Jan 7, 2025
1 parent e440333 commit bbfaae2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/apps/schema/src/app/components/CreateModelDialogue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<ContentModel>, next: any) => {
const newModel = { ...prev, ...next };
Expand Down Expand Up @@ -181,7 +182,6 @@ export const CreateModelDialogue = ({ onClose, modelType = "" }: Props) => {
sort: 9999,
},
});
onClose();
} else {
history.push(`/schema/${createModelData.data.ZUID}`);
onClose();
Expand All @@ -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]);
Expand Down

0 comments on commit bbfaae2

Please sign in to comment.