feat: Implement centralized module management system
- Add ModuleRegistry for managing built-in modules (newsletter, wishlist, affiliate, subscription, licensing) - Add ModulesController REST API for module enable/disable - Create Modules settings page with category grouping and toggle controls - Integrate module checks across admin-spa and customer-spa - Add useModules hook for both SPAs to check module status - Hide newsletter from footer builder when module disabled - Hide wishlist features when module disabled (product cards, account menu, wishlist page) - Protect wishlist API endpoints with module checks - Auto-update navigation tree when modules toggled - Clean up obsolete documentation files - Add comprehensive documentation: - MODULE_SYSTEM_IMPLEMENTATION.md - MODULE_INTEGRATION_SUMMARY.md - ADDON_MODULE_INTEGRATION.md (proposal) - ADDON_MODULE_DESIGN_DECISIONS.md (design doc) - FEATURE_ROADMAP.md - SHIPPING_INTEGRATION.md Module system provides: - Centralized enable/disable for all features - Automatic navigation updates - Frontend/backend integration - Foundation for addon-module unification
This commit is contained in:
31
customer-spa/src/hooks/useModules.ts
Normal file
31
customer-spa/src/hooks/useModules.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '@/lib/api/client';
|
||||
|
||||
interface ModulesResponse {
|
||||
enabled: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to check if modules are enabled
|
||||
* Uses public endpoint, cached for performance
|
||||
*/
|
||||
export function useModules() {
|
||||
const { data, isLoading } = useQuery<ModulesResponse>({
|
||||
queryKey: ['modules-enabled'],
|
||||
queryFn: async () => {
|
||||
const response = await api.get('/modules/enabled') as any;
|
||||
return response.data;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
|
||||
});
|
||||
|
||||
const isEnabled = (moduleId: string): boolean => {
|
||||
return data?.enabled?.includes(moduleId) ?? false;
|
||||
};
|
||||
|
||||
return {
|
||||
enabledModules: data?.enabled ?? [],
|
||||
isEnabled,
|
||||
isLoading,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user