From a5a8f64a46db714420979c9e7e84b7f855181146 Mon Sep 17 00:00:00 2001 From: HauklandJ Date: Mon, 6 Jan 2025 10:08:00 +0100 Subject: [PATCH 1/7] add datamodelbinding for surname for personlookup --- src/layout/PersonLookup/PersonLookupComponent.tsx | 3 +++ src/layout/PersonLookup/config.ts | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/layout/PersonLookup/PersonLookupComponent.tsx b/src/layout/PersonLookup/PersonLookupComponent.tsx index 6ad55b02e5..1efa44d014 100644 --- a/src/layout/PersonLookup/PersonLookupComponent.tsx +++ b/src/layout/PersonLookup/PersonLookupComponent.tsx @@ -130,6 +130,8 @@ export function PersonLookupComponent({ node, overrideDisplay }: PropsFromGeneri return; } + setValue('person_lookup_surname', tempName); + const { data } = await performLookup(); if (data?.person) { setValue('person_lookup_name', data.person.name); @@ -140,6 +142,7 @@ export function PersonLookupComponent({ node, overrideDisplay }: PropsFromGeneri function handleClear() { setValue('person_lookup_name', ''); setValue('person_lookup_ssn', ''); + setValue('person_lookup_surname', ''); setTempName(''); setTempSsn(''); } diff --git a/src/layout/PersonLookup/config.ts b/src/layout/PersonLookup/config.ts index d1fee31ae8..b6ae643c4e 100644 --- a/src/layout/PersonLookup/config.ts +++ b/src/layout/PersonLookup/config.ts @@ -29,11 +29,19 @@ export const Config = new CG.component({ new CG.prop( 'person_lookup_name', new CG.dataModelBinding() - .setTitle('Data model binding for zip code') + .setTitle('Data model binding for the full name of a person') .setDescription( 'Describes the location in the data model where the component should store the name of the person to look up.', ), ), + new CG.prop( + 'person_lookup_surname', + new CG.dataModelBinding() + .setTitle('Data model binding for the surname of a person') + .setDescription( + 'Describes the location in the data model where the component should store the surname of the person to look up.', + ), + ), ).exportAs('IDataModelBindingsForPersonLookup'), ) .addTextResource( From 50d06a85473d37ae30984ee5c1b57e5b2f7de175 Mon Sep 17 00:00:00 2001 From: HauklandJ Date: Mon, 6 Jan 2025 14:51:20 +0100 Subject: [PATCH 2/7] rm surname datamodelbinding and compose fullname --- src/layout/PersonLookup/PersonLookupComponent.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/layout/PersonLookup/PersonLookupComponent.tsx b/src/layout/PersonLookup/PersonLookupComponent.tsx index 1efa44d014..51cfbaafea 100644 --- a/src/layout/PersonLookup/PersonLookupComponent.tsx +++ b/src/layout/PersonLookup/PersonLookupComponent.tsx @@ -37,7 +37,9 @@ const personLookupQueries = { }; export type Person = { - name: string; + firstName: string; + lastName: string; + middleName: string; ssn: string; }; export type PersonLookupResponse = { success: false; personDetails: null } | { success: true; personDetails: Person }; @@ -130,19 +132,20 @@ export function PersonLookupComponent({ node, overrideDisplay }: PropsFromGeneri return; } - setValue('person_lookup_surname', tempName); - const { data } = await performLookup(); if (data?.person) { - setValue('person_lookup_name', data.person.name); + setValue('person_lookup_name', getFullName(data.person)); setValue('person_lookup_ssn', data.person.ssn); } } + function getFullName({ firstName, middleName, lastName }) { + return middleName ? `${firstName} ${middleName} ${lastName}` : `${firstName} ${lastName}`; + } + function handleClear() { setValue('person_lookup_name', ''); setValue('person_lookup_ssn', ''); - setValue('person_lookup_surname', ''); setTempName(''); setTempSsn(''); } From 228bd7aa4c1bbbf9b3e9ff84d3a27621ce087ba4 Mon Sep 17 00:00:00 2001 From: HauklandJ Date: Mon, 6 Jan 2025 15:06:13 +0100 Subject: [PATCH 3/7] update validation of person lookup name --- src/layout/PersonLookup/validation.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/layout/PersonLookup/validation.ts b/src/layout/PersonLookup/validation.ts index bf10768999..ab087f336b 100644 --- a/src/layout/PersonLookup/validation.ts +++ b/src/layout/PersonLookup/validation.ts @@ -42,12 +42,12 @@ export function checkValidSsn(ssn: string): boolean { return k1 === calculated_k1 && k2 === calculated_k2; } -const nameSchema: JSONSchemaType> = { +const nameSchema: JSONSchemaType> = { type: 'object', properties: { - name: { type: 'string', minLength: 2, errorMessage: 'person_lookup.validation_error_name_too_short' }, + lastName: { type: 'string', minLength: 2, errorMessage: 'person_lookup.validation_error_name_too_short' }, }, - required: ['name'], + required: ['lastName'], }; export const validateSsn = ajv.compile(ssnSchema); From cfc844120078d0c35c431a997ea6a97b779c7fdc Mon Sep 17 00:00:00 2001 From: HauklandJ Date: Mon, 6 Jan 2025 15:10:22 +0100 Subject: [PATCH 4/7] rm surname from datamodelbindings --- src/layout/PersonLookup/config.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/layout/PersonLookup/config.ts b/src/layout/PersonLookup/config.ts index b6ae643c4e..7ecd92730f 100644 --- a/src/layout/PersonLookup/config.ts +++ b/src/layout/PersonLookup/config.ts @@ -34,14 +34,6 @@ export const Config = new CG.component({ 'Describes the location in the data model where the component should store the name of the person to look up.', ), ), - new CG.prop( - 'person_lookup_surname', - new CG.dataModelBinding() - .setTitle('Data model binding for the surname of a person') - .setDescription( - 'Describes the location in the data model where the component should store the surname of the person to look up.', - ), - ), ).exportAs('IDataModelBindingsForPersonLookup'), ) .addTextResource( From 5ee903774c6e04a2bb8e38fde8217d6667c82051 Mon Sep 17 00:00:00 2001 From: HauklandJ Date: Mon, 6 Jan 2025 15:14:11 +0100 Subject: [PATCH 5/7] validate first and last name --- src/layout/PersonLookup/validation.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/layout/PersonLookup/validation.ts b/src/layout/PersonLookup/validation.ts index ab087f336b..8811cc74d2 100644 --- a/src/layout/PersonLookup/validation.ts +++ b/src/layout/PersonLookup/validation.ts @@ -42,12 +42,13 @@ export function checkValidSsn(ssn: string): boolean { return k1 === calculated_k1 && k2 === calculated_k2; } -const nameSchema: JSONSchemaType> = { +const nameSchema: JSONSchemaType> = { type: 'object', properties: { lastName: { type: 'string', minLength: 2, errorMessage: 'person_lookup.validation_error_name_too_short' }, + firstName: { type: 'string', minLength: 2, errorMessage: 'person_lookup.validation_error_name_too_short' }, }, - required: ['lastName'], + required: ['lastName', 'firstName'], }; export const validateSsn = ajv.compile(ssnSchema); From 08eec3deda9406063b232a3a096364bf2a4a779f Mon Sep 17 00:00:00 2001 From: HauklandJ Date: Mon, 6 Jan 2025 15:32:54 +0100 Subject: [PATCH 6/7] validate tempName inline --- .../PersonLookup/PersonLookupComponent.tsx | 17 ++++++----------- src/layout/PersonLookup/validation.ts | 10 ---------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/layout/PersonLookup/PersonLookupComponent.tsx b/src/layout/PersonLookup/PersonLookupComponent.tsx index 51cfbaafea..c5648a496b 100644 --- a/src/layout/PersonLookup/PersonLookupComponent.tsx +++ b/src/layout/PersonLookup/PersonLookupComponent.tsx @@ -19,7 +19,7 @@ import { useBindingValidationsForNode } from 'src/features/validation/selectors/ import { hasValidationErrors } from 'src/features/validation/utils'; import { ComponentStructureWrapper } from 'src/layout/ComponentStructureWrapper'; import classes from 'src/layout/PersonLookup/PersonLookupComponent.module.css'; -import { validateName, validatePersonLookupResponse, validateSsn } from 'src/layout/PersonLookup/validation'; +import { validatePersonLookupResponse, validateSsn } from 'src/layout/PersonLookup/validation'; import { useLabel } from 'src/utils/layout/useLabel'; import { useNodeItem } from 'src/utils/layout/useNodeItem'; import { httpPost } from 'src/utils/network/networking'; @@ -85,7 +85,7 @@ export function PersonLookupComponent({ node, overrideDisplay }: PropsFromGeneri const [tempSsn, setTempSsn] = useState(''); const [tempName, setTempName] = useState(''); const [ssnErrors, setSsnErrors] = useState(); - const [nameErrors, setNameErrors] = useState(); + const [nameError, setNameError] = useState(); const bindingValidations = useBindingValidationsForNode(node); const { langAsString } = useLanguage(); @@ -97,16 +97,11 @@ export function PersonLookupComponent({ node, overrideDisplay }: PropsFromGeneri const { data, refetch: performLookup, isFetching } = useQuery(personLookupQueries.lookup(tempSsn, tempName)); function handleValidateName(name: string) { - if (!validateName({ name })) { - const nameErrors = validateName.errors - ?.filter((error) => error.instancePath === '/name') - .map((error) => error.message) - .filter((it) => it != null); - - setNameErrors(nameErrors); + if (name.length < 2) { + setNameError('person_lookup.validation_error_name_too_short'); return false; } - setNameErrors(undefined); + setNameError(undefined); return true; } @@ -225,7 +220,7 @@ export function PersonLookupComponent({ node, overrideDisplay }: PropsFromGeneri required={required} readOnly={hasSuccessfullyFetched} error={ - (nameErrors?.length && ) || + (nameError?.length && ) || (hasValidationErrors(bindingValidations?.person_lookup_name) && ( )) diff --git a/src/layout/PersonLookup/validation.ts b/src/layout/PersonLookup/validation.ts index 8811cc74d2..f845cb8921 100644 --- a/src/layout/PersonLookup/validation.ts +++ b/src/layout/PersonLookup/validation.ts @@ -42,17 +42,7 @@ export function checkValidSsn(ssn: string): boolean { return k1 === calculated_k1 && k2 === calculated_k2; } -const nameSchema: JSONSchemaType> = { - type: 'object', - properties: { - lastName: { type: 'string', minLength: 2, errorMessage: 'person_lookup.validation_error_name_too_short' }, - firstName: { type: 'string', minLength: 2, errorMessage: 'person_lookup.validation_error_name_too_short' }, - }, - required: ['lastName', 'firstName'], -}; - export const validateSsn = ajv.compile(ssnSchema); -export const validateName = ajv.compile(nameSchema); const personLookupResponseSchema: JSONSchemaType = { type: 'object', From 63efa40a3876bb7d642dfc2935bdef7b2eb3f467 Mon Sep 17 00:00:00 2001 From: Johannes Haukland <42615991+HauklandJ@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:46:15 +0100 Subject: [PATCH 7/7] Update src/layout/PersonLookup/PersonLookupComponent.tsx Co-authored-by: Camilla Marie Dalan --- src/layout/PersonLookup/PersonLookupComponent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layout/PersonLookup/PersonLookupComponent.tsx b/src/layout/PersonLookup/PersonLookupComponent.tsx index c5648a496b..9a9cca55f9 100644 --- a/src/layout/PersonLookup/PersonLookupComponent.tsx +++ b/src/layout/PersonLookup/PersonLookupComponent.tsx @@ -220,7 +220,7 @@ export function PersonLookupComponent({ node, overrideDisplay }: PropsFromGeneri required={required} readOnly={hasSuccessfullyFetched} error={ - (nameError?.length && ) || + (nameError && ) || (hasValidationErrors(bindingValidations?.person_lookup_name) && ( ))