import { Component, inject, signal } from '@angular/core'; import { BffApiV1Service, type SubmitAccepted } from 'api-client'; import { AuthService } from 'auth'; import { UtrechtComponentsModule } from 'ui'; /** * The self-service submit page: a signed-in zorgprofessional confirms and submits their BIG * registration. The bsn comes from the DigiD token (not a form field), so this is a confirm-and- * submit flow that posts to the BFF and shows the returned reference (ADR-0010; S-08c). After * submitting they can withdraw it — "trek aanvraag in" — keyed by that reference (S-11c). */ @Component({ selector: 'app-registration-page', imports: [UtrechtComponentsModule], templateUrl: './registration-page.html', }) export class RegistrationPage { private readonly auth = inject(AuthService); private readonly bff = inject(BffApiV1Service); protected readonly bsn = this.auth.bsn; protected readonly submitting = signal(false); protected readonly reference = signal(undefined); protected readonly submitted = signal(false); protected readonly failed = signal(false); protected readonly withdrawing = signal(false); protected readonly withdrawn = signal(false); protected readonly withdrawFailed = signal(false); submit(): void { this.submitting.set(true); this.failed.set(false); this.bff.postSelfServiceRegistrations().subscribe({ next: (accepted: SubmitAccepted) => { this.reference.set(accepted.registrationId); this.submitted.set(true); this.submitting.set(false); }, // Surface the failure instead of swallowing it: re-enable the button so the user can retry. error: () => { this.failed.set(true); this.submitting.set(false); }, }); } withdraw(): void { const reference = this.reference(); if (!reference) { return; } this.withdrawing.set(true); this.withdrawFailed.set(false); this.bff.postSelfServiceRegistrationsIdWithdraw(reference).subscribe({ next: () => { this.withdrawn.set(true); this.withdrawing.set(false); }, // Surface the failure instead of swallowing it: keep the action so the user can retry. error: () => { this.withdrawFailed.set(true); this.withdrawing.set(false); }, }); } }