Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/tec 5163 help hub chat page #2227

Merged
merged 16 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 75 additions & 5 deletions src/Tribe/Admin/Help_Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* @since 4.0
*/

use TEC\Common\Configuration\Configuration;
use TEC\Common\Telemetry\Telemetry;

if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
Expand All @@ -17,6 +20,29 @@
*/
class Tribe__Admin__Help_Page {
//phpcs:ignore - legacy class naming.

/**
* @since TBD
*
* @var Configuration The configuration object.
*/
protected Configuration $config;

/**
* Initialize any required vars.
*/
public function __construct() {
$this->config = tribe( Configuration::class );

if ( ! defined( 'DOCSBOT_SUPPORT_KEY' ) ) {
// @todo Need key
define( 'DOCSBOT_SUPPORT_KEY', '' );
}
if ( ! defined( 'ZENDESK_CHAT_KEY' ) ) {
define( 'ZENDESK_CHAT_KEY', '' );
}
}

/**
* Static Singleton Factory Method
*
Expand All @@ -35,16 +61,56 @@ public function do_help_tab() {
$main = Tribe__Main::instance();
$template = new \Tribe__Template();

$template->set_values( [ 'main' => $main ] );
// Setup our admin notice.
$notice_slug = 'tec-common-help-chatbot-notice';
$notice_content = sprintf(
// translators: 1: the opening tag to the chatbot link, 2: the closing tag.
_x(
'To find the answer to all your questions use the %1$sTEC Chatbot%2$s',
'The callout notice to try the chatbot with a link to the page',
'tribe-common'
),
'<a data-tab-target="tec-help-tab" href="javascript:void(0);">',
'</a>'
);

// Our notices.
tribe_transient_notice(
$notice_slug,
"<p>$notice_content</p>",
[
'type' => 'info',
'dismiss' => true,
'priority' => 1,
'inline' => true,
],
YEAR_IN_SECONDS
);

$notice = Tribe__Admin__Notices::instance()->render( $notice_slug );
$common_telemetry = tribe( Telemetry::class );
$is_opted_in = $common_telemetry->calculate_optin_status();
$is_license_valid = Tribe__PUE__Checker::is_any_license_valid();
$zendesk_chat_key = $this->config->get( 'ZENDESK_CHAT_KEY' );

// Setup template for help page.
$template->set_values(
[
'main' => $main,
'notice' => $notice,
'is_opted_in' => $is_opted_in,
'is_license_valid' => $is_license_valid,
'zendesk_chat_key' => $zendesk_chat_key,
]
);

$template->set_template_origin( $main );
$template->set_template_folder( 'src/admin-views' );
$template->set_template_context_extract( true );
$template->set_template_folder_lookup( false );
$template->template( 'help-hub' );
}



/**
* Set up hooks.
*
Expand All @@ -58,7 +124,7 @@ public function hook() {
}

/**
* Enqueue the help page assets.
* Enqueue the Help page assets.
*
* @since TBD
*/
Expand All @@ -74,6 +140,9 @@ public function load_assets() {
null,
'admin_enqueue_scripts'
);

// Add the built-in accordion.
wp_enqueue_script( 'jquery-ui-accordion' );
}

/**
Expand Down Expand Up @@ -158,7 +227,7 @@ public function is_tec_tickets_help_page() {
}

/**
* Register the Admin assets for the help page
* Register the Admin assets for the Help and Troubleshooting pages
*
* @since 4.9.12
*
Expand All @@ -177,6 +246,7 @@ public function register_assets() {
'localize' => [
'name' => 'tribe_system_info',
'data' => [
'docsbot_key' => $this->config->get( 'DOCSBOT_SUPPORT_KEY' ),
'sysinfo_optin_nonce' => wp_create_nonce( 'sysinfo_optin_nonce' ),
'clipboard_btn_text' => _x( 'Copy to clipboard', 'Copy to clipboard button text.', 'tribe-common' ),
'clipboard_copied_text' => _x( 'System info copied', 'Copy to clipboard success message', 'tribe-common' ),
Expand Down
2 changes: 2 additions & 0 deletions src/Tribe/Admin/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ public function render( $slug, $content = null, $return = true, $wrap = false )
$classes[] = 'inline';
}

$content ??= $notice->content;

// Prevents Empty Notices
if ( empty( $content ) ) {
return false;
Expand Down
67 changes: 67 additions & 0 deletions src/Tribe/PUE/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ class Tribe__PUE__Checker {
*/
private $validate_query = [];

/**
* A unique list of instances of the PUE Checker that has been initialized.
*
* @since TBD
*
* @var Tribe__PUE__Checker[] Instances of checkers that have been registered.
*/
protected static $instances = [];

/**
* @var string The transient key.
*/
public const IS_ANY_LICENSE_VALID_TRANSIENT_KEY = 'IS_ANY_LICENSE_VALID_TRANSIENT';

/**
* Class constructor.
*
Expand All @@ -204,6 +218,8 @@ public function __construct( $pue_update_url, $slug = '', $options = [], $plugin
$this->set_options( $options );
$this->hooks();
$this->set_key_status_name();
// So we can reference our "registered" instances later.
self::$instances[ $slug ] ??= $this;
}

/**
Expand All @@ -222,6 +238,55 @@ public function is_key_valid() {
return 'valid' === $status;
}

/**
* Iterate on all the registered PUE Product Licenses we have and find if any are valid.
* Will revalidate the licenses if none are found to be valid.
*
* @since TBD
*
* @return bool
*/
public static function is_any_license_valid(): bool {
$valid_slug = 'valid';
$has_valid = false;

// Check our transient.
$transient_value = get_transient( self::IS_ANY_LICENSE_VALID_TRANSIENT_KEY );
if ( ! empty( $transient_value ) ) {
return $transient_value === $valid_slug;
}

// Check our local transient/cache first.
foreach ( self::$instances as $checker ) {
if ( $checker->is_key_valid() ) {
set_transient( self::IS_ANY_LICENSE_VALID_TRANSIENT_KEY, $valid_slug, HOUR_IN_SECONDS );
$has_valid = true;
break;
}
}

if ( ! $has_valid ) {
// Revalidate if we haven't found a valid license yet.
foreach ( self::$instances as $checker ) {
$license = get_option( $checker->get_license_option_key() );
$response = $checker->validate_key( $license );
// Is it valid?
if ( ! empty( $response['status'] ) ) {
set_transient( self::IS_ANY_LICENSE_VALID_TRANSIENT_KEY, $valid_slug, HOUR_IN_SECONDS );
$has_valid = true;
break;
}
}
}

// We found no valid licenses above.
if ( ! $has_valid ) {
set_transient( self::IS_ANY_LICENSE_VALID_TRANSIENT_KEY, 'invalid', HOUR_IN_SECONDS );
}

return get_transient( self::IS_ANY_LICENSE_VALID_TRANSIENT_KEY ) === $valid_slug;
}

/**
* Gets whether or not the PUE key validation check is expired.
*
Expand Down Expand Up @@ -323,6 +388,8 @@ public function hooks() {
add_filter( 'upgrader_pre_download', [ Tribe__PUE__Package_Handler::instance(), 'filter_upgrader_pre_download' ], 5, 3 );
}



/********************** Getter / Setter Functions **********************/

/**
Expand Down
21 changes: 0 additions & 21 deletions src/admin-views/help-hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,3 @@ class="tribe-events-admin-title__logo"
</div>
</div>

<script>
jQuery( document ).ready( function($) {
let currentTab = $( 'li.tec-nav__tab.tec-nav__tab--subnav-active' );
let tabContainer = $( '#' + currentTab.data( 'tab-target' ) );
$( '.tec-tab-container' ).hide();
tabContainer.show();

$( 'li.tec-nav__tab' ).on( 'click', function() {
let tab = $( this );
let tabTarget = $( '#' + tab.data( 'tab-target' ) );

$( 'li.tec-nav__tab' ).removeClass( 'tec-nav__tab--subnav-active' );
tab.addClass( 'tec-nav__tab--subnav-active' );

tabContainer.hide();
tabTarget.show();
tabContainer = tabTarget;
} );
} );
</script>

104 changes: 104 additions & 0 deletions src/admin-views/help-hub/resources-sidebar-has-license-has-consent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* The template that displays the resources sidebar.
*
* @var Tribe__Main $main The main common object.
* @var bool $is_opted_in Whether the user has opted in to telemetry.
* @var bool $is_license_valid Whether the user has any valid licenses.
*/

$stars_icon_url = tribe_resource_url( 'images/icons/stars.svg', false, null, $main );
$chat_icon_url = tribe_resource_url( 'images/icons/chat-bubble.svg', false, null, $main );

?>

<div class="tec-settings-form__sidebar tec-help-resources__sidebar">
<div class="tec-settings__sidebar-inner">
<h2>
<?php
echo esc_html_x(
'Our TEC support hub now offers an improved help experience',
'Help page resources sidebar header',
'tribe-common'
);
?>
</h2>
<p>
<?php
echo esc_html_x(
'Our Help page is better than ever with the addition of:',
'Describes why consent is beneficial',
'tribe-common'
);
?>
</p>

<div class="tec-settings__sidebar-icon-wrap">
<div>
<img class="tec-settings-infobox-logo"
src="<?php echo esc_url( $stars_icon_url ); ?>"
alt="AI chat bot logo"
>
</div>
<div class="tec-settings__sidebar-icon-wrap-content">
<h3>
<?php
echo esc_html_x(
'AI Chatbot',
'AI Chatbot sidebar header',
'tribe-common'
);
?>
</h3>
<p>
<?php
echo esc_html_x(
'Here to provide quick answers to your questions. It’s never been easier to find the right resource.',
'AI Chatbot support sidebar paragraph',
'tribe-common'
);
?>
</p>
</div>
</div>
<div class="tec-settings__sidebar-icon-wrap">
<div>
<img class="tec-settings-infobox-logo"
src="<?php echo esc_url( $chat_icon_url ); ?>"
alt="Support chat logo"
>
</div>
<div class="tec-settings__sidebar-icon-wrap-content">
<h3>
<?php
echo esc_html_x(
'Talk to our support team',
'Get support sidebar header',
'tribe-common'
);
?>
</h3>
<p>
<?php
echo esc_html_x(
'Our Support team is available to help you out 5 days a week:',
'Live support sidebar paragraph',
'tribe-common'
);
?>
</p>
<p>
<strong>
<?php
echo esc_html_x(
'Mon-Fri from 9:00 - 20:00 PST',
'Live support hours',
'tribe-common'
);
?>
</strong>
</p>
</div>
</div>
</div>
</div>
Loading
Loading