From 2ef18e9caeaab1ad20a934801abca8832c3ec31d Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 2 Apr 2024 15:55:49 +0300 Subject: [PATCH] Enable publish button when title and cover is not empty --- src/components/posts/editor/FullEditor.tsx | 33 +++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/components/posts/editor/FullEditor.tsx b/src/components/posts/editor/FullEditor.tsx index e8c834e17..1f55db17d 100644 --- a/src/components/posts/editor/FullEditor.tsx +++ b/src/components/posts/editor/FullEditor.tsx @@ -149,12 +149,31 @@ const FullEditor = ({ function onBodyChanged(text: string) { form.setFieldsValue({ [fieldName('body')]: text }) handleChange() + setPublishIsDisable(!text) + } + + const onTitleChange = (e: React.ChangeEvent) => { + const title = e.target.value + + form.setFieldsValue({ [fieldName('title')]: title }) + + const image = form.getFieldValue(fieldName('image')) + + if (image) { + setPublishIsDisable(!title) + } } const defaultSpace = spaceForPost || allowedSpaceIds[0] useEffect(() => { setSpaceForPost(defaultSpace) + + const { title, image, body } = initialValues + + if (title && (image || body)) { + setPublishIsDisable(false) + } }, [defaultSpace]) if (isEmptyArray(allowedSpaceIds)) return @@ -163,12 +182,16 @@ const FullEditor = ({ const onAvatarChanged = (url?: string) => { form.setFieldsValue({ [fieldName('image')]: url }) + const title = form.getFieldValue(fieldName('title')) + + if (title) { + setPublishIsDisable(!url) + } } const tags = initialValues.tags || [] const saveDraft = (content: PostContent) => { - setPublishIsDisable(!content.body) saveContent(content) } @@ -199,7 +222,7 @@ const FullEditor = ({ - form.setFieldsValue({ [fieldName('title')]: e.target.value.trim() })} - placeholder='Title' - className={styles.TitleInput} - /> +
{!postType && (