diff --git a/client/my-sites/site-settings/settings-newsletter/main.tsx b/client/my-sites/site-settings/settings-newsletter/main.tsx index 334feee831ee41..9a1d06921d7e90 100644 --- a/client/my-sites/site-settings/settings-newsletter/main.tsx +++ b/client/my-sites/site-settings/settings-newsletter/main.tsx @@ -118,6 +118,7 @@ type NewsletterSettingsFormProps = { isSavingSettings: boolean; settings: { subscription_options?: SubscriptionOptions }; updateFields: ( fields: Fields ) => void; + errorNotice: ( text: string ) => void; }; const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( { @@ -128,6 +129,7 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( { isSavingSettings, settings, updateFields, + errorNotice, }: NewsletterSettingsFormProps ) => { const translate = useTranslate(); const siteId = useSelector( getSelectedSiteId ); @@ -185,15 +187,31 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( { scrollToAnchor( { offset: 15 } ); }, [ savedSubscriptionOptions, updateFields ] ); + const onSubmit = ( event?: React.FormEvent | React.MouseEvent ) => { + event?.preventDefault(); + + if ( + fields.wpcom_newsletter_categories_enabled && + ! fields.wpcom_newsletter_categories?.length + ) { + errorNotice( + translate( 'Please select at least one category when newsletter categories are enabled.' ) + ); + return; + } + + handleSubmitForm(); + }; + return ( -