Skip to content

Commit

Permalink
Show categories field based on available categories data.
Browse files Browse the repository at this point in the history
  • Loading branch information
allilevine committed Dec 16, 2024
1 parent 373079a commit d945b43
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions packages/subscriber/src/components/add-form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable wpcalypso/jsx-classname-namespace */
import { FormInputValidation } from '@automattic/components';
import { Subscriber, useNewsletterCategories } from '@automattic/data-stores';
import { STORE_KEY as SiteStore } from '@automattic/data-stores/src/site';
import { localizeUrl } from '@automattic/i18n-utils';
import { Title, SubTitle, NextButton } from '@automattic/onboarding';
import { TextControl, FormFileUpload, Button } from '@wordpress/components';
Expand All @@ -26,7 +25,6 @@ import { RecordTrackEvents, useRecordAddFormEvents } from '../../hooks/use-recor
import AddSubscribersDisclaimer from '../add-subscribers-disclaimer';
import { CategoriesSection } from './categories-section';
import { tip } from './icon';
import type { SiteSettings } from '@automattic/data-stores/src/site/types';

import './style.scss';

Expand Down Expand Up @@ -90,17 +88,6 @@ export const AddSubscriberForm: FunctionComponent< Props > = ( props ) => {
siteId,
} );

const newsletterCategoriesEnabled = useSelect(
( select ) => {
const store = select( SiteStore ) as {
getSiteSettings: ( id: number ) => SiteSettings | undefined;
};
const siteSettings = siteId ? store.getSiteSettings( siteId ) : undefined;
return siteSettings?.wpcom_newsletter_categories_enabled ?? false;
},
[ siteId ]
);

const [ selectedCategories, setSelectedCategories ] = useState< string[] >( [] );

useEffect( () => {
Expand Down Expand Up @@ -520,14 +507,15 @@ export const AddSubscriberForm: FunctionComponent< Props > = ( props ) => {

{ renderEmptyFormValidationMsg() }

{ newsletterCategoriesEnabled && (
<CategoriesSection
siteId={ siteId }
newsletterCategories={ newsletterCategoriesData?.newsletterCategories }
selectedCategories={ selectedCategories }
setSelectedCategories={ setSelectedCategories }
/>
) }
{ newsletterCategoriesData?.enabled &&
newsletterCategoriesData?.newsletterCategories.length > 0 && (
<CategoriesSection
siteId={ siteId }
newsletterCategories={ newsletterCategoriesData?.newsletterCategories }
selectedCategories={ selectedCategories }
setSelectedCategories={ setSelectedCategories }
/>
) }

<AddSubscribersDisclaimer buttonLabel={ submitBtnName } />

Expand Down

0 comments on commit d945b43

Please sign in to comment.