Skip to content

Commit

Permalink
PES-2565: Wizard (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
zemekoule authored Feb 28, 2025
2 parents bae4741 + bf9f656 commit e72b3cc
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ services:
- Packetery\Module\Views\AssetManager
- Packetery\Module\Shipping\ShippingProvider
- Packetery\Module\Shipping\ShippingMethodGenerator
- Packetery\Module\Views\WizardAssetManager
27 changes: 27 additions & 0 deletions public/js/tours/admin-wizard-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const driver = window.driver.js.driver;

const driverObj = driver(
{
showProgress: true,
progressText: '{{current}} ' + adminWizardTourSettings.translations.of + ' {{total}}',
showButtons: [
'next',
'previous',
'close'
],
nextBtnText: adminWizardTourSettings.translations.next,
prevBtnText: adminWizardTourSettings.translations.previous,
doneBtnText: adminWizardTourSettings.translations.close,
steps: [
{ element: '#frm-packetery-api_password', popover: { title: adminWizardTourSettings.translations.apiPassword.title, description: adminWizardTourSettings.translations.apiPassword.description } },
{ element: '#frm-packetery-sender', popover: { title: adminWizardTourSettings.translations.apiSender.title, description: adminWizardTourSettings.translations.apiSender.description } },
{ element: '.sidebar', popover: { title: 'Title', description: 'Description' } },
{ element: '.footer', popover: { title: 'Title', description: 'Description' } },
],
onDestroyStarted: function () {
if (!driverObj.hasNextStep() || window.confirm("Are you sure?")) {
driverObj.destroy();
}
}
});
driverObj.drive();
1 change: 1 addition & 0 deletions public/libs/driverjs-1.3.4/driver.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions public/libs/driverjs-1.3.4/driver.js.iife.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/Packetery/Module/Hooks/HookRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Packetery\Module\Views\ViewAdmin;
use Packetery\Module\Views\ViewFrontend;
use Packetery\Module\Views\ViewMail;
use Packetery\Module\Views\WizardAssetManager;

class HookRegistrar {

Expand Down Expand Up @@ -239,6 +240,11 @@ class HookRegistrar {
*/
private $shippingProvider;

/**
* @var WizardAssetManager
*/
private $wizardAssetManager;

public function __construct(
PluginHooks $pluginHooks,
MessageManager $messageManager,
Expand Down Expand Up @@ -278,7 +284,8 @@ public function __construct(
PacketSynchronizer $packetSynchronizer,
CheckoutSettings $checkoutSettings,
ModuleHelper $moduleHelper,
ShippingProvider $shippingProvider
ShippingProvider $shippingProvider,
WizardAssetManager $wizardAssetManager
) {
$this->messageManager = $messageManager;
$this->checkout = $checkout;
Expand Down Expand Up @@ -319,6 +326,7 @@ public function __construct(
$this->checkoutSettings = $checkoutSettings;
$this->moduleHelper = $moduleHelper;
$this->shippingProvider = $shippingProvider;
$this->wizardAssetManager = $wizardAssetManager;
}

public function register(): void {
Expand Down Expand Up @@ -366,6 +374,7 @@ private function registerBackEnd(): void {
if ( $this->wpAdapter->doingAjax() === false ) {
$this->wpAdapter->addAction( 'init', [ $this->messageManager, 'init' ] );
$this->wpAdapter->addAction( 'admin_enqueue_scripts', [ $this->assetManager, 'enqueueAdminAssets' ] );
$this->wpAdapter->addAction( 'admin_enqueue_scripts', [ $this->wizardAssetManager, 'enqueueWizardAssets' ] );
$this->wpAdapter->addAction(
'admin_notices',
function () {
Expand Down
4 changes: 2 additions & 2 deletions src/Packetery/Module/Views/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function __construct(
* @param bool $inFooter Tells where to include script.
* @param array $deps Script dependencies.
*/
private function enqueueScript( string $name, string $file, bool $inFooter, array $deps = [] ): void {
public function enqueueScript( string $name, string $file, bool $inFooter, array $deps = [] ): void {
$this->wpAdapter->enqueueScript(
$name,
$this->wpAdapter->pluginDirUrl( ModuleHelper::getPluginMainFilePath() ) . $file,
Expand All @@ -115,7 +115,7 @@ private function enqueueScript( string $name, string $file, bool $inFooter, arra
* @param string $name Name of script.
* @param string $file Relative file path.
*/
private function enqueueStyle( string $name, string $file ): void {
public function enqueueStyle( string $name, string $file ): void {
$this->wpAdapter->enqueueStyle(
$name,
$this->wpAdapter->pluginDirUrl( ModuleHelper::getPluginMainFilePath() ) . $file,
Expand Down
85 changes: 85 additions & 0 deletions src/Packetery/Module/Views/WizardAssetManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Packetery\Module\Views;

use Packetery\Module\Framework\WpAdapter;
use Packetery\Module\Options\Page;
use Packetery\Nette\Http\Request;

class WizardAssetManager {
/**
* @var WpAdapter
*/
private $wpAdapter;

/**
* @var AssetManager
*/
private $assetManager;

/**
* @var Request
*/
private $request;

public function __construct(
AssetManager $assetManager,
Request $request,
WpAdapter $wpAdapter
) {
$this->assetManager = $assetManager;
$this->request = $request;
$this->wpAdapter = $wpAdapter;
}

public function enqueueWizardAssets(): void {
$page = $this->request->getQuery( 'page' );
$isWizardEnabled = $this->request->getQuery( 'wizard-enabled' ) === 'true';
$isWizardExampleTourEnabled = $this->request->getQuery( 'wizard-example-tour-enabled' ) === 'true';

if ( $page === Page::SLUG && $isWizardEnabled ) {
$this->assetManager->enqueueStyle( 'packetery-driverjs-css', 'public/libs/driverjs-1.3.4/driver.css' );
$this->assetManager->enqueueScript( 'packetery-driverjs', 'public/libs/driverjs-1.3.4/driver.js.iife.js', true );

$adminWizardTourSettings = [
'translations' => [
'next' => $this->wpAdapter->__( 'Next', 'packeta' ),
'previous' => $this->wpAdapter->__( 'Previous', 'packeta' ),
'close' => $this->wpAdapter->__( 'Close', 'packeta' ),
'of' => $this->wpAdapter->__( 'of', 'packeta' ),
'apiPassword' => [
'title' => $this->wpAdapter->__( 'API password', 'packeta' ),
'description' => sprintf(
$this->wpAdapter->__( 'API password can be found at %s', 'packeta' ),
'<a href="https://client.packeta.com/support" target="_blank">https://client.packeta.com/support<a/>'
),
],
'apiSender' => [
'title' => $this->wpAdapter->__( 'Sender', 'packeta' ),
'description' => sprintf(
/* translators: 1: emphasis start 2: emphasis end 3: client section link start 4: client section link end */
esc_html__( 'Fill here %1$ssender label%2$s - you will find it in %3$sclient section%4$s - user information - field \'Indication\'.', 'packeta' ),
'<strong>',
'</strong>',
'<a href="https://client.packeta.com/senders" target="_blank">',
'</a>'
),
],
],
];

if ( $isWizardExampleTourEnabled ) {
$this->assetManager->enqueueScript(
'packetery-admin-wizard-tour',
'public/js/tours/admin-wizard-example.js',
true,
[
'packetery-driverjs',
]
);

$this->wpAdapter->localizeScript( 'packetery-admin-wizard-tour', 'adminWizardTourSettings', $adminWizardTourSettings );
}
}
}
}

0 comments on commit e72b3cc

Please sign in to comment.