feat: implement settings interface with user permission control
New Features: - Add SettingsPage component with Admin/User view differentiation - Create ConfigManager service for .env file management - Add IPC handlers for settings CRUD operations - Implement connection testing for ERP and database - Add settings navigation to main app Files Created: - src/main/types/settings.types.ts - Type definitions - src/main/services/config/config-manager.ts - Config service - src/main/ipc/settings-handler.ts - IPC handlers - src/renderer/src/pages/SettingsPage.tsx - React UI component Files Modified: - src/main/ipc/index.ts - Register settings handlers - src/preload/index.ts - Expose settings API - src/preload/index.d.ts - Add SettingsAPI type - src/renderer/src/App.tsx - Add settings navigation Co-Authored-By: Claude (qwen3.5-plus) <noreply@anthropic.com>
This commit is contained in:
43
src/preload/index.d.ts
vendored
43
src/preload/index.d.ts
vendored
@@ -9,6 +9,7 @@ import type {
|
||||
CurrentUserResponse
|
||||
} from '../main/ipc/auth-handler'
|
||||
import type { ValidationRequest, ValidationResponse } from '../main/types/validation.types'
|
||||
import type { SettingsData, UserType, ConnectionTestResult, SaveSettingsResult } from '../main/types/settings.types'
|
||||
|
||||
/**
|
||||
* Order number resolver API
|
||||
@@ -88,6 +89,16 @@ export interface ValidationAPI {
|
||||
* Get shared Production IDs
|
||||
*/
|
||||
getSharedProductionIds: () => Promise<{ productionIds: string[] }>
|
||||
/**
|
||||
* Get cleaner data (order numbers from shared Production IDs + material codes from MaterialsToBeDeleted)
|
||||
* Filters materials by current user (admin sees all, regular users see only their own)
|
||||
*/
|
||||
getCleanerData: () => Promise<{
|
||||
success: boolean
|
||||
orderNumbers?: string[]
|
||||
materialCodes?: string[]
|
||||
error?: string
|
||||
}>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,6 +142,37 @@ export interface MaterialsAPI {
|
||||
getStatistics: () => Promise<{ stats: unknown }>
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings API
|
||||
*/
|
||||
export interface SettingsAPI {
|
||||
/**
|
||||
* Get current user type
|
||||
*/
|
||||
getUserType: () => Promise<UserType>
|
||||
/**
|
||||
* Get settings (filtered by user type)
|
||||
*/
|
||||
getSettings: () => Promise<SettingsData>
|
||||
/**
|
||||
* Save settings
|
||||
* @param settings - Settings data to save
|
||||
*/
|
||||
saveSettings: (settings: SettingsData) => Promise<SaveSettingsResult>
|
||||
/**
|
||||
* Reset to defaults (Admin only)
|
||||
*/
|
||||
resetDefaults: () => Promise<SaveSettingsResult>
|
||||
/**
|
||||
* Test ERP connection
|
||||
*/
|
||||
testErpConnection: () => Promise<ConnectionTestResult>
|
||||
/**
|
||||
* Test database connection
|
||||
*/
|
||||
testDbConnection: () => Promise<ConnectionTestResult>
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
electron: {
|
||||
@@ -157,6 +199,7 @@ declare global {
|
||||
auth: AuthAPI
|
||||
validation: ValidationAPI
|
||||
materials: MaterialsAPI
|
||||
settings: SettingsAPI
|
||||
}
|
||||
api: unknown
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { ResolverInput } from '../main/ipc/resolver-handler'
|
||||
import type { LoginRequest } from '../main/ipc/auth-handler'
|
||||
import type { UserInfo } from '../main/types/user.types'
|
||||
import type { ValidationRequest } from '../main/types/validation.types'
|
||||
import type { SettingsData } from '../main/types/settings.types'
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {
|
||||
@@ -70,7 +71,9 @@ const api = {
|
||||
setSharedProductionIds: (productionIds: string[]) =>
|
||||
ipcRenderer.invoke('validation:setSharedProductionIds', productionIds),
|
||||
getSharedProductionIds: () =>
|
||||
ipcRenderer.invoke('validation:getSharedProductionIds')
|
||||
ipcRenderer.invoke('validation:getSharedProductionIds'),
|
||||
getCleanerData: () =>
|
||||
ipcRenderer.invoke('validation:getCleanerData')
|
||||
},
|
||||
|
||||
// Materials service
|
||||
@@ -84,6 +87,16 @@ const api = {
|
||||
ipcRenderer.invoke('materials:getByManager', managerName),
|
||||
getAll: () => ipcRenderer.invoke('materials:getAll'),
|
||||
getStatistics: () => ipcRenderer.invoke('materials:getStatistics')
|
||||
},
|
||||
|
||||
// Settings service
|
||||
settings: {
|
||||
getUserType: () => ipcRenderer.invoke('settings:getUserType'),
|
||||
getSettings: () => ipcRenderer.invoke('settings:getSettings'),
|
||||
saveSettings: (settings: SettingsData) => ipcRenderer.invoke('settings:saveSettings', settings),
|
||||
resetDefaults: () => ipcRenderer.invoke('settings:resetDefaults'),
|
||||
testErpConnection: () => ipcRenderer.invoke('settings:testErpConnection'),
|
||||
testDbConnection: () => ipcRenderer.invoke('settings:testDbConnection')
|
||||
}
|
||||
} as const
|
||||
|
||||
|
||||
Reference in New Issue
Block a user