style: format code with Prettier
Apply Prettier formatting to maintain consistent code style across the codebase. Changes include formatting improvements for: - IPC handlers (database, file, material-type, resolver, user-erp-config, validation) - Type definitions (ipc-api.types) - React components (MaterialTypeManagementDialog) - React hooks (useAuth, useCleaner, useValidation) - Pages (SettingsPage) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -154,13 +154,16 @@ export const MaterialTypeManagementDialog: React.FC<MaterialTypeManagementDialog
|
||||
}, [])
|
||||
|
||||
// Start editing a cell
|
||||
const startEdit = useCallback((rowIndex: number, field: string) => {
|
||||
const row = rows[rowIndex]
|
||||
if (row.state === 'deleted') return
|
||||
const startEdit = useCallback(
|
||||
(rowIndex: number, field: string) => {
|
||||
const row = rows[rowIndex]
|
||||
if (row.state === 'deleted') return
|
||||
|
||||
setEditingCell({ rowIndex, field })
|
||||
setEditValue(row.record[field as keyof MaterialTypeRecord] as string)
|
||||
}, [rows])
|
||||
setEditingCell({ rowIndex, field })
|
||||
setEditValue(row.record[field as keyof MaterialTypeRecord] as string)
|
||||
},
|
||||
[rows]
|
||||
)
|
||||
|
||||
// Save edit
|
||||
const saveEdit = useCallback(() => {
|
||||
@@ -252,7 +255,9 @@ export const MaterialTypeManagementDialog: React.FC<MaterialTypeManagementDialog
|
||||
toUpdate,
|
||||
toDelete
|
||||
})
|
||||
const payload = result.success ? (result.data as { stats?: { success?: number; failed?: number } } | undefined) : undefined
|
||||
const payload = result.success
|
||||
? (result.data as { stats?: { success?: number; failed?: number } } | undefined)
|
||||
: undefined
|
||||
|
||||
if (result.success) {
|
||||
alert(
|
||||
|
||||
@@ -56,7 +56,10 @@ export function useAuth(): UseAuthReturn {
|
||||
return true
|
||||
}, [])
|
||||
|
||||
const silentLogin = useCallback(async (): Promise<{ success: boolean; requiresUserSelection?: boolean }> => {
|
||||
const silentLogin = useCallback(async (): Promise<{
|
||||
success: boolean
|
||||
requiresUserSelection?: boolean
|
||||
}> => {
|
||||
setState((prev) => ({ ...prev, loading: true, error: null }))
|
||||
const result = await window.electron.auth.silentLogin()
|
||||
|
||||
|
||||
@@ -100,7 +100,9 @@ export function useCleaner() {
|
||||
// Load managers
|
||||
if (admin) {
|
||||
const resp = await window.electron.materials.getManagers()
|
||||
const managersPayload = resp.success ? (resp.data as { managers: string[] } | undefined) : undefined
|
||||
const managersPayload = resp.success
|
||||
? (resp.data as { managers: string[] } | undefined)
|
||||
: undefined
|
||||
const managerList = managersPayload?.managers ?? []
|
||||
setManagers(managerList)
|
||||
setSelectedManagers(new Set(managerList))
|
||||
@@ -108,7 +110,9 @@ export function useCleaner() {
|
||||
|
||||
// Get shared Production IDs
|
||||
const result = await window.electron.validation.getSharedProductionIds()
|
||||
const idsPayload = result.success ? (result.data as { productionIds?: string[] } | undefined) : undefined
|
||||
const idsPayload = result.success
|
||||
? (result.data as { productionIds?: string[] } | undefined)
|
||||
: undefined
|
||||
setSharedProductionIdsCount(idsPayload?.productionIds?.length ?? 0)
|
||||
} catch (err) {
|
||||
console.error('Initialization failed:', err)
|
||||
@@ -297,7 +301,9 @@ export function useCleaner() {
|
||||
|
||||
if (materialsToUpsert.length > 0) {
|
||||
const res = await window.electron.materials.upsertBatch(materialsToUpsert)
|
||||
const payload = res.success ? (res.data as { stats?: { success?: number } } | undefined) : undefined
|
||||
const payload = res.success
|
||||
? (res.data as { stats?: { success?: number } } | undefined)
|
||||
: undefined
|
||||
if (!res.success) throw new Error(res.error || '写入物料失败')
|
||||
msgParts.push(`写入/更新成功:${payload?.stats?.success || 0} 条`)
|
||||
}
|
||||
@@ -314,7 +320,9 @@ export function useCleaner() {
|
||||
// Reload managers if admin
|
||||
if (isAdmin) {
|
||||
const resp = await window.electron.materials.getManagers()
|
||||
const payload = resp.success ? (resp.data as { managers?: string[] } | undefined) : undefined
|
||||
const payload = resp.success
|
||||
? (resp.data as { managers?: string[] } | undefined)
|
||||
: undefined
|
||||
setManagers(payload?.managers ?? [])
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -52,28 +52,39 @@ export function useValidation(): UseValidationReturn {
|
||||
error: null
|
||||
})
|
||||
|
||||
const validate = useCallback(async (request: ValidationRequest): Promise<ValidationResponse | null> => {
|
||||
setState((prev) => ({ ...prev, loading: true, error: null }))
|
||||
const response = await window.electron.validation.validate(request)
|
||||
if (!response.success || !response.data) {
|
||||
setState((prev) => ({ ...prev, loading: false, error: response.error || 'Validation failed' }))
|
||||
return response.success ? null : { success: false, error: response.error }
|
||||
}
|
||||
const validate = useCallback(
|
||||
async (request: ValidationRequest): Promise<ValidationResponse | null> => {
|
||||
setState((prev) => ({ ...prev, loading: true, error: null }))
|
||||
const response = await window.electron.validation.validate(request)
|
||||
if (!response.success || !response.data) {
|
||||
setState((prev) => ({
|
||||
...prev,
|
||||
loading: false,
|
||||
error: response.error || 'Validation failed'
|
||||
}))
|
||||
return response.success ? null : { success: false, error: response.error }
|
||||
}
|
||||
|
||||
const result = response.data as ValidationResponse
|
||||
if (!result.success) {
|
||||
setState((prev) => ({ ...prev, loading: false, error: result.error || 'Validation failed' }))
|
||||
const result = response.data as ValidationResponse
|
||||
if (!result.success) {
|
||||
setState((prev) => ({
|
||||
...prev,
|
||||
loading: false,
|
||||
error: result.error || 'Validation failed'
|
||||
}))
|
||||
return result
|
||||
}
|
||||
|
||||
setState({
|
||||
loading: false,
|
||||
data: result.results || null,
|
||||
stats: result.stats || null,
|
||||
error: null
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
setState({
|
||||
loading: false,
|
||||
data: result.results || null,
|
||||
stats: result.stats || null,
|
||||
error: null
|
||||
})
|
||||
return result
|
||||
}, [])
|
||||
},
|
||||
[]
|
||||
)
|
||||
|
||||
const setSharedProductionIds = useCallback(async (ids: string[]): Promise<void> => {
|
||||
await window.electron.validation.setSharedProductionIds(ids)
|
||||
@@ -88,7 +99,10 @@ export function useValidation(): UseValidationReturn {
|
||||
return payload.productionIds || []
|
||||
}, [])
|
||||
|
||||
const getCleanerData = useCallback(async (): Promise<{ orderNumbers: string[]; materialCodes: string[] } | null> => {
|
||||
const getCleanerData = useCallback(async (): Promise<{
|
||||
orderNumbers: string[]
|
||||
materialCodes: string[]
|
||||
} | null> => {
|
||||
const result = await window.electron.validation.getCleanerData()
|
||||
if (!result.success || !result.data) {
|
||||
return null
|
||||
|
||||
@@ -27,7 +27,9 @@ const SettingsPage: React.FC = () => {
|
||||
setIsLoading(true)
|
||||
// ERP credentials are loaded from database (current user's config)
|
||||
const response = await window.electron.settings.getSettings()
|
||||
const config = response.success ? (response.data as { erp?: ErpCredentials } | undefined) : undefined
|
||||
const config = response.success
|
||||
? (response.data as { erp?: ErpCredentials } | undefined)
|
||||
: undefined
|
||||
|
||||
// Extract ERP credentials from the config
|
||||
if (config?.erp) {
|
||||
@@ -60,7 +62,9 @@ const SettingsPage: React.FC = () => {
|
||||
password: credentials.password
|
||||
}
|
||||
})
|
||||
const saveData = result.success ? (result.data as { success?: boolean; error?: string } | undefined) : undefined
|
||||
const saveData = result.success
|
||||
? (result.data as { success?: boolean; error?: string } | undefined)
|
||||
: undefined
|
||||
|
||||
if (result.success && saveData?.success !== false) {
|
||||
setIsModified(false)
|
||||
|
||||
Reference in New Issue
Block a user