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 2 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
20 changes: 19 additions & 1 deletion 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,6 +187,22 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( {
scrollToAnchor( { offset: 15 } );
}, [ savedSubscriptionOptions, updateFields ] );

const onNewsletterCategoriesSubmit = ( 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 }>
{ siteId && <QueryJetpackModules siteId={ siteId } /> }
Expand Down Expand Up @@ -299,7 +317,7 @@ const NewsletterSettingsForm = wrapSettingsForm( getFormSettings )( ( {
id="newsletter-categories-settings"
title={ translate( 'Newsletter categories' ) }
showButton
onButtonClick={ handleSubmitForm }
onButtonClick={ onNewsletterCategoriesSubmit }
disabled={ disabled }
isSaving={ isSavingSettings }
/>
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