Phase 0: Add frontend module config and update settings store
- Created modules.config.ts with module definitions - Added ModuleEnableSettings API functions - Updated settingsStore with module enable settings support - Added isModuleEnabled helper method
This commit is contained in:
110
frontend/src/config/modules.config.ts
Normal file
110
frontend/src/config/modules.config.ts
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
/**
|
||||||
|
* Module Configuration
|
||||||
|
* Defines all available modules and their properties
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface ModuleConfig {
|
||||||
|
name: string;
|
||||||
|
route: string;
|
||||||
|
icon?: string;
|
||||||
|
description?: string;
|
||||||
|
enabled: boolean; // Will be checked from API
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MODULES: Record<string, ModuleConfig> = {
|
||||||
|
planner: {
|
||||||
|
name: 'Planner',
|
||||||
|
route: '/planner',
|
||||||
|
icon: '📊',
|
||||||
|
description: 'Keyword research and clustering',
|
||||||
|
enabled: true, // Default, will be checked from API
|
||||||
|
},
|
||||||
|
writer: {
|
||||||
|
name: 'Writer',
|
||||||
|
route: '/writer',
|
||||||
|
icon: '✍️',
|
||||||
|
description: 'Content generation and management',
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
thinker: {
|
||||||
|
name: 'Thinker',
|
||||||
|
route: '/thinker',
|
||||||
|
icon: '🧠',
|
||||||
|
description: 'AI prompts and strategies',
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
automation: {
|
||||||
|
name: 'Automation',
|
||||||
|
route: '/automation',
|
||||||
|
icon: '⚙️',
|
||||||
|
description: 'Automated workflows and tasks',
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
site_builder: {
|
||||||
|
name: 'Site Builder',
|
||||||
|
route: '/site-builder',
|
||||||
|
icon: '🏗️',
|
||||||
|
description: 'Build and manage sites',
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
linker: {
|
||||||
|
name: 'Linker',
|
||||||
|
route: '/linker',
|
||||||
|
icon: '🔗',
|
||||||
|
description: 'Internal linking optimization',
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
optimizer: {
|
||||||
|
name: 'Optimizer',
|
||||||
|
route: '/optimizer',
|
||||||
|
icon: '⚡',
|
||||||
|
description: 'Content optimization',
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
publisher: {
|
||||||
|
name: 'Publisher',
|
||||||
|
route: '/publisher',
|
||||||
|
icon: '📤',
|
||||||
|
description: 'Content publishing',
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get module config by name
|
||||||
|
*/
|
||||||
|
export function getModuleConfig(moduleName: string): ModuleConfig | undefined {
|
||||||
|
return MODULES[moduleName];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all enabled modules
|
||||||
|
*/
|
||||||
|
export function getEnabledModules(moduleEnableSettings?: Record<string, boolean>): ModuleConfig[] {
|
||||||
|
return Object.entries(MODULES)
|
||||||
|
.filter(([key, module]) => {
|
||||||
|
// If moduleEnableSettings provided, use it; otherwise default to enabled
|
||||||
|
if (moduleEnableSettings) {
|
||||||
|
const enabledKey = `${key}_enabled` as keyof typeof moduleEnableSettings;
|
||||||
|
return moduleEnableSettings[enabledKey] !== false; // Default to true if not set
|
||||||
|
}
|
||||||
|
return module.enabled;
|
||||||
|
})
|
||||||
|
.map(([, module]) => module);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a module is enabled
|
||||||
|
*/
|
||||||
|
export function isModuleEnabled(moduleName: string, moduleEnableSettings?: Record<string, boolean>): boolean {
|
||||||
|
const module = MODULES[moduleName];
|
||||||
|
if (!module) return false;
|
||||||
|
|
||||||
|
if (moduleEnableSettings) {
|
||||||
|
const enabledKey = `${moduleName}_enabled` as keyof typeof moduleEnableSettings;
|
||||||
|
return moduleEnableSettings[enabledKey] !== false; // Default to true if not set
|
||||||
|
}
|
||||||
|
|
||||||
|
return module.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1474,6 +1474,20 @@ export async function deleteAccountSetting(key: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Module Settings
|
// Module Settings
|
||||||
|
export interface ModuleEnableSettings {
|
||||||
|
id: number;
|
||||||
|
planner_enabled: boolean;
|
||||||
|
writer_enabled: boolean;
|
||||||
|
thinker_enabled: boolean;
|
||||||
|
automation_enabled: boolean;
|
||||||
|
site_builder_enabled: boolean;
|
||||||
|
linker_enabled: boolean;
|
||||||
|
optimizer_enabled: boolean;
|
||||||
|
publisher_enabled: boolean;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ModuleSetting {
|
export interface ModuleSetting {
|
||||||
id: number;
|
id: number;
|
||||||
module_name: string;
|
module_name: string;
|
||||||
@@ -1498,6 +1512,19 @@ export async function createModuleSetting(data: { module_name: string; key: stri
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchModuleEnableSettings(): Promise<ModuleEnableSettings> {
|
||||||
|
const response = await fetchAPI('/v1/system/settings/modules/enable/');
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateModuleEnableSettings(data: Partial<ModuleEnableSettings>): Promise<ModuleEnableSettings> {
|
||||||
|
const response = await fetchAPI('/v1/system/settings/modules/enable/', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
export async function updateModuleSetting(moduleName: string, key: string, data: Partial<{ config: Record<string, any>; is_active: boolean }>): Promise<ModuleSetting> {
|
export async function updateModuleSetting(moduleName: string, key: string, data: Partial<{ config: Record<string, any>; is_active: boolean }>): Promise<ModuleSetting> {
|
||||||
return fetchAPI(`/v1/system/settings/modules/${key}/?module_name=${moduleName}`, {
|
return fetchAPI(`/v1/system/settings/modules/${key}/?module_name=${moduleName}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
|||||||
@@ -13,13 +13,17 @@ import {
|
|||||||
fetchModuleSettings,
|
fetchModuleSettings,
|
||||||
createModuleSetting,
|
createModuleSetting,
|
||||||
updateModuleSetting,
|
updateModuleSetting,
|
||||||
|
fetchModuleEnableSettings,
|
||||||
|
updateModuleEnableSettings,
|
||||||
AccountSetting,
|
AccountSetting,
|
||||||
ModuleSetting,
|
ModuleSetting,
|
||||||
|
ModuleEnableSettings,
|
||||||
} from '../services/api';
|
} from '../services/api';
|
||||||
|
|
||||||
interface SettingsState {
|
interface SettingsState {
|
||||||
accountSettings: Record<string, AccountSetting>;
|
accountSettings: Record<string, AccountSetting>;
|
||||||
moduleSettings: Record<string, Record<string, ModuleSetting>>;
|
moduleSettings: Record<string, Record<string, ModuleSetting>>;
|
||||||
|
moduleEnableSettings: ModuleEnableSettings | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
|
|
||||||
@@ -29,6 +33,9 @@ interface SettingsState {
|
|||||||
updateAccountSetting: (key: string, value: any) => Promise<void>;
|
updateAccountSetting: (key: string, value: any) => Promise<void>;
|
||||||
loadModuleSettings: (moduleName: string) => Promise<void>;
|
loadModuleSettings: (moduleName: string) => Promise<void>;
|
||||||
updateModuleSetting: (moduleName: string, key: string, value: any) => Promise<void>;
|
updateModuleSetting: (moduleName: string, key: string, value: any) => Promise<void>;
|
||||||
|
loadModuleEnableSettings: () => Promise<void>;
|
||||||
|
updateModuleEnableSettings: (data: Partial<ModuleEnableSettings>) => Promise<void>;
|
||||||
|
isModuleEnabled: (moduleName: string) => boolean;
|
||||||
reset: () => void;
|
reset: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +44,7 @@ export const useSettingsStore = create<SettingsState>()(
|
|||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
accountSettings: {},
|
accountSettings: {},
|
||||||
moduleSettings: {},
|
moduleSettings: {},
|
||||||
|
moduleEnableSettings: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
|
|
||||||
@@ -135,10 +143,40 @@ export const useSettingsStore = create<SettingsState>()(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
loadModuleEnableSettings: async () => {
|
||||||
|
set({ loading: true, error: null });
|
||||||
|
try {
|
||||||
|
const settings = await fetchModuleEnableSettings();
|
||||||
|
set({ moduleEnableSettings: settings, loading: false });
|
||||||
|
} catch (error: any) {
|
||||||
|
set({ error: error.message, loading: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateModuleEnableSettings: async (data: Partial<ModuleEnableSettings>) => {
|
||||||
|
set({ loading: true, error: null });
|
||||||
|
try {
|
||||||
|
const settings = await updateModuleEnableSettings(data);
|
||||||
|
set({ moduleEnableSettings: settings, loading: false });
|
||||||
|
} catch (error: any) {
|
||||||
|
set({ error: error.message, loading: false });
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
isModuleEnabled: (moduleName: string): boolean => {
|
||||||
|
const settings = get().moduleEnableSettings;
|
||||||
|
if (!settings) return true; // Default to enabled if not loaded
|
||||||
|
|
||||||
|
const enabledKey = `${moduleName}_enabled` as keyof ModuleEnableSettings;
|
||||||
|
return settings[enabledKey] !== false; // Default to true if not set
|
||||||
|
},
|
||||||
|
|
||||||
reset: () => {
|
reset: () => {
|
||||||
set({
|
set({
|
||||||
accountSettings: {},
|
accountSettings: {},
|
||||||
moduleSettings: {},
|
moduleSettings: {},
|
||||||
|
moduleEnableSettings: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
});
|
});
|
||||||
@@ -149,6 +187,7 @@ export const useSettingsStore = create<SettingsState>()(
|
|||||||
partialize: (state) => ({
|
partialize: (state) => ({
|
||||||
accountSettings: state.accountSettings,
|
accountSettings: state.accountSettings,
|
||||||
moduleSettings: state.moduleSettings,
|
moduleSettings: state.moduleSettings,
|
||||||
|
moduleEnableSettings: state.moduleEnableSettings,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user