diff --git a/.changeset/clever-radios-share.md b/.changeset/clever-radios-share.md new file mode 100644 index 0000000000..28e90b2caf --- /dev/null +++ b/.changeset/clever-radios-share.md @@ -0,0 +1,6 @@ +--- +"@comet/cms-admin": patch +"@comet/cms-api": patch +--- + +Prevent the creation of a second home page diff --git a/packages/admin/cms-admin/src/pages/createEditPageNode.tsx b/packages/admin/cms-admin/src/pages/createEditPageNode.tsx index a19f6dfdfe..d5bce8f3ba 100644 --- a/packages/admin/cms-admin/src/pages/createEditPageNode.tsx +++ b/packages/admin/cms-admin/src/pages/createEditPageNode.tsx @@ -130,9 +130,10 @@ export function createEditPageNode({ }); let parentPath: string | null = null; + const hasParentNode = parentNodeData?.pageTreeNode?.path != undefined; if (parentNodeData?.pageTreeNode) { - parentPath = parentNodeData.pageTreeNode.slug === "home" ? "/home" : parentNodeData.pageTreeNode.path; + parentPath = parentNodeData.pageTreeNode.slug === "home" && hasParentNode ? "/home" : parentNodeData.pageTreeNode.path; } const options = Object.keys(documentTypes).map((type) => ({ @@ -150,6 +151,7 @@ export function createEditPageNode({ // The unchanged slug is expected to be available return "Available"; } + const { data } = await apollo.query({ query: isPathAvailableQuery, variables: { @@ -338,7 +340,7 @@ export function createEditPageNode({ variant="horizontal" > - {values.slug === "home" + {values.slug === "home" && parentPath === null ? "/" : parentPath === null ? `/${values.slug}` diff --git a/packages/api/cms-api/src/page-tree/createPageTreeResolver.ts b/packages/api/cms-api/src/page-tree/createPageTreeResolver.ts index 43ca6a616c..a4b699c643 100644 --- a/packages/api/cms-api/src/page-tree/createPageTreeResolver.ts +++ b/packages/api/cms-api/src/page-tree/createPageTreeResolver.ts @@ -121,6 +121,11 @@ export function createPageTreeResolver({ if (this.config.reservedPaths.includes(requestedPath)) { return SlugAvailability.Reserved; } + + if (slug == "home" && requestedPath !== "/home") { + return SlugAvailability.Reserved; + } + const nodeWithSamePath = await this.pageTreeService.nodeWithSamePath(requestedPath, nonEmptyScopeOrNothing(scope)); if (nodeWithSamePath) {