diff --git a/assets/wizards/engagement/components/prerequisite.tsx b/assets/wizards/engagement/components/prerequisite.tsx
index 0c8b9aa825..16ae5b86fd 100644
--- a/assets/wizards/engagement/components/prerequisite.tsx
+++ b/assets/wizards/engagement/components/prerequisite.tsx
@@ -23,10 +23,11 @@ export default function Prerequisite( {
saveConfig,
}: PrequisiteProps ) {
const { href } = prerequisite;
+ const isValid = Boolean( prerequisite.active || prerequisite.is_skipped );
// If the prerequisite is active but has empty fields, show a warning.
const hasEmptyFields = () => {
- if ( prerequisite.active && prerequisite.fields && prerequisite.warning ) {
+ if ( isValid && prerequisite.fields && prerequisite.warning ) {
const emptyValues = Object.keys( prerequisite.fields ).filter(
fieldName => '' === config[ fieldName as keyof Config ]
);
@@ -93,9 +94,7 @@ export default function Prerequisite( {
: sprintf(
// Translators: Save or Update settings.
__( '%s settings', 'newspack-plugin' ),
- prerequisite.active
- ? __( 'Update', 'newspack-plugin' )
- : __( 'Save', 'newspack-plugin' )
+ isValid ? __( 'Update', 'newspack-plugin' ) : __( 'Save', 'newspack-plugin' )
) }
@@ -138,7 +137,7 @@ export default function Prerequisite( {
} }
>
{ /* eslint-disable no-nested-ternary */ }
- { ( prerequisite.active
+ { ( isValid
? __( 'Update ', 'newspack-plugin' )
: prerequisite.fields
? __( 'Save ', 'newspack-plugin' )
@@ -158,8 +157,10 @@ export default function Prerequisite( {
);
let status = __( 'Pending', 'newspack-plugin' );
- if ( prerequisite.active ) {
- status = __( 'Ready', 'newspack-plugin' );
+ if ( isValid ) {
+ status = `${ __( 'Ready', 'newspack-plugin' ) } ${
+ prerequisite.is_skipped ? `(${ __( 'Skipped', 'newspack-plugin' ) })` : ''
+ }`;
}
if ( prerequisite.is_unavailable ) {
status = __( 'Unavailable', 'newspack-plugin' );
@@ -170,14 +171,14 @@ export default function Prerequisite( {
className="newspack-ras-wizard__prerequisite"
isMedium
expandable={ ! prerequisite.is_unavailable }
- collapse={ prerequisite.active }
+ collapse={ isValid }
title={ prerequisite.label }
description={ sprintf(
/* translators: %s: Prerequisite status */
__( 'Status: %s', 'newspack-plugin' ),
status
) }
- checkbox={ prerequisite.active ? 'checked' : 'unchecked' }
+ checkbox={ isValid ? 'checked' : 'unchecked' }
notificationLevel="info"
notification={ hasEmptyFields() }
>
diff --git a/assets/wizards/engagement/components/types.ts b/assets/wizards/engagement/components/types.ts
index e1e947d277..dc577e72e3 100644
--- a/assets/wizards/engagement/components/types.ts
+++ b/assets/wizards/engagement/components/types.ts
@@ -127,6 +127,7 @@ export type PrequisiteProps = {
action_enabled?: boolean;
disabled_text?: string;
is_unavailable?: boolean;
+ is_skipped?: boolean;
};
};
diff --git a/assets/wizards/engagement/views/reader-activation/campaign.js b/assets/wizards/engagement/views/reader-activation/campaign.js
index 66bca1d63e..b9e216ab05 100644
--- a/assets/wizards/engagement/views/reader-activation/campaign.js
+++ b/assets/wizards/engagement/views/reader-activation/campaign.js
@@ -16,16 +16,26 @@ import {
SectionHeader,
Waiting,
withWizardScreen,
+ utils,
} from '../../../../components/src';
import Prompt from '../../components/prompt';
+import Router from '../../../../components/src/proxied-imports/router';
import './style.scss';
+const { useHistory } = Router;
+
export default withWizardScreen( () => {
+ const { is_skipped_campaign_setup, reader_activation_url } = newspack_engagement_wizard;
+
const [ inFlight, setInFlight ] = useState( false );
const [ error, setError ] = useState( false );
const [ prompts, setPrompts ] = useState( null );
const [ allReady, setAllReady ] = useState( false );
- const { reader_activation_url } = newspack_engagement_wizard;
+ const [ skipped, setSkipped ] = useState( {
+ status: '',
+ isSkipped: is_skipped_campaign_setup === '1',
+ } );
+ const history = useHistory();
const fetchPrompts = () => {
setError( false );
@@ -40,6 +50,45 @@ export default withWizardScreen( () => {
.finally( () => setInFlight( false ) );
};
+ /**
+ * Display prompt requiring editors to confirm skipping, on confirmation send request to
+ * server to store skipped option in options table and redirect back to RAS
+ *
+ * @return {void}
+ */
+ async function onSkipCampaignSetup() {
+ if (
+ ! utils.confirmAction(
+ __(
+ 'Are you sure you want to skip setting up a reader activation campaign?',
+ 'newspack-plugin'
+ )
+ )
+ ) {
+ return;
+ }
+ setError( false );
+ setSkipped( { ...skipped, status: 'pending' } );
+ try {
+ const request = await apiFetch( {
+ path: '/newspack/v1/wizard/newspack-engagement-wizard/reader-activation/skip-campaign-setup',
+ method: 'POST',
+ data: { skip: ! skipped.isSkipped },
+ } );
+ if ( ! request.updated ) {
+ setError( { message: __( 'Server not updated', 'newspack-plugin' ) } );
+ setSkipped( { isSkipped: false, status: '' } );
+ return;
+ }
+ setSkipped( { isSkipped: Boolean( request.skipped ), status: '' } );
+ newspack_engagement_wizard.is_skipped_campaign_setup = request.skipped ? '1' : '';
+ history.push( '/reader-activation/complete' );
+ } catch ( err ) {
+ setError( err );
+ setSkipped( { isSkipped: false, status: '' } );
+ }
+ }
+
useEffect( () => {
window.scrollTo( 0, 0 );
fetchPrompts();
@@ -83,9 +132,21 @@ export default withWizardScreen( () => {
/>
) ) }
+