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:
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user