Files
atomic-design-poc/src/app/registratie/domain/aanvraag-view.ts
Edwin van den Houdt 8078c499cb feat(fp): WP-09 — pure-logic closure: dates + missing command specs
Consolidate four hand-rolled nl-NL date formatters (tasks.ts, aanvraag-
block, letter-preview, aanvraag-view -- one more than the WP found) into
one shared/kernel/datum.ts::formatDatumNl, spec-pinned and empty-safe.
Add the two missing command specs CLAUDE.md's testing rule calls for:
draft-sync.spec.ts (debounce coalescing + trailing-call + submit Result
shape, via fake timers) and submit-change-request.spec.ts. Remove the
unused RemoteData.map3 (updating the three docs that mentioned it); the
variant input on confirmation.component.ts was already gone. Documents
both stale-WP-text corrections in the backlog file.

This closes out backlog Phase 1 (FP/DDD core, WP-05..09).
2026-07-03 22:02:50 +02:00

99 lines
3.8 KiB
TypeScript

import { formatDatumNl } from '@shared/kernel/datum';
import { Aanvraag, AanvraagStatus, AanvraagType } from './aanvraag';
/** View-model mapping for an aanvraag: type → labels, status → label, and the fields
for a CIBG "aanvragen" row / the case-detail page. Pure, no Angular — the UI
renders these, it does not derive them. */
export const TYPE_LABELS: Record<AanvraagType, string> = {
registratie: $localize`:@@aanvraagBlock.type.registratie:Inschrijving`,
herregistratie: $localize`:@@aanvraagBlock.type.herregistratie:Herregistratie`,
intake: $localize`:@@aanvraagBlock.type.intake:Herregistratie-intake`,
};
/** What the aanvraag is for (shown under the title). */
export function purposeLabel(type: AanvraagType): string {
switch (type) {
case 'registratie':
return $localize`:@@aanvraag.purpose.registratie:Inschrijving in het BIG-register`;
case 'herregistratie':
return $localize`:@@aanvraag.purpose.herregistratie:Verlenging van uw BIG-registratie`;
case 'intake':
return $localize`:@@aanvraag.purpose.intake:Intake-vragenlijst voor uw herregistratie`;
}
}
/** The status as a plain label (what state the aanvraag is in). */
export function statusLabel(status: AanvraagStatus): string {
switch (status.tag) {
case 'Concept':
return $localize`:@@aanvraag.status.concept:Concept (nog niet ingediend)`;
case 'InBehandeling':
return $localize`:@@aanvraag.status.inBehandeling:In behandeling`;
case 'Goedgekeurd':
return $localize`:@@aanvraag.status.goedgekeurd:Goedgekeurd`;
case 'Afgewezen':
return $localize`:@@aanvraag.status.afgewezen:Afgewezen`;
}
}
/** The reference number, or '' for a Concept (which has none yet). */
export function referentie(status: AanvraagStatus): string {
return status.tag === 'Concept' ? '' : status.referentie;
}
export interface AanvraagRow {
heading: string;
/** What the aanvraag is for (the `.subtitle` line). */
subtitle: string;
/** The status: label + reference + submit date (+ any note) — the `.status` line. */
status: string;
}
/** Fields for a submitted aanvraag's row in the dashboard "aanvragen" list (Concept
has no row — it renders as a resumable melding, see aanvraag-block). */
export function submittedRow(a: Aanvraag): AanvraagRow {
const s = a.status;
const parts = [statusLabel(s)];
const ref = referentie(s);
if (ref) parts.push($localize`:@@aanvraag.row.ref:Referentie ${ref}:ref:`);
if (a.submittedAt)
parts.push(
$localize`:@@aanvraag.row.ingediend:ingediend op ${formatDatumNl(a.submittedAt)}:datum:`,
);
if (s.tag === 'InBehandeling' && s.manual)
parts.push(
$localize`:@@aanvraagBlock.manual:Uw aanvraag wordt handmatig beoordeeld in de backoffice.`,
);
if (s.tag === 'Afgewezen') parts.push(s.reden);
return {
heading: TYPE_LABELS[a.type],
subtitle: purposeLabel(a.type),
status: parts.join(' · '),
};
}
/** Key/value rows for the case-detail page (CIBG Datablock). */
export function detailRows(a: Aanvraag): { key: string; value: string }[] {
const rows = [
{ key: $localize`:@@aanvraag.detail.soort:Soort aanvraag`, value: TYPE_LABELS[a.type] },
{ key: $localize`:@@aanvraag.detail.waarvoor:Waarvoor`, value: purposeLabel(a.type) },
{ key: $localize`:@@aanvraag.detail.status:Status`, value: statusLabel(a.status) },
{
key: $localize`:@@aanvraag.detail.referentie:Referentie`,
value: referentie(a.status) || '—',
},
{
key: $localize`:@@aanvraag.detail.ingediend:Ingediend op`,
value: a.submittedAt ? formatDatumNl(a.submittedAt) : '—',
},
];
if (a.status.tag === 'Afgewezen') {
rows.push({
key: $localize`:@@aanvraag.detail.reden:Reden van afwijzing`,
value: a.status.reden,
});
}
return rows;
}