import { Component, inject, signal } from '@angular/core'; import { BffApiV1Service, type WerkbakItem } from 'api-client'; import { UtrechtComponentsModule } from 'ui'; /** The two decisions a behandelaar can make; the BFF validates these exact values (ADR-0013). */ type Besluit = 'goedkeuren' | 'afwijzen'; /** * The behandel werkbak: a signed-in behandelaar sees the registrations awaiting beoordeling (the open * Flowable `Beoordelen` tasks, read through the domain) and decides each — goedkeuren or afwijzen. A * decision posts to the BFF, which applies the domain transition and completes the workflow task * (ADR-0013; S-12). After a decision the werkbak refreshes so the handled item drops off the list. */ @Component({ selector: 'app-werkbak-page', imports: [UtrechtComponentsModule], templateUrl: './werkbak-page.html', }) export class WerkbakPage { private readonly bff = inject(BffApiV1Service); protected readonly items = signal([]); protected readonly loading = signal(false); protected readonly loaded = signal(false); protected readonly failed = signal(false); protected readonly deciding = signal(undefined); constructor() { this.load(); } load(): void { this.loading.set(true); this.failed.set(false); this.bff.getBehandelWerkbak().subscribe({ next: (rows: WerkbakItem[]) => { this.items.set(rows); this.loading.set(false); this.loaded.set(true); }, // Surface the failure (e.g. 403 for a non-behandelaar) instead of swallowing it. error: () => { this.items.set([]); this.loading.set(false); this.loaded.set(true); this.failed.set(true); }, }); } decide(registrationId: string, besluit: Besluit): void { this.deciding.set(registrationId); this.bff.postBehandelRegistrationsIdDecide(registrationId, { besluit }).subscribe({ // Refresh so the decided registration drops off the werkbak (its task is now completed). next: () => { this.deciding.set(undefined); this.load(); }, error: () => { this.deciding.set(undefined); this.failed.set(true); }, }); } }