diff --git a/cypress/e2e/content/navigation.spec.js b/cypress/e2e/content/navigation.spec.js
index d130ed4b2..fcc3f08e1 100644
--- a/cypress/e2e/content/navigation.spec.js
+++ b/cypress/e2e/content/navigation.spec.js
@@ -19,6 +19,13 @@ describe("Navigation through content editor", () => {
cy.get(".ModalAligner--ptdt-.Open--M5j6S button.Close--kVpCO").click();
});
+ it("Should not navigate to the create item page if no model is selected", () => {
+ cy.getBySelector("create_new_content_item").should("exist").click();
+ cy.getBySelector("create_new_content_item_btn").click({ force: true });
+ cy.contains("Please select a Model to proceed.").should("exist");
+ cy.getBySelector("discard_new_content_item_btn").should("exist").click();
+ });
+
it("Creates a new item from the menu", () => {
cy.getBySelector("create_new_content_item").should("exist").click();
cy.getBySelector("create_new_content_item_dialog").should("exist");
diff --git a/src/shell/components/CreateContentItemDialog.tsx b/src/shell/components/CreateContentItemDialog.tsx
index b0832861b..95cfec766 100644
--- a/src/shell/components/CreateContentItemDialog.tsx
+++ b/src/shell/components/CreateContentItemDialog.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useState } from "react";
+import { useMemo, useState } from "react";
import {
Box,
Button,
@@ -10,12 +10,9 @@ import {
InputLabel,
Autocomplete,
Typography,
- Avatar,
} from "@mui/material";
import EditRoundedIcon from "@mui/icons-material/EditRounded";
import { useHistory } from "react-router";
-import { ThemeProvider } from "@mui/material/styles";
-import { theme } from "@zesty-io/material";
import { cloneDeep } from "lodash";
import { useGetContentModelsQuery } from "../services/instance";
@@ -34,10 +31,8 @@ export const CreateContentItemDialog = ({
}: Props) => {
const { data: models } = useGetContentModelsQuery();
const history = useHistory();
- const [selectedModel, setSelectedModel] = useState({
- label: "None",
- ZUID: "",
- });
+ const [selectedModel, setSelectedModel] = useState(null);
+ const [hasError, setHasError] = useState(false);
const sortedModels = useMemo(() => {
if (models?.length) {
@@ -65,8 +60,12 @@ export const CreateContentItemDialog = ({
}, [models, limitTo]);
const onCreateClick = () => {
- onClose();
- history.push("/content/" + selectedModel.ZUID + "/new");
+ if (!selectedModel?.ZUID) {
+ setHasError(true);
+ } else {
+ onClose();
+ history.push("/content/" + selectedModel.ZUID + "/new");
+ }
};
return (
@@ -101,6 +100,7 @@ export const CreateContentItemDialog = ({
Select Model
}
+ renderInput={(params) => (
+
+ )}
getOptionLabel={(option: any) => option.label}
isOptionEqualToValue={(option, value) => option.ZUID === value.ZUID}
- onChange={(event, newValue) => setSelectedModel(newValue)}
+ onChange={(event, newValue) => {
+ if (!!newValue?.ZUID) {
+ setHasError(false);
+ }
+
+ setSelectedModel(newValue);
+ }}
onKeyDown={(evt) => {
if (evt.key.toLowerCase() === "enter" && !!selectedModel?.ZUID) {
evt.preventDefault();
@@ -138,14 +149,17 @@ export const CreateContentItemDialog = ({
/>
-