feat(achievements): dedicated /achievements page with locked/unlocked list

Pre-v1.4.15 the page silently dropped locked achievements, so the user
only saw what they had already earned. Now every badge renders — locked
ones are grayed out with a "Locked" badge, criterion hint
({current} / {target}), and a progress bar. Unlocked entries keep the
existing primary-gradient card with the "Completed on …" footer.

Achievements are grouped by a new `category` axis (medication, vitals,
security, engagement) — derived in `getAchievementCategory()` so a
metric is always in exactly one bucket. Inside a category, unlocked
items sort first; among locked items the closest-to-unlock one ranks
first so the user always sees their immediate next goal at the top.

The sidebar link to /achievements was already in place under the
user-area group; this commit only adds the new locked/grouped render
plus an e2e smoke spec that walks the desktop sidebar → click →
heading visible path.

i18n: 9 new keys under `achievements.*` (locked, criterionHint,
progressPercent, categories.{medication,vitals,security,engagement},
dashboardCard.{title,viewAll,empty}) — EN + DE. C4's parity audit will
sweep later.

Tests: +9 unit (groupByCategory ordering + page render in EN/DE) +
1 e2e (sidebar → /achievements). 909 / 909 unit pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc-André BombeckandClaude Opus 4.7 committed 2026-05-09 21:17:04 +02:00
1 parent db5a49d593
commit 34c967c14a
9 files changed
+773 -55

No files matched your search

+56
View File
@@ -17,6 +17,19 @@ export type AchievementMetricKey =
| "loginDayStreak"
| "bugReportCount";
/**
* Achievement categories — used by the /achievements UI to visually group
* the badges. Pure presentation: the computation logic in this file does
* not branch on category, and the metric → category mapping is derived in
* `getAchievementCategory` below so a metric is always in exactly one
* group.
*/
export type AchievementCategory =
| "medication"
| "vitals"
| "security"
| "engagement";
export interface AchievementDefinition {
id: string;
metric: AchievementMetricKey;
@@ -28,6 +41,47 @@ export interface AchievementDefinition {
format: "count" | "days" | "percent";
}
/**
* Stable metric → category mapping. Add a metric here when it joins the
* `AchievementMetricKey` union; the page falls back to "engagement" if
* a future definition slips through, so there is no silent drop-off.
*/
export function getAchievementCategory(
metric: AchievementMetricKey,
): AchievementCategory {
switch (metric) {
case "totalTakenIntakes":
case "overIntakeCount":
case "skippedIntakeCount":
case "onTimePerfectDayStreak":
case "compliance80DayStreak":
return "medication";
case "bmiGreenStreak":
case "bpGreenStreak":
case "pulseGreenStreak":
return "vitals";
case "passkeyCreatedCount":
case "passkeyLoginCount":
case "passwordLoginCount":
return "security";
case "loginDayStreak":
case "bugReportCount":
return "engagement";
}
}
/**
* Stable category render order on the /achievements page. Medication is
* the densest category (16 / 38 today) so it goes first; engagement is
* the smallest, last.
*/
export const ACHIEVEMENT_CATEGORY_ORDER: readonly AchievementCategory[] = [
"medication",
"vitals",
"security",
"engagement",
] as const;
export interface AchievementMetrics {
totalTakenIntakes: number;
overIntakeCount: number;
@@ -47,6 +101,7 @@ export interface AchievementMetrics {
export interface AchievementProgress {
id: string;
metric: AchievementMetricKey;
category: AchievementCategory;
titleKey: string;
descriptionKey: string;
icon: string;
@@ -335,6 +390,7 @@ export function evaluateAchievementsWithCompletionDates(
return {
id: definition.id,
metric: definition.metric,
category: getAchievementCategory(definition.metric),
titleKey: definition.tTitle,
descriptionKey: definition.tDescription,
icon: definition.icon,