@@ -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 ) ) }
0 commit comments