Skip to content

Commit

Permalink
feat: pr feedback - added redirect, activation skip and remove `activ…
Browse files Browse the repository at this point in the history
…ationStep[0]`
  • Loading branch information
jaredrethman committed Apr 15, 2024
1 parent 6b5bd22 commit 3110cb5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions assets/wizards/engagement/views/reader-activation/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import {
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;

Expand All @@ -32,6 +35,7 @@ export default withWizardScreen( () => {
status: '',
isSkipped: is_skipped_campaign_setup === '1',
} );
const history = useHistory();

const fetchPrompts = () => {
setError( false );
Expand Down Expand Up @@ -78,6 +82,7 @@ export default withWizardScreen( () => {
}
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: '' } );
Expand Down
12 changes: 11 additions & 1 deletion assets/wizards/engagement/views/reader-activation/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const activationSteps = [
__( 'Activating Reader Activation Campaign…', 'newspack-plugin' ),
];

const activationStepsCount = activationSteps.length;

/**
* Get a random number between min and max.
*
Expand All @@ -60,7 +62,12 @@ export default withWizardScreen( () => {
const [ progressLabel, setProgressLabel ] = useState( false );
const [ completed, setCompleted ] = useState( false );
const timer = useRef();
const { reader_activation_url } = newspack_engagement_wizard;
const { reader_activation_url, is_skipped_campaign_setup = '' } = newspack_engagement_wizard;
const isSkippedCampaignSetup = is_skipped_campaign_setup === '1';

if ( isSkippedCampaignSetup && activationSteps.length !== activationStepsCount - 1 ) {
activationSteps.shift();
}

useEffect( () => {
if ( timer.current ) {
Expand Down Expand Up @@ -95,6 +102,9 @@ export default withWizardScreen( () => {
await apiFetch( {
path: '/newspack/v1/wizard/newspack-engagement-wizard/reader-activation/activate',
method: 'post',
data: {
skip_activation: isSkippedCampaignSetup,
},
} )
);
} catch ( err ) {
Expand Down
9 changes: 7 additions & 2 deletions includes/wizards/class-engagement-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

namespace Newspack;

use TypeError;
use WP_Error;
use WP_REST_Request;
use WP_REST_Response;

defined( 'ABSPATH' ) || exit;

Expand Down Expand Up @@ -276,10 +279,12 @@ public function api_update_reader_activation_settings( $request ) {
/**
* Activate reader activation and publish RAS prompts/segments.
*
* @param WP_REST_Request $request WP Rest Request object.
* @return WP_REST_Response
*/
public function api_activate_reader_activation() {
$response = Reader_Activation::activate();
public function api_activate_reader_activation( WP_REST_Request $request ) {
$skip_activation = $request->get_param( 'skip_activation' ) ?? false;
$response = $skip_activation ? true : Reader_Activation::activate();

if ( \is_wp_error( $response ) ) {
return new \WP_REST_Response( [ 'message' => $response->get_error_message() ], 400 );
Expand Down

0 comments on commit 3110cb5

Please sign in to comment.