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:
@@ -13,13 +13,17 @@ import {
|
||||
fetchModuleSettings,
|
||||
createModuleSetting,
|
||||
updateModuleSetting,
|
||||
fetchModuleEnableSettings,
|
||||
updateModuleEnableSettings,
|
||||
AccountSetting,
|
||||
ModuleSetting,
|
||||
ModuleEnableSettings,
|
||||
} from '../services/api';
|
||||
|
||||
interface SettingsState {
|
||||
accountSettings: Record<string, AccountSetting>;
|
||||
moduleSettings: Record<string, Record<string, ModuleSetting>>;
|
||||
moduleEnableSettings: ModuleEnableSettings | null;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
|
||||
@@ -29,6 +33,9 @@ interface SettingsState {
|
||||
updateAccountSetting: (key: string, value: any) => Promise<void>;
|
||||
loadModuleSettings: (moduleName: string) => 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;
|
||||
}
|
||||
|
||||
@@ -37,6 +44,7 @@ export const useSettingsStore = create<SettingsState>()(
|
||||
(set, get) => ({
|
||||
accountSettings: {},
|
||||
moduleSettings: {},
|
||||
moduleEnableSettings: null,
|
||||
loading: false,
|
||||
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: () => {
|
||||
set({
|
||||
accountSettings: {},
|
||||
moduleSettings: {},
|
||||
moduleEnableSettings: null,
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
@@ -149,6 +187,7 @@ export const useSettingsStore = create<SettingsState>()(
|
||||
partialize: (state) => ({
|
||||
accountSettings: state.accountSettings,
|
||||
moduleSettings: state.moduleSettings,
|
||||
moduleEnableSettings: state.moduleEnableSettings,
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user