fix: Dashboard always active + Full wishlist settings implementation

Dashboard Navigation Fix:
- Fixed ActiveNavLink to only activate Dashboard on / or /dashboard/* paths
- Dashboard no longer shows active when on other routes (Marketing, Settings, etc.)
- Proper path matching logic for all main menu items

Wishlist Settings - Full Implementation:
Backend (PHP):
1. Guest Wishlist Support
   - Modified check_permission() to allow guests if enable_guest_wishlist is true
   - Guests can now add/remove wishlist items (stored in user meta when they log in)

2. Max Items Limit
   - Added max_items_per_wishlist enforcement in add_to_wishlist()
   - Returns error when limit reached with helpful message
   - 0 = unlimited (default)

Frontend (React):
3. Show in Header Setting
   - Added useModuleSettings hook to customer-spa
   - Wishlist icon respects show_in_header setting (default: true)
   - Icon hidden when setting is false

4. Show Add to Cart Button Setting
   - Wishlist page checks show_add_to_cart_button setting
   - Add to cart buttons hidden when setting is false (default: true)
   - Allows wishlist-only mode without purchase prompts

Files Added (1):
- customer-spa/src/hooks/useModuleSettings.ts

Files Modified (5):
- admin-spa/src/App.tsx (dashboard active fix)
- includes/Frontend/WishlistController.php (guest support, max items)
- customer-spa/src/layouts/BaseLayout.tsx (show_in_header)
- customer-spa/src/pages/Account/Wishlist.tsx (show_add_to_cart_button)
- admin-spa/dist/app.js + customer-spa/dist/app.js (rebuilt)

Implemented Settings (4 of 8):
 enable_guest_wishlist - Backend permission check
 show_in_header - Frontend icon visibility
 max_items_per_wishlist - Backend validation
 show_add_to_cart_button - Frontend button visibility

Not Yet Implemented (4 of 8):
- wishlist_page (page selector - would need routing logic)
- enable_sharing (share functionality - needs share UI)
- enable_email_notifications (back in stock - needs cron job)
- enable_multiple_wishlists (multiple lists - needs data structure change)

All core wishlist settings now functional!
This commit is contained in:
Dwindi Ramadhana
2025-12-26 21:57:56 +07:00
parent 9b8fa7d0f9
commit 863610043d
5 changed files with 80 additions and 19 deletions

View File

@@ -99,15 +99,23 @@ function ActiveNavLink({ to, startsWith, end, className, children, childPaths }:
to={to}
end={end}
className={(nav) => {
// Special case: Dashboard should also match root path "/"
const isDashboard = starts === '/dashboard' && location.pathname === '/';
// Special case: Dashboard should ONLY match root path "/" or paths starting with "/dashboard"
const isDashboard = starts === '/dashboard' && (location.pathname === '/' || location.pathname.startsWith('/dashboard'));
// Check if current path matches any child paths (e.g., /coupons under Marketing)
const matchesChild = childPaths && Array.isArray(childPaths)
? childPaths.some((childPath: string) => location.pathname.startsWith(childPath))
: false;
const activeByPath = starts ? (location.pathname.startsWith(starts) || isDashboard || matchesChild) : false;
// For dashboard: only active if isDashboard is true
// For others: active if path starts with their path OR matches a child path
let activeByPath = false;
if (starts === '/dashboard') {
activeByPath = isDashboard;
} else if (starts) {
activeByPath = location.pathname.startsWith(starts) || matchesChild;
}
const mergedActive = nav.isActive || activeByPath;
if (typeof className === 'function') {
// Preserve caller pattern: className receives { isActive }