PlanTempusApp/PlanTempus.Application/Features/Dashboard/Components/StatCardViewComponent.cs
Janus C. H. Knudsen 9b2ace7bc0 Adds dashboard stat cards and demo banner
Introduces StatCard ViewComponent with configurable stat display
Adds demo mode banner to application layout
Refactors dashboard stats to use dynamic component rendering

Improves dashboard presentation and user experience
2026-01-11 11:17:51 +01:00

90 lines
2.6 KiB
C#

using Microsoft.AspNetCore.Mvc;
namespace PlanTempus.Application.Features.Dashboard.Components;
/// <summary>
/// ViewComponent for rendering a stat card on the dashboard.
/// </summary>
public class StatCardViewComponent : ViewComponent
{
public IViewComponentResult Invoke(string key)
{
var model = StatCardCatalog.Get(key);
return View(model);
}
}
/// <summary>
/// ViewModel for the StatCard component.
/// </summary>
public class StatCardViewModel
{
public required string Key { get; init; }
public required string Value { get; init; }
public required string Label { get; init; }
public string? TrendText { get; init; }
public string? TrendIcon { get; init; }
public string? TrendDirection { get; init; }
public string? Variant { get; init; }
public bool HasTrend => !string.IsNullOrEmpty(TrendText);
}
/// <summary>
/// Catalog of available stat cards with their data.
/// </summary>
public static class StatCardCatalog
{
private static readonly Dictionary<string, StatCardViewModel> Cards = new()
{
["bookings-today"] = new StatCardViewModel
{
Key = "bookings-today",
Value = "12",
Label = "Bookinger i dag",
TrendText = "4 gennemført, 2 i gang",
TrendIcon = "ph-check-circle",
TrendDirection = "up",
Variant = "highlight"
},
["expected-revenue"] = new StatCardViewModel
{
Key = "expected-revenue",
Value = "8.450 kr",
Label = "Forventet omsætning",
TrendText = "+12% vs. gennemsnit",
TrendIcon = "ph-trend-up",
TrendDirection = "up",
Variant = "success"
},
["occupancy-rate"] = new StatCardViewModel
{
Key = "occupancy-rate",
Value = "78%",
Label = "Belægningsgrad",
TrendText = "God kapacitet",
TrendIcon = "ph-trend-up",
TrendDirection = "up",
Variant = null
},
["needs-attention"] = new StatCardViewModel
{
Key = "needs-attention",
Value = "4",
Label = "Kræver opmærksomhed",
TrendText = null,
TrendIcon = null,
TrendDirection = null,
Variant = "warning"
}
};
public static StatCardViewModel Get(string key)
{
if (Cards.TryGetValue(key, out var card))
return card;
throw new KeyNotFoundException($"StatCard with key '{key}' not found");
}
public static IEnumerable<string> AllKeys => Cards.Keys;
}