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

@@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button';
import { formatPrice } from '@/lib/currency';
import { toast } from 'sonner';
import { useModules } from '@/hooks/useModules';
import { useModuleSettings } from '@/hooks/useModuleSettings';
interface WishlistItem {
product_id: number;
@@ -28,6 +29,7 @@ export default function Wishlist() {
const [items, setItems] = useState<WishlistItem[]>([]);
const [loading, setLoading] = useState(true);
const { isEnabled, isLoading: modulesLoading } = useModules();
const { settings: wishlistSettings } = useModuleSettings('wishlist');
if (modulesLoading) {
return (
@@ -217,19 +219,21 @@ export default function Wishlist() {
</div>
{/* Actions */}
<Button
onClick={() => handleAddToCart(item)}
disabled={item.stock_status === 'outofstock'}
className="w-full"
size="sm"
>
<ShoppingCart className="w-4 h-4 mr-2" />
{item.stock_status === 'outofstock'
? 'Out of Stock'
: item.type === 'variable'
? 'Select Options'
: 'Add to Cart'}
</Button>
{(wishlistSettings.show_add_to_cart_button ?? true) && (
<Button
onClick={() => handleAddToCart(item)}
disabled={item.stock_status === 'outofstock'}
className="w-full"
size="sm"
>
<ShoppingCart className="w-4 h-4 mr-2" />
{item.stock_status === 'outofstock'
? 'Out of Stock'
: item.type === 'variable'
? 'Select Options'
: 'Add to Cart'}
</Button>
)}
</div>
</div>
))}