feat: add option to display onboarding on homepage and improve modal slide handling
This commit is contained in:
@@ -30,18 +30,7 @@ class Modal extends Component
|
||||
|
||||
$userId = Auth::id();
|
||||
|
||||
// Check if user has seen onboarding before
|
||||
if ($perSession) {
|
||||
// Use cookie for per-session tracking
|
||||
$hasSeenOnboarding = $testMode ? false : \Illuminate\Support\Facades\Cookie::has('onboarding_completed');
|
||||
$this->currentSlide = (int) \Illuminate\Support\Facades\Cookie::get('onboarding_current_slide', 0);
|
||||
} else {
|
||||
// Use database session for persistent tracking
|
||||
$hasSeenOnboarding = $testMode ? false : session()->get("onboarding_seen_{$userId}", false);
|
||||
$this->currentSlide = session()->get("onboarding_current_slide_{$userId}", 0);
|
||||
}
|
||||
|
||||
// Only show if user hasn't seen it and there are slides
|
||||
// Load slides first so we can validate currentSlide
|
||||
try {
|
||||
$this->slides = OnboardingSlide::where('enabled', true)
|
||||
->orderBy('sort', 'asc')
|
||||
@@ -50,9 +39,39 @@ class Modal extends Component
|
||||
} catch (\Exception $e) {
|
||||
// If query fails (e.g., missing columns), don't show modal
|
||||
$this->slides = [];
|
||||
$this->showModal = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->showModal = !$hasSeenOnboarding && count($this->slides) > 0 && $this->currentSlide < count($this->slides);
|
||||
// No slides configured, nothing to show
|
||||
if (count($this->slides) === 0) {
|
||||
$this->showModal = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if user has seen onboarding before
|
||||
if ($perSession) {
|
||||
// Use cookie for per-session tracking
|
||||
$hasSeenOnboarding = $testMode ? false : \Illuminate\Support\Facades\Cookie::has('onboarding_completed');
|
||||
$this->currentSlide = (int) \Illuminate\Support\Facades\Cookie::get('onboarding_current_slide', 0);
|
||||
} else {
|
||||
// Use database session for persistent tracking
|
||||
$hasSeenOnboarding = $testMode ? false : session()->get("onboarding_seen_{$userId}", false);
|
||||
$this->currentSlide = (int) session()->get("onboarding_current_slide_{$userId}", 0);
|
||||
}
|
||||
|
||||
// Reset currentSlide if out of bounds (slides may have been deleted/disabled)
|
||||
if ($this->currentSlide >= count($this->slides)) {
|
||||
$this->currentSlide = 0;
|
||||
// Clear the stored progress since it's invalid
|
||||
if ($perSession) {
|
||||
\Illuminate\Support\Facades\Cookie::queue(\Illuminate\Support\Facades\Cookie::forget('onboarding_current_slide'));
|
||||
} else {
|
||||
session()->forget("onboarding_current_slide_{$userId}");
|
||||
}
|
||||
}
|
||||
|
||||
$this->showModal = !$hasSeenOnboarding;
|
||||
}
|
||||
|
||||
public function getShowBackdropProperty()
|
||||
|
||||
@@ -45,6 +45,14 @@ class Onboarding extends Extension
|
||||
'required' => false,
|
||||
'default' => false,
|
||||
],
|
||||
[
|
||||
'name' => 'include_homepage',
|
||||
'type' => 'checkbox',
|
||||
'label' => 'Show on Homepage',
|
||||
'description' => 'Also display onboarding on the homepage. By default, onboarding only shows on internal pages like dashboard, services, etc.',
|
||||
'required' => false,
|
||||
'default' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -84,27 +92,40 @@ class Onboarding extends Extension
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
// Only register body hook if the table exists
|
||||
if (!Schema::hasTable('ext_onboarding_slides')) {
|
||||
return;
|
||||
}
|
||||
|
||||
\Illuminate\Support\Facades\Event::listen('body', function () {
|
||||
|
||||
if (!request()->is('admin/*') &&
|
||||
!request()->is('login') &&
|
||||
!request()->is('register') &&
|
||||
!request()->is('2fa') &&
|
||||
!request()->is('forgot-password') &&
|
||||
!request()->is('reset-password/*') &&
|
||||
!request()->is('verify-email') &&
|
||||
!request()->is('/') &&
|
||||
\Illuminate\Support\Facades\Auth::check()) {
|
||||
return [
|
||||
'view' => view('onboarding::widget')->render(),
|
||||
];
|
||||
// Skip if table doesn't exist
|
||||
if (!Schema::hasTable('ext_onboarding_slides')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if homepage should be included
|
||||
$extension = ExtensionHelper::getExtension('other', 'Onboarding');
|
||||
$includeHomepage = $extension->config('include_homepage', false);
|
||||
|
||||
// Skip admin and auth pages
|
||||
if (request()->is('admin/*') ||
|
||||
request()->is('login') ||
|
||||
request()->is('register') ||
|
||||
request()->is('2fa') ||
|
||||
request()->is('forgot-password') ||
|
||||
request()->is('reset-password/*') ||
|
||||
request()->is('verify-email')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Skip homepage unless explicitly included
|
||||
if (!$includeHomepage && request()->is('/')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only show for authenticated users
|
||||
if (!\Illuminate\Support\Facades\Auth::check()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'view' => view('onboarding::widget'),
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user