2026-01-11 13:11:55 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-01-12 15:42:18 +01:00
|
|
|
using PlanTempus.Application.Features.Localization.Services;
|
2026-01-11 13:11:55 +01:00
|
|
|
|
|
|
|
|
namespace PlanTempus.Application.Features.Dashboard.Components;
|
|
|
|
|
|
|
|
|
|
public class NotificationListViewComponent : ViewComponent
|
|
|
|
|
{
|
2026-01-12 15:42:18 +01:00
|
|
|
private readonly ILocalizationService _localization;
|
|
|
|
|
|
|
|
|
|
public NotificationListViewComponent(ILocalizationService localization)
|
|
|
|
|
{
|
|
|
|
|
_localization = localization;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 13:11:55 +01:00
|
|
|
public IViewComponentResult Invoke(string key)
|
|
|
|
|
{
|
2026-01-12 15:42:18 +01:00
|
|
|
var model = NotificationListCatalog.Get(key, _localization);
|
2026-01-11 13:11:55 +01:00
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class NotificationListViewModel
|
|
|
|
|
{
|
|
|
|
|
public required string Key { get; init; }
|
|
|
|
|
public required string Title { get; init; }
|
|
|
|
|
public required string ActionText { get; init; }
|
|
|
|
|
public required IReadOnlyList<string> NotificationKeys { get; init; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 15:42:18 +01:00
|
|
|
internal class NotificationListData
|
|
|
|
|
{
|
|
|
|
|
public required string Key { get; init; }
|
|
|
|
|
public required string TitleKey { get; init; }
|
|
|
|
|
public required string ActionTextKey { get; init; }
|
|
|
|
|
public required IReadOnlyList<string> NotificationKeys { get; init; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 13:11:55 +01:00
|
|
|
public static class NotificationListCatalog
|
|
|
|
|
{
|
2026-01-12 15:42:18 +01:00
|
|
|
private static readonly Dictionary<string, NotificationListData> Lists = new()
|
2026-01-11 13:11:55 +01:00
|
|
|
{
|
2026-01-12 15:42:18 +01:00
|
|
|
["recent-notifications"] = new NotificationListData
|
2026-01-11 13:11:55 +01:00
|
|
|
{
|
|
|
|
|
Key = "recent-notifications",
|
2026-01-12 15:42:18 +01:00
|
|
|
TitleKey = "dashboard.notifications.title",
|
|
|
|
|
ActionTextKey = "dashboard.notifications.markAllRead",
|
2026-01-11 13:11:55 +01:00
|
|
|
NotificationKeys = ["notif-1", "notif-2", "notif-3", "notif-4"]
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-12 15:42:18 +01:00
|
|
|
public static NotificationListViewModel Get(string key, ILocalizationService localization)
|
2026-01-11 13:11:55 +01:00
|
|
|
{
|
2026-01-12 15:42:18 +01:00
|
|
|
if (!Lists.TryGetValue(key, out var list))
|
|
|
|
|
throw new KeyNotFoundException($"NotificationList with key '{key}' not found");
|
2026-01-11 13:11:55 +01:00
|
|
|
|
2026-01-12 15:42:18 +01:00
|
|
|
return new NotificationListViewModel
|
|
|
|
|
{
|
|
|
|
|
Key = list.Key,
|
|
|
|
|
Title = localization.Get(list.TitleKey),
|
|
|
|
|
ActionText = localization.Get(list.ActionTextKey),
|
|
|
|
|
NotificationKeys = list.NotificationKeys
|
|
|
|
|
};
|
2026-01-11 13:11:55 +01:00
|
|
|
}
|
|
|
|
|
}
|