From 70f494766b4dacad260575faa576913e8a514bd2 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 3 May 2023 21:24:49 +0100 Subject: [PATCH] fix: post updating --- src/models/page.model.ts | 3 ++- src/pages/dashboard/[subdomain]/editor.tsx | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/models/page.model.ts b/src/models/page.model.ts index ae55aeff..8f7de68f 100644 --- a/src/models/page.model.ts +++ b/src/models/page.model.ts @@ -20,6 +20,7 @@ import { ExpandedNote, PageVisibilityEnum } from "~/lib/types" export async function checkPageSlug(input: { slug: string characterId?: number + noteId?: number }) { if (!input.characterId) { return "Character not found" @@ -33,7 +34,7 @@ export async function checkPageSlug(input: { slug: input.slug, characterId: input.characterId, }) - if (page) { + if (page && page.noteId !== input.noteId) { return `Slug "${input.slug}" has already been used` } } catch (error) {} diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index f303cb16..b3e0fa03 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -209,6 +209,7 @@ export default function SubdomainEditor() { const check = await checkPageSlug({ slug: values.slug || defaultSlug, characterId: site.data?.characterId, + noteId: page?.data?.noteId, }) if (check) { toast.error(check) @@ -219,7 +220,9 @@ export default function SubdomainEditor() { tags: uniqueTags, slug: values.slug || defaultSlug, siteId: subdomain, - ...(visibility === PageVisibilityEnum.Draft ? {} : { pageId: pageId }), + ...(visibility === PageVisibilityEnum.Draft + ? {} + : { pageId: `${page?.data?.characterId}-${page?.data?.noteId}` }), isPost: isPost, published, externalUrl: