Name the parent and year in vacation-expiry warnings

Several vacation_expiring warnings rendered with an identical title and a
body without the parent, so two warnings for the same year read as
duplicates. The backend already sends parent_personal_data_uuid; the
strings just never used it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 13:17:16 +02:00
parent 61e5487078
commit 74ddfcd440
4 changed files with 21 additions and 18 deletions
@@ -69,8 +69,8 @@ describe('PlanWarningCard', () => {
/>,
)
const warning = screen.getByTestId('dashboard-plan-warning-2')
expect(warning).toHaveTextContent('Semesterdagar riskerar att gå förlorade')
expect(warning).toHaveTextContent('4 semesterdagar riskerar att gå förlorade 2027')
expect(warning).toHaveTextContent('Semesterdagar riskerar att gå förlorade 2027')
expect(warning).toHaveTextContent('Sam riskerar att förlora 4 semesterdagar om inget görs')
})
it('falls back to the raw kind and messageKey for an unrecognised warning', () => {
@@ -54,21 +54,24 @@ export function PlanWarningCard({ warning, nameFor, index }: PlanWarningCardProp
const { t, locale } = useTranslation()
const titleKey = PLAN_WARNING_TITLE_KEYS[warning.kind]
const bodyKey = PLAN_WARNING_BODY_KEYS[warning.messageKey]
const title = titleKey ? t(titleKey) : warning.kind
// Construct params for title and body interpolation
const params = toTranslationParams(warning.data)
const uuid = warning.data.parent_personal_data_uuid
if (typeof uuid === 'string') {
params.parent_name = nameFor(uuid)
}
for (const field of DATE_FIELDS_BY_KIND[warning.kind] ?? []) {
const raw = warning.data[field]
if (typeof raw === 'string') {
params[field] = formatDateForDisplay(raw, locale)
}
}
const title = titleKey ? t(titleKey, params) : warning.kind
let body = warning.messageKey
if (bodyKey) {
const params = toTranslationParams(warning.data)
const uuid = warning.data.parent_personal_data_uuid
if (typeof uuid === 'string') {
params.parent_name = nameFor(uuid)
}
for (const field of DATE_FIELDS_BY_KIND[warning.kind] ?? []) {
const raw = warning.data[field]
if (typeof raw === 'string') {
params[field] = formatDateForDisplay(raw, locale)
}
}
body = t(bodyKey, params)
}