feat: add option to display onboarding on homepage and improve modal slide handling

This commit is contained in:
2025-12-03 22:38:46 -05:00
parent ea471aa6a9
commit 5c4e39a2f5
2 changed files with 72 additions and 32 deletions

View File

@@ -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()