From 119fc4b31941bb154e18d0de932f6ab37087e8f0 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 9 Jun 2025 22:43:56 +0100 Subject: [PATCH] fix(cms): don't allow accidental publishing --- cms/components/PublishAction.tsx | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cms/components/PublishAction.tsx b/cms/components/PublishAction.tsx index b7fecb2e..7778c325 100644 --- a/cms/components/PublishAction.tsx +++ b/cms/components/PublishAction.tsx @@ -7,24 +7,32 @@ export const PublishAction: DocumentActionComponent = props => { const { patch } = useDocumentOperation(props.id, props.type) const document = props.draft || props.published - const isReady = document?.publishStatus === 'ready' const isPublished = document?.publishStatus === 'published' - const hasResponse = (document?.posts as any[])?.length > 0 - // Don't show the action if there's no response or if already published - if (!hasResponse || isPublished) { + const hasTextContent = (document?.posts as any[])?.some(post => { + if (!post.content || !Array.isArray(post.content)) return false + return post.content.some((block: any) => { + if (block._type === 'block' && block.children) { + return block.children.some((child: any) => child.text && child.text.trim().length > 0) + } + return false + }) + }) + + const hasImage = !!(document as any)?.generatedImage?.asset?._ref + const hasContent = hasTextContent && hasImage + + if (isPublished) { return null } return { - label: isReady ? 'Ready to publish ✓' : 'Mark as ready to publish', + label: 'Mark as ready to publish', icon: CheckIcon, - disabled: isReady, - tone: isReady ? 'positive' : 'primary', - shortcut: !isReady ? 'mod+shift+p' : undefined, + disabled: !hasContent, + tone: 'positive', + shortcut: 'mod+shift+p', onHandle: () => { - if (isReady) return - // Set the publish status to 'ready' patch.execute([ { -- 2.51.2