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

@@ -260,10 +260,12 @@ class NavigationRegistry {
}
/**
* Flush the navigation cache
* Flush navigation cache
*/
public static function flush() {
delete_option(self::NAV_OPTION);
// Rebuild immediately after flush
self::build_nav_tree();
}
/**