Refactor dashboard widget management: Update dashboardService to handle user-specific widget configurations with create and update logic. Enhance LoggedInView to support adding the same widget type and display error messages for save operations. Ensure effective endpoint handling for widgets and improve UI interactions.

This commit is contained in:
Torsten Schulz (local)
2026-01-30 07:31:38 +01:00
parent 39ac149430
commit 4779a6e4af
4 changed files with 114 additions and 48 deletions

View File

@@ -45,10 +45,13 @@ class DashboardService extends BaseService {
title: String(w?.title ?? ''),
endpoint: String(w?.endpoint ?? '')
})).filter(w => w.id && (w.title || w.endpoint));
await UserDashboard.upsert({
userId: user.id,
config: { widgets: sanitized }
}, { conflictFields: ['userId'] });
const payload = { widgets: sanitized };
const existing = await UserDashboard.findOne({ where: { userId: user.id } });
if (existing) {
await existing.update({ config: payload });
} else {
await UserDashboard.create({ userId: user.id, config: payload });
}
return { widgets: sanitized };
}
}