Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newsletter settings: Show copy and error asking user to choose categories. #97479

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions client/my-sites/site-settings/settings-newsletter/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type NewsletterSettingsFormProps = {
isSavingSettings: boolean;
settings: { subscription_options?: SubscriptionOptions };
updateFields: ( fields: Fields ) => void;
errorNotice: ( text: string ) => void;
};

const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( {
Expand All @@ -128,6 +129,7 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( {
isSavingSettings,
settings,
updateFields,
errorNotice,
}: NewsletterSettingsFormProps ) => {
const translate = useTranslate();
const siteId = useSelector( getSelectedSiteId );
Expand Down Expand Up @@ -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 (
<form onSubmit={ handleSubmitForm }>
<form onSubmit={ onSubmit }>
{ siteId && <QueryJetpackModules siteId={ siteId } /> }

<SettingsSectionHeader
disabled={ disabled }
id="subscriptions"
isSaving={ isSavingSettings }
onButtonClick={ handleSubmitForm }
onButtonClick={ onSubmit }
showButton
title={ translate( 'Subscriptions' ) }
/>
Expand Down Expand Up @@ -252,7 +270,7 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( {
disabled={ disabled }
id="email-settings"
isSaving={ isSavingSettings }
onButtonClick={ handleSubmitForm }
onButtonClick={ onSubmit }
showButton
title={ translate( 'Email' ) }
/>
Expand Down Expand Up @@ -299,7 +317,7 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( {
id="newsletter-categories-settings"
title={ translate( 'Newsletter categories' ) }
showButton
onButtonClick={ handleSubmitForm }
onButtonClick={ onSubmit }
disabled={ disabled }
isSaving={ isSavingSettings }
/>
Expand All @@ -314,7 +332,7 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( {
disabled={ disabled }
id="messages"
isSaving={ isSavingSettings }
onButtonClick={ handleSubmitForm }
onButtonClick={ onSubmit }
showButton
title={ translate( 'Messages' ) }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import React from 'react';
import TermTreeSelector from 'calypso/blocks/term-tree-selector';
import FormLegend from 'calypso/components/forms/form-legend';
import FormSettingExplanation from 'calypso/components/forms/form-setting-explanation';
import NewsletterCategoriesToggle from './newsletter-categories-toggle';
import './style.scss';
Expand Down Expand Up @@ -44,6 +45,11 @@ const NewsletterCategoriesSection = ( {
) }
aria-hidden={ ! newsletterCategoriesEnabled }
>
<FormLegend>
{ translate(
'Which categories will you use for newsletter subscribers? Select all that apply:'
) }
</FormLegend>
<TermTreeSelector
taxonomy="category"
addTerm
Expand Down
Loading