Skip to content

Commit

Permalink
WordAds: Include Inline Ads Setting (#91006)
Browse files Browse the repository at this point in the history
* Initial commit

* WordAds: Include Inline Ads Setting

* Fix supportsInlineAds to include Simple sites

* Fix TS error for siteId potentially being null

---------

Co-authored-by: Collyn Philleo <collyn.philleo@automattic.com>
  • Loading branch information
Aurorum and cphilleo authored May 22, 2024
1 parent 26a999e commit 32b2cc2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
19 changes: 18 additions & 1 deletion client/my-sites/earn/ads/form-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import { useDispatch, useSelector } from 'calypso/state';
import getSiteUrl from 'calypso/state/selectors/get-site-url';
import { getWordadsSettings } from 'calypso/state/selectors/get-wordads-settings';
import isSavingWordadsSettings from 'calypso/state/selectors/is-saving-wordads-settings';
import { isJetpackSite, getCustomizerUrl } from 'calypso/state/sites/selectors';
import {
isJetpackSite,
isJetpackMinimumVersion,
getCustomizerUrl,
} from 'calypso/state/sites/selectors';
import { getSelectedSite, getSelectedSiteId } from 'calypso/state/ui/selectors';
import { saveWordadsSettings } from 'calypso/state/wordads/settings/actions';

Expand All @@ -32,6 +36,7 @@ type DisplayOptions = {
display_archive?: boolean;
enable_header_ad?: boolean;
second_belowpost?: boolean;
inline_enabled?: boolean;
sidebar?: boolean;
};

Expand Down Expand Up @@ -64,6 +69,10 @@ const AdsFormSettings = () => {
);
const wordadsSettings = useSelector( ( state ) => getWordadsSettings( state, siteId ) );
const widgetsUrl = useSelector( ( state ) => getCustomizerUrl( state, siteId, 'widgets' ) );
const isMinVersionForInlineAds = useSelector(
( state ) => siteId && isJetpackMinimumVersion( state, siteId, '13.5-a.1' )
);
const supportsInlineAds = ! siteIsJetpack || isMinVersionForInlineAds;

const isLoading = ! wordadsSettings || isSavingSettings;
const isWordAds = site?.options?.wordads;
Expand Down Expand Up @@ -253,6 +262,14 @@ const AdsFormSettings = () => {
onChange={ () => handleDisplayToggle( 'second_belowpost' ) }
label={ translate( 'Second ad below post' ) }
/>
{ supportsInlineAds && (
<ToggleControl
checked={ !! settings.display_options?.inline_enabled }
disabled={ isDisabled }
onChange={ () => handleDisplayToggle( 'inline_enabled' ) }
label={ translate( 'Inline within post content' ) }
/>
) }
{ ! siteIsJetpack && (
<ToggleControl
checked={ !! settings.display_options?.sidebar }
Expand Down
1 change: 1 addition & 0 deletions client/my-sites/earn/ads/payments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type WordAdSettings = {
display_page: boolean;
enable_header_ad: boolean;
second_belowpost: boolean;
inline_enabled: boolean;
sidebar: boolean;
display_archive: boolean;
};
Expand Down
1 change: 1 addition & 0 deletions client/state/data-layer/wpcom/wordads/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const saveWordadsSettings = ( action ) => ( dispatch, getState ) => {
wordads_display_archive: settings.display_options.display_archive,
enable_header_ad: settings.display_options.enable_header_ad,
wordads_second_belowpost: settings.display_options.second_belowpost,
wordads_inline_enabled: settings.display_options.inline_enabled,
wordads_ccpa_enabled: settings.ccpa_enabled,
wordads_ccpa_privacy_policy_url: settings.ccpa_privacy_policy_url,
wordads_custom_adstxt_enabled: settings.custom_adstxt_enabled,
Expand Down
1 change: 1 addition & 0 deletions client/state/selectors/get-wordads-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const getWordadsSettings = createSelector(
display_archive: siteSettings.wordads_display_archive,
enable_header_ad: siteSettings.enable_header_ad,
second_belowpost: siteSettings.wordads_second_belowpost,
inline_enabled: siteSettings.wordads_inline_enabled,
},
ccpa_enabled: siteSettings.wordads_ccpa_enabled,
ccpa_privacy_policy_url: siteSettings.wordads_ccpa_privacy_policy_url,
Expand Down
5 changes: 5 additions & 0 deletions client/state/selectors/test/get-wordads-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe( 'getWordadsSettings()', () => {
wordads_display_archive: 'wordads_display_archive-test',
enable_header_ad: 'enable_header_ad-test',
wordads_second_belowpost: 'wordads_second_belowpost-test',
wordads_inline_enabled: 'wordads_inline_enabled-test',
wordads_ccpa_enabled: 'wordads_ccpa_enabled-test',
wordads_ccpa_privacy_policy_url: 'wordads_ccpa_privacy_policy_url-test',
wordads_custom_adstxt_enabled: 'wordads_custom_adstxt_enabled-test',
Expand Down Expand Up @@ -117,6 +118,10 @@ describe( 'getWordadsSettings()', () => {
'display_options.second_belowpost',
'wordads_second_belowpost-test'
);
expect( output ).toHaveProperty(
'display_options.inline_enabled',
'wordads_inline_enabled-test'
);
expect( output ).toHaveProperty( 'ccpa_enabled', 'wordads_ccpa_enabled-test' );
expect( output ).toHaveProperty(
'ccpa_privacy_policy_url',
Expand Down

0 comments on commit 32b2cc2

Please sign in to comment.