Skip to content

Commit 0d5bb63

Browse files
committed
fix: check for required plugins in RAS setup wizard (#2442)
1 parent c003a36 commit 0d5bb63

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

assets/wizards/engagement/components/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ export type PrequisiteProps = {
9696
// Schema for prequisite object is defined in PHP class Reader_Activation::get_prerequisites_status().
9797
prerequisite: {
9898
active: boolean;
99+
plugins?: {
100+
[ pluginName: string ]: boolean; // Are the required plugins active?
101+
};
99102
label: string;
100103
description: string;
101104
warning?: string;

assets/wizards/engagement/views/reader-activation/index.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Button,
1616
Card,
1717
Notice,
18+
PluginInstaller,
1819
SectionHeader,
1920
TextControl,
2021
Waiting,
@@ -32,6 +33,7 @@ export default withWizardScreen( () => {
3233
const [ allReady, setAllReady ] = useState( false );
3334
const [ isActiveCampaign, setIsActiveCampaign ] = useState( false );
3435
const [ prerequisites, setPrerequisites ] = useState( null );
36+
const [ missingPlugins, setMissingPlugins ] = useState( [] );
3537
const [ showAdvanced, setShowAdvanced ] = useState( false );
3638
const updateConfig = ( key, val ) => {
3739
setConfig( { ...config, [ key ]: val } );
@@ -84,9 +86,27 @@ export default withWizardScreen( () => {
8486
}, [] );
8587
useEffect( () => {
8688
const _allReady =
87-
prerequisites && Object.keys( prerequisites ).every( key => prerequisites[ key ]?.active );
89+
! missingPlugins.length &&
90+
prerequisites &&
91+
Object.keys( prerequisites ).every( key => prerequisites[ key ]?.active );
8892

8993
setAllReady( _allReady );
94+
95+
if ( prerequisites ) {
96+
setMissingPlugins(
97+
Object.keys( prerequisites ).reduce( ( acc, slug ) => {
98+
const prerequisite = prerequisites[ slug ];
99+
if ( prerequisite.plugins ) {
100+
for ( const pluginSlug in prerequisite.plugins ) {
101+
if ( ! prerequisite.plugins[ pluginSlug ] ) {
102+
acc.push( pluginSlug );
103+
}
104+
}
105+
}
106+
return acc;
107+
}, [] )
108+
);
109+
}
90110
}, [ prerequisites ] );
91111

92112
const getSharedProps = ( configKey, type = 'checkbox' ) => {
@@ -148,7 +168,10 @@ export default withWizardScreen( () => {
148168
isError
149169
/>
150170
) }
151-
{ prerequisites && ! allReady && (
171+
{ 0 < missingPlugins.length && (
172+
<Notice noticeText={ __( 'The following plugins are required.', 'newspack' ) } isWarning />
173+
) }
174+
{ 0 === missingPlugins.length && prerequisites && ! allReady && (
152175
<Notice
153176
noticeText={ __( 'Complete these settings to enable Reader Activation.', 'newspack' ) }
154177
isWarning
@@ -163,14 +186,23 @@ export default withWizardScreen( () => {
163186
{ __( 'Retrieving status…', 'newspack' ) }
164187
</>
165188
) }
166-
{ prerequisites &&
189+
{ 0 < missingPlugins.length && prerequisites && (
190+
<PluginInstaller
191+
plugins={ missingPlugins }
192+
withoutFooterButton
193+
onStatus={ ( { complete } ) => complete && fetchConfig() }
194+
/>
195+
) }
196+
{ ! missingPlugins.length &&
197+
prerequisites &&
167198
Object.keys( prerequisites ).map( key => (
168199
<Prerequisite
169200
key={ key }
170201
config={ config }
171202
getSharedProps={ getSharedProps }
172203
inFlight={ inFlight }
173204
prerequisite={ prerequisites[ key ] }
205+
fetchConfig={ fetchConfig }
174206
saveConfig={ saveConfig }
175207
/>
176208
) ) }

includes/reader-activation/class-reader-activation.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ public static function get_prerequisites_status() {
386386
],
387387
'esp' => [
388388
'active' => self::is_esp_configured(),
389+
'plugins' => [
390+
'newspack-newsletters' => class_exists( '\Newspack_Newsletters' ),
391+
],
389392
'label' => __( 'Email Service Provider (ESP)', 'newspack' ),
390393
'description' => __( 'Connect to your ESP to register readers with their email addresses and send newsletters.', 'newspack' ),
391394
'instructions' => __( 'Connect to your email service provider (ESP) and enable at least one subscription list.', 'newspack' ),
@@ -424,6 +427,12 @@ public static function get_prerequisites_status() {
424427
],
425428
'reader_revenue' => [
426429
'active' => self::is_reader_revenue_ready(),
430+
'plugins' => [
431+
'newspack-blocks' => class_exists( '\Newspack_Blocks' ),
432+
'woocommerce' => function_exists( 'WC' ),
433+
'woocommerce-subscriptions' => class_exists( 'WC_Subscriptions_Product' ),
434+
'woocommerce-name-your-price' => class_exists( 'WC_Name_Your_Price_Helpers' ),
435+
],
427436
'label' => __( 'Reader Revenue', 'newspack' ),
428437
'description' => __( 'Setting suggested donation amounts is required for enabling a streamlined donation experience.', 'newspack' ),
429438
'instructions' => __( 'Set platform to "Newspack" and configure your default donation settings.', 'newspack' ),
@@ -433,6 +442,9 @@ public static function get_prerequisites_status() {
433442
],
434443
'ras_campaign' => [
435444
'active' => self::is_ras_campaign_configured(),
445+
'plugins' => [
446+
'newspack-popups' => class_exists( '\Newspack_Popups_Model' ),
447+
],
436448
'label' => __( 'Reader Activation Campaign', 'newspack' ),
437449
'description' => __( 'Building a set of prompts with default segments and settings allows for an improved experience optimized for Reader Activation.', 'newspack' ),
438450
'help_url' => 'https://help.newspack.com/engagement/reader-activation-system',

0 commit comments

Comments
 (0)