Skip to content

Commit 5354673

Browse files
committed
fix(onboarding): handoff message component
1 parent f8b4acc commit 5354673

File tree

5 files changed

+49
-35
lines changed

5 files changed

+49
-35
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* WordPress dependencies.
3+
*/
4+
import { useEffect, useState } from '@wordpress/element';
5+
6+
/**
7+
* Internal dependencies.
8+
*/
9+
import { HANDOFF_KEY } from '../consts';
10+
import { Notice } from '../';
11+
12+
/**
13+
* Handoff Message Component.
14+
*/
15+
export default function HandoffMessage() {
16+
const [ handoffMessage, setHandoffMessage ] = useState( false );
17+
useEffect( () => {
18+
// Slight delay to allow for localStorage to be updated by RAS component.
19+
setTimeout( () => {
20+
const handoff = JSON.parse( localStorage.getItem( HANDOFF_KEY ) );
21+
if ( handoff?.message ) {
22+
setHandoffMessage( handoff.message );
23+
} else {
24+
setHandoffMessage( false );
25+
}
26+
}, 100 );
27+
}, [] );
28+
if ( ! handoffMessage ) return null;
29+
return <Notice isHandoff isDismissible={ false } rawHTML noticeText={ handoffMessage } />;
30+
}

assets/components/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export { default as CustomSelectControl } from './custom-select-control';
1111
export { default as FormTokenField } from './form-token-field';
1212
export { default as Footer } from './footer';
1313
export { default as Handoff } from './handoff';
14+
export { default as HandoffMessage } from './handoff-message';
1415
export { default as InfoButton } from './info-button';
1516
export { default as ImageUpload } from './image-upload';
1617
export { default as GlobalNotices } from './global-notices';

assets/components/src/with-wizard-screen/index.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
* WordPress dependencies.
33
*/
44
import { __ } from '@wordpress/i18n';
5-
import { useEffect, useState } from '@wordpress/element';
65
import { category } from '@wordpress/icons';
76

87
/**
98
* Internal dependencies
109
*/
11-
import { Button, Handoff, NewspackIcon, Notice, TabbedNavigation } from '../';
12-
import { HANDOFF_KEY } from '../consts';
10+
import { Button, Handoff, NewspackIcon, Notice, HandoffMessage, TabbedNavigation } from '../';
1311
import { buttonProps } from '../../../shared/js/';
1412
import './style.scss';
1513

@@ -23,7 +21,6 @@ import classnames from 'classnames';
2321
*/
2422
export default function withWizardScreen( WrappedComponent, { hidePrimaryButton } = {} ) {
2523
const WrappedWithWizardScreen = props => {
26-
const [ handoffMessage, setHandoffMessage ] = useState( false );
2724
const {
2825
className,
2926
buttonText,
@@ -38,14 +35,6 @@ export default function withWizardScreen( WrappedComponent, { hidePrimaryButton
3835
disableUpcomingInTabbedNavigation,
3936
} = props;
4037

41-
useEffect( () => {
42-
const handoff = JSON.parse( localStorage.getItem( HANDOFF_KEY ) );
43-
44-
if ( handoff?.message ) {
45-
setHandoffMessage( handoff.message );
46-
}
47-
}, [] );
48-
4938
const retrievedButtonProps = buttonProps( buttonAction );
5039
const retrievedSecondaryButtonProps = buttonProps( secondaryButtonAction );
5140
const SecondaryCTAComponent = retrievedSecondaryButtonProps.plugin ? Handoff : Button;
@@ -99,9 +88,7 @@ export default function withWizardScreen( WrappedComponent, { hidePrimaryButton
9988
/>
10089
) }
10190

102-
{ handoffMessage && (
103-
<Notice isHandoff isDismissible={ false } rawHTML noticeText={ handoffMessage } />
104-
) }
91+
<HandoffMessage />
10592

10693
<div className={ classnames( 'newspack-wizard newspack-wizard__content', className ) }>
10794
{ typeof renderAboveContent === 'function' ? renderAboveContent() : null }

assets/components/src/wizard/index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,26 @@ import classnames from 'classnames';
77
* WordPress dependencies.
88
*/
99
import { useSelect } from '@wordpress/data';
10-
import { useEffect, useState } from '@wordpress/element';
10+
import { useState } from '@wordpress/element';
1111
import { __ } from '@wordpress/i18n';
1212
import { category } from '@wordpress/icons';
1313

1414
/**
1515
* Internal dependencies
1616
*/
17-
import { Footer, Notice, Button, NewspackIcon, TabbedNavigation, PluginInstaller } from '../';
17+
import {
18+
Footer,
19+
Notice,
20+
Button,
21+
NewspackIcon,
22+
TabbedNavigation,
23+
PluginInstaller,
24+
HandoffMessage,
25+
} from '../';
1826
import Router from '../proxied-imports/router';
1927
import registerStore, { WIZARD_STORE_NAMESPACE } from './store';
2028
import { useWizardData } from './store/utils';
2129
import WizardError from './components/WizardError';
22-
import { HANDOFF_KEY } from '../consts';
2330

2431
registerStore();
2532

@@ -35,22 +42,13 @@ const Wizard = ( {
3542
renderAboveSections,
3643
requiredPlugins = [],
3744
} ) => {
38-
const [ handoffMessage, setHandoffMessage ] = useState( false );
3945
const isLoading = useSelect( select => select( WIZARD_STORE_NAMESPACE ).isLoading() );
4046
const isQuietLoading = useSelect( select => select( WIZARD_STORE_NAMESPACE ).isQuietLoading() );
4147

4248
// Trigger initial data fetch. Some sections might not use the wizard data,
4349
// but for consistency, fetching is triggered regardless of the section.
4450
useSelect( select => select( WIZARD_STORE_NAMESPACE ).getWizardAPIData( apiSlug ) );
4551

46-
useEffect( () => {
47-
const handoff = JSON.parse( localStorage.getItem( HANDOFF_KEY ) );
48-
49-
if ( handoff?.message ) {
50-
setHandoffMessage( handoff.message );
51-
}
52-
}, [] );
53-
5452
let displayedSections = sections.filter( section => ! section.isHidden );
5553

5654
const [ pluginRequirementsSatisfied, setPluginRequirementsSatisfied ] = useState(
@@ -112,9 +110,7 @@ const Wizard = ( {
112110
<WizardError />
113111
</TabbedNavigation>
114112
) }
115-
{ handoffMessage && (
116-
<Notice isHandoff isDismissible={ false } rawHTML noticeText={ handoffMessage } />
117-
) }
113+
<HandoffMessage />
118114

119115
<Switch>
120116
{ displayedSections.map( ( section, index ) => {

assets/wizards/engagement/views/newsletters/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ import {
3232
export const NewspackNewsletters = ( {
3333
className,
3434
onUpdate,
35-
authUrl = false,
36-
setAuthUrl,
37-
isOnboarding = true,
3835
initialProvider,
39-
setInitialProvider,
4036
newslettersConfig,
41-
setLockedLists,
37+
isOnboarding = true,
38+
authUrl = false,
39+
setInitialProvider = () => {},
40+
setAuthUrl = () => {},
41+
setLockedLists = () => {},
4242
} ) => {
4343
const [ inFlight, setInFlight ] = useState( false );
4444
const [ error, setError ] = useState( false );

0 commit comments

Comments
 (0)