fix: Better error handling for goal types loading
- Check if goal_type_definitions table exists - Detailed error messages - Fallback if goalTypes is empty - Prevent form opening without types Helps debugging Migration 024 issues. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
043bed4323
commit
bbee44ecdc
2 files changed
+63
-29
No files matched your search
@@ -84,21 +84,23 @@ export default function GoalsPage() {
|
||||
|
||||
// Convert types array to map for quick lookup
|
||||
const typesMap = {}
|
||||
typesData.forEach(type => {
|
||||
typesMap[type.type_key] = {
|
||||
label: type.label_de,
|
||||
unit: type.unit,
|
||||
icon: type.icon || '📊',
|
||||
category: type.category,
|
||||
is_system: type.is_system
|
||||
}
|
||||
})
|
||||
if (typesData && Array.isArray(typesData)) {
|
||||
typesData.forEach(type => {
|
||||
typesMap[type.type_key] = {
|
||||
label: type.label_de,
|
||||
unit: type.unit,
|
||||
icon: type.icon || '📊',
|
||||
category: type.category,
|
||||
is_system: type.is_system
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
setGoalTypes(typesData)
|
||||
setGoalTypes(typesData || [])
|
||||
setGoalTypesMap(typesMap)
|
||||
} catch (err) {
|
||||
console.error('Failed to load goals:', err)
|
||||
setError('Fehler beim Laden der Ziele')
|
||||
setError(`Fehler beim Laden: ${err.message || err.toString()}`)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
@@ -121,8 +123,12 @@ export default function GoalsPage() {
|
||||
}
|
||||
|
||||
const handleCreateGoal = () => {
|
||||
if (goalTypes.length === 0) {
|
||||
setError('Keine Goal Types verfügbar. Bitte Admin kontaktieren.')
|
||||
return
|
||||
}
|
||||
setEditingGoal(null)
|
||||
const firstType = goalTypes.length > 0 ? goalTypes[0].type_key : 'weight'
|
||||
const firstType = goalTypes[0].type_key
|
||||
setFormData({
|
||||
goal_type: firstType,
|
||||
is_primary: goals.length === 0, // First goal is primary by default
|
||||
|
||||
Reference in new issue
Block a user