* Add survey class and URL builder method

* Use survey URL method in notes

* Pass survey URL to opt out modal

* Simplify source/query filter

* Move survey URL to constant
This commit is contained in:
Joshua T Flowers 2021-01-15 09:54:26 -05:00 committed by GitHub
parent b606a6933e
commit 24ccd6803b
6 changed files with 59 additions and 4 deletions

View File

@ -19,6 +19,10 @@ export class NavigationOptOutContainer extends Component {
return null;
}
if ( ! window.surveyData || ! window.surveyData.url ) {
return null;
}
return (
<Modal
title={ __( 'Help us improve', 'woocommerce-admin' ) }
@ -45,7 +49,7 @@ export class NavigationOptOutContainer extends Component {
<Button
isPrimary
target="_blank"
href="https://automattic.survey.fm/new-navigation-opt-out"
href={ window.surveyData.url }
onClick={ () =>
this.setState( { isModalOpen: false } )
}

View File

@ -8,6 +8,7 @@
namespace Automattic\WooCommerce\Admin\Features\Navigation;
use Automattic\WooCommerce\Admin\Loader;
use Automattic\WooCommerce\Admin\Survey;
use Automattic\WooCommerce\Admin\Features\Navigation\Screen;
use Automattic\WooCommerce\Admin\Features\Navigation\Menu;
use Automattic\WooCommerce\Admin\Features\Navigation\CoreMenu;
@ -203,6 +204,14 @@ class Init {
true
);
wp_localize_script(
'wc-admin-navigation-opt-out',
'surveyData',
array(
'url' => Survey::get_url( '/new-navigation-opt-out' ),
)
);
delete_option( 'woocommerce_navigation_show_opt_out' );
}
}

View File

@ -9,6 +9,8 @@ namespace Automattic\WooCommerce\Admin\Notes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\Survey;
/**
* Giving_Feedback_Notes
*/
@ -46,7 +48,7 @@ class GivingFeedbackNotes {
$note->add_action(
'share-feedback',
__( 'Share feedback', 'woocommerce-admin' ),
'https://automattic.survey.fm/store-setup-survey'
Survey::get_url( '/store-setup-survey' )
);
return $note;
}

View File

@ -6,6 +6,7 @@
namespace Automattic\WooCommerce\Admin\Notes;
use Automattic\WooCommerce\Admin\Loader;
use Automattic\WooCommerce\Admin\Survey;
defined( 'ABSPATH' ) || exit;
@ -42,7 +43,7 @@ class NavigationFeedback {
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
$note->set_name( self::NOTE_NAME );
$note->set_source( 'woocommerce-admin' );
$note->add_action( 'share-feedback', __( 'Share feedback', 'woocommerce-admin' ), 'https://automattic.survey.fm/new-navigation' );
$note->add_action( 'share-feedback', __( 'Share feedback', 'woocommerce-admin' ), Survey::get_url( '/new-navigation' ) );
return $note;
}
}

View File

@ -6,6 +6,7 @@
namespace Automattic\WooCommerce\Admin\Notes;
use Automattic\WooCommerce\Admin\Loader;
use Automattic\WooCommerce\Admin\Survey;
defined( 'ABSPATH' ) || exit;
@ -56,7 +57,7 @@ class NavigationFeedbackFollowUp {
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
$note->set_name( self::NOTE_NAME );
$note->set_source( 'woocommerce-admin' );
$note->add_action( 'share-feedback', __( 'Share feedback', 'woocommerce-admin' ), 'https://automattic.survey.fm/new-navigation' );
$note->add_action( 'share-feedback', __( 'Share feedback', 'woocommerce-admin' ), Survey::get_url( '/new-navigation' ) );
return $note;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Survey helper methods.
*/
namespace Automattic\WooCommerce\Admin;
defined( 'ABSPATH' ) || exit;
/**
* Survey Class.
*/
class Survey {
/**
* Survey URL.
*/
const SURVEY_URL = 'https://automattic.survey.fm';
/**
* Get a survey's URL from a path.
*
* @param string $path Path of the survey.
* @param array $query Query arguments as key value pairs.
* @return string Full URL to survey.
*/
public static function get_url( $path, $query = array() ) {
$url = self::SURVEY_URL . $path;
$query_args = apply_filters( 'woocommerce_admin_survey_query', $query );
if ( ! empty( $query_args ) ) {
$query_string = http_build_query( $query_args );
$url = $url . '?' . $query_string;
}
return $url;
}
}