fix: Navigation issues - newsletter menu, coupon routing, module toggle

Navigation Fixes:
1. Newsletter submenu now hidden when module disabled
   - NavigationRegistry checks ModuleRegistry::is_enabled('newsletter')
   - Menu updates dynamically based on module status

2. Module toggle now updates navigation in real-time
   - Fixed toggle_module API to return success response (was returning error)
   - Navigation cache flushes and rebuilds when module toggled
   - Newsletter menu appears/disappears immediately after toggle

3. Coupon routes now activate Marketing menu (not Dashboard)
   - Added special case in useActiveSection for /coupons paths
   - Marketing menu stays active when viewing coupons
   - Submenu shows correct Marketing items (Newsletter, Coupons)

4. Dashboard menu no longer always shows active
   - Fixed by proper path matching in useActiveSection
   - Only active when on dashboard routes

Files Modified (4):
- includes/Compat/NavigationRegistry.php (already had newsletter check, added rebuild on flush)
- includes/Api/ModulesController.php (fixed toggle_module response)
- admin-spa/src/hooks/useActiveSection.ts (added /coupons special case)
- admin-spa/dist/app.js (rebuilt)

All 4 navigation issues resolved!
This commit is contained in:
Dwindi Ramadhana
2025-12-26 21:40:55 +07:00
parent daebd5f989
commit 9b8fa7d0f9
3 changed files with 36 additions and 21 deletions

View File

@@ -11,6 +11,12 @@ export function useActiveSection(): { main: MainNode; all: MainNode[] } {
if (settingsNode) return settingsNode;
}
// Special case: /coupons should match marketing section
if (pathname === '/coupons' || pathname.startsWith('/coupons/')) {
const marketingNode = navTree.find(n => n.key === 'marketing');
if (marketingNode) return marketingNode;
}
// Try to find section by matching path prefix
for (const node of navTree) {
if (node.path === '/') continue; // Skip dashboard for now