Step 2 (code quality): dedup + stop FE recomputing a server rule
- H1: tasksFromProfile takes the server's eligibleForHerregistratie decision
instead of recomputing isHerregistratieEligible — the FE renders the rule,
doesn't own it (ADR-0001). Policy reference impl kept for tests.
- M1: one shared runSubmit(fn, fallback) wrapper; the 4 submit-* commands keep
only their payload mapping. +spec.
- M2: whenTag() kernel helper removes 10 repeated `as Extract<U,{tag}>` casts
across the wizard/form components.
M4 (shared JA_NEE) folded into the upcoming i18n pass (clean dedup needs
$localize labels to sit in shared without breaking the English-shared-UI rule).
L1 already resolved by the restyle commit.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,22 +1,20 @@
|
||||
import { Result, ok, err } from '@shared/kernel/fp';
|
||||
import { Result } from '@shared/kernel/fp';
|
||||
import { Valid } from '@registratie/domain/change-request.machine';
|
||||
import { ApiClient } from '@shared/infrastructure/api-client';
|
||||
import { problemDetail } from '@shared/infrastructure/api-error';
|
||||
import { runSubmit, SUBMIT_FAILED } from '@shared/application/submit';
|
||||
|
||||
/**
|
||||
* Command: POST an address change to the backend (`/api/v1/change-requests`),
|
||||
* which re-validates and returns a reference. Same shape as the other submit
|
||||
* commands — a `Result`, never a thrown error — so the form's reduce can branch.
|
||||
*/
|
||||
export async function submitChangeRequest(client: ApiClient, data: Valid): Promise<Result<string, string>> {
|
||||
try {
|
||||
export function submitChangeRequest(client: ApiClient, data: Valid): Promise<Result<string, string>> {
|
||||
return runSubmit(async () => {
|
||||
const res = await client.changeRequests({
|
||||
straat: data.straat,
|
||||
postcode: data.postcode,
|
||||
woonplaats: data.woonplaats,
|
||||
});
|
||||
return ok(res.referentie ?? '');
|
||||
} catch (e) {
|
||||
return err(problemDetail(e, 'Het indienen is niet gelukt. Probeer het later opnieuw.'));
|
||||
}
|
||||
return res.referentie ?? '';
|
||||
}, SUBMIT_FAILED);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user