diff --git a/backend/akr/src/main/java/fi/oph/akr/api/dto/clerk/PersonDTO.java b/backend/akr/src/main/java/fi/oph/akr/api/dto/clerk/PersonDTO.java index f997b07f2..aa2fbc74f 100644 --- a/backend/akr/src/main/java/fi/oph/akr/api/dto/clerk/PersonDTO.java +++ b/backend/akr/src/main/java/fi/oph/akr/api/dto/clerk/PersonDTO.java @@ -1,5 +1,6 @@ package fi.oph.akr.api.dto.clerk; +import java.util.List; import lombok.Builder; import lombok.NonNull; @@ -12,8 +13,5 @@ public record PersonDTO( @NonNull String lastName, @NonNull String firstName, @NonNull String nickName, - String street, - String postalCode, - String town, - String country + @NonNull List address ) {} diff --git a/backend/akr/src/main/java/fi/oph/akr/onr/mock/PersonalDataFactory.java b/backend/akr/src/main/java/fi/oph/akr/onr/mock/PersonalDataFactory.java index b94f3076a..dfded5eba 100644 --- a/backend/akr/src/main/java/fi/oph/akr/onr/mock/PersonalDataFactory.java +++ b/backend/akr/src/main/java/fi/oph/akr/onr/mock/PersonalDataFactory.java @@ -262,20 +262,11 @@ private static Iterator cyclicIterator(final String... values) { private final Iterator countries = cyclicIterator("Suomi", "suomi", "SUOMI", "Finland", "", null); - private final Iterator streetsVTJ = cyclicIterator( - "Downing Street 1", - null - ); + private final Iterator streetsVTJ = cyclicIterator("Downing Street 1", null); - private final Iterator postalCodesVTJ = cyclicIterator( - "00100", - null - ); + private final Iterator postalCodesVTJ = cyclicIterator("00100", null); - private final Iterator townsVTJ = cyclicIterator( - "London", - null - ); + private final Iterator townsVTJ = cyclicIterator("London", null); private final Iterator countriesVTJ = cyclicIterator("UK", "DEU", "", null); } diff --git a/backend/akr/src/main/java/fi/oph/akr/service/ClerkTranslatorService.java b/backend/akr/src/main/java/fi/oph/akr/service/ClerkTranslatorService.java index 971f10114..c59af29ba 100644 --- a/backend/akr/src/main/java/fi/oph/akr/service/ClerkTranslatorService.java +++ b/backend/akr/src/main/java/fi/oph/akr/service/ClerkTranslatorService.java @@ -43,6 +43,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -336,6 +337,7 @@ private PersonalData createPersonalData(final String onrId, final TranslatorDTOC .town(addr.town()) .country(addr.country()) .street(addr.street()) + .postalCode(addr.postalCode()) .source(addr.source()) .type(addr.type()) .build() @@ -348,6 +350,19 @@ private PersonalData createPersonalData(final String onrId, final TranslatorDTOC private void copyDtoFieldsToTranslator(final TranslatorDTOCommonFields dto, final Translator translator) { translator.setExtraInformation(dto.extraInformation()); translator.setAssuranceGiven(dto.isAssuranceGiven()); + + final Optional selectedAddress = dto + .address() + .stream() + .filter(ClerkTranslatorAddressDTO::selected) + .findFirst(); + + selectedAddress.ifPresent(clerkTranslatorAddressDTO -> + translator.setSelectedSource(clerkTranslatorAddressDTO.source().toString()) + ); + selectedAddress.ifPresent(clerkTranslatorAddressDTO -> + translator.setSelectedType(clerkTranslatorAddressDTO.type().toString()) + ); } @CacheEvict(cacheNames = CacheConfig.CACHE_NAME_PUBLIC_TRANSLATORS, allEntries = true) diff --git a/frontend/packages/akr/src/components/clerkTranslator/new/NewTranslatorBasicInformation.tsx b/frontend/packages/akr/src/components/clerkTranslator/new/NewTranslatorBasicInformation.tsx index 5da781cbe..43772fa6b 100644 --- a/frontend/packages/akr/src/components/clerkTranslator/new/NewTranslatorBasicInformation.tsx +++ b/frontend/packages/akr/src/components/clerkTranslator/new/NewTranslatorBasicInformation.tsx @@ -4,6 +4,7 @@ import { ClerkTranslatorDetailsFields } from 'components/clerkTranslator/overvie import { useAppDispatch, useAppSelector } from 'configs/redux'; import { ClerkNewTranslator } from 'interfaces/clerkNewTranslator'; import { + ClerkTranslatorAddress, ClerkTranslatorBasicInformation, ClerkTranslatorTextFields, } from 'interfaces/clerkTranslator'; @@ -38,9 +39,13 @@ export const NewTranslatorBasicInformation = ({ handleFieldChange(field, checked); }; + const handleAddressChange = (addresses: Array) => { + handleFieldChange('address', addresses); + }; + const handleFieldChange = ( field: keyof ClerkTranslatorBasicInformation, - fieldValue: string | boolean | undefined, + fieldValue: string | boolean | Array | undefined, ) => { const updatedTranslatorDetails = { ...translator, @@ -60,6 +65,7 @@ export const NewTranslatorBasicInformation = ({ onTextFieldChange={(field: keyof ClerkTranslatorTextFields) => handleTextFieldChange(field) } + onAddressChange={handleAddressChange} // onComboBoxChange={(field: keyof ClerkTranslatorBasicInformation) => // handleComboBoxChange(field) // } diff --git a/frontend/packages/akr/src/components/clerkTranslator/overview/ClerkTranslatorDetails.tsx b/frontend/packages/akr/src/components/clerkTranslator/overview/ClerkTranslatorDetails.tsx index 48a8737d6..244531c49 100644 --- a/frontend/packages/akr/src/components/clerkTranslator/overview/ClerkTranslatorDetails.tsx +++ b/frontend/packages/akr/src/components/clerkTranslator/overview/ClerkTranslatorDetails.tsx @@ -98,7 +98,7 @@ export const ClerkTranslatorDetails = () => { const handleFieldChange = ( field: keyof ClerkTranslatorBasicInformation, - fieldValue: string | boolean | undefined, + fieldValue: string | boolean | Array | undefined, ) => { const updatedTranslatorDetails = { ...translatorDetails, diff --git a/frontend/packages/akr/src/components/clerkTranslator/overview/ClerkTranslatorDetailsFields.tsx b/frontend/packages/akr/src/components/clerkTranslator/overview/ClerkTranslatorDetailsFields.tsx index c92fa9ded..d39f8ee4a 100644 --- a/frontend/packages/akr/src/components/clerkTranslator/overview/ClerkTranslatorDetailsFields.tsx +++ b/frontend/packages/akr/src/components/clerkTranslator/overview/ClerkTranslatorDetailsFields.tsx @@ -1,8 +1,5 @@ import { - FormControlLabel, FormHelperTextProps, - Radio, - RadioGroup, TableCell, TableHead, TableRow, @@ -10,13 +7,19 @@ import { import { ChangeEvent, useState } from 'react'; import { //ComboBox, + CustomButton, CustomSwitch, CustomTable, CustomTextField, H3, InfoText, + Text, } from 'shared/components'; -import { TextFieldTypes /*TextFieldVariant*/ } from 'shared/enums'; +import { + Color, + TextFieldTypes /*TextFieldVariant*/, + Variant, +} from 'shared/enums'; import { InputFieldUtils } from 'shared/utils'; import { @@ -25,15 +28,21 @@ import { useCommonTranslation, //useKoodistoCountriesTranslation, } from 'configs/i18n'; -import { ClerkTranslatorTextFieldEnum } from 'enums/clerkTranslator'; +import { + ClerkTranslatorAddressFieldEnum, + ClerkTranslatorTextFieldEnum, +} from 'enums/clerkTranslator'; import { ClerkTranslatorAddress, ClerkTranslatorBasicInformation, ClerkTranslatorTextFields, } from 'interfaces/clerkTranslator'; import { ClerkTranslatorTextFieldProps } from 'interfaces/clerkTranslatorTextField'; +import { WithId } from 'interfaces/with'; //import koodistoCountriesFI from 'public/i18n/koodisto/countries/koodisto_countries_fi-FI.json'; +type ClerkTranslatorAddressRow = ClerkTranslatorAddress & WithId; + const textFieldMaxLengths = { [ClerkTranslatorTextFieldEnum.IdentityNumber]: 255, [ClerkTranslatorTextFieldEnum.LastName]: 255, @@ -41,10 +50,6 @@ const textFieldMaxLengths = { [ClerkTranslatorTextFieldEnum.NickName]: 255, [ClerkTranslatorTextFieldEnum.Email]: 255, [ClerkTranslatorTextFieldEnum.PhoneNumber]: 255, - [ClerkTranslatorTextFieldEnum.Street]: 255, - [ClerkTranslatorTextFieldEnum.PostalCode]: 255, - [ClerkTranslatorTextFieldEnum.Town]: 255, - [ClerkTranslatorTextFieldEnum.Country]: 255, [ClerkTranslatorTextFieldEnum.ExtraInformation]: 4096, }; @@ -126,6 +131,38 @@ const ClerkTranslatorDetailsTextField = ({ ); }; +const ClerkTranslatorPrimaryAddress = ({ + addresses, +}: { + addresses: Array; +}) => { + const { t } = useAppTranslation({ + keyPrefix: + 'akr.component.clerkTranslatorOverview.translatorDetails.address', + }); + const address = addresses.filter((address) => address.selected); + + if (address.length <= 0) { + return <>; + } + + const selectedAddress = address[0]; + + return ( +
+ {selectedAddress.street} + + {selectedAddress.postalCode} {selectedAddress.town} + + {selectedAddress.country} +
+ + Osoitteen lähde: {t(selectedAddress.source)} ({t(selectedAddress.type)}) + +
+ ); +}; + const ClerkTranslatorAddressFields = ({ addresses, onAddressChange, @@ -147,49 +184,52 @@ const ClerkTranslatorAddressFields = ({ Kaupunki Maa Osoitteen lähde - Valitse osoitelähde + Toiminnot ); + const handleSelectAsPrimary = (address: ClerkTranslatorAddress) => () => + onAddressChange( + addresses.map((addr) => ({ + ...addr, + selected: addr.type === address.type && addr.source === address.source, + })), + ); + const getRowDetails = (address: ClerkTranslatorAddress) => ( - {address[ClerkTranslatorTextFieldEnum.Street]} - {address[ClerkTranslatorTextFieldEnum.PostalCode]} - {address[ClerkTranslatorTextFieldEnum.Town]} - {address[ClerkTranslatorTextFieldEnum.Country]} + {address[ClerkTranslatorAddressFieldEnum.Street]} + + {address[ClerkTranslatorAddressFieldEnum.PostalCode]} + + {address[ClerkTranslatorAddressFieldEnum.Town]} + {address[ClerkTranslatorAddressFieldEnum.Country]} {t(address.source)}
({t(address.type)})
- { - onAddressChange( - addresses.map((addr) => ({ - ...addr, - selected: - addr.source === address.source && addr.type === address.type, - })), - ); - }} + - } - checked={address.selected} - label={'Käytä lähdettä'} - /> - + Vaihda lähteeksi +
); - const addIdToData = (address: ClerkTranslatorAddress) => ({ - id: address.source + '-' + address.type, + const filterNonSelected = (address: ClerkTranslatorAddress) => + !address.selected; + const addIdToData = ( + address: ClerkTranslatorAddress, + idx: number, + ): ClerkTranslatorAddressRow => ({ + id: idx, ...address, }); @@ -197,7 +237,7 @@ const ClerkTranslatorAddressFields = ({ } - data={addresses.map(addIdToData)} + data={addresses.filter(filterNonSelected).map(addIdToData)} getRowDetails={getRowDetails} stickyHeader /> @@ -264,20 +304,7 @@ export const ClerkTranslatorDetailsFields = ({ ClerkTranslatorTextFieldEnum.NickName, ].includes(field); - const isIndividualisedAddressField = - isAddressIndividualised && - [ - ClerkTranslatorTextFieldEnum.Street, - ClerkTranslatorTextFieldEnum.PostalCode, - ClerkTranslatorTextFieldEnum.Town, - ClerkTranslatorTextFieldEnum.Country, - ].includes(field); - - return ( - isIdentityNumberField || - isIndividualisedPersonalInformationField || - isIndividualisedAddressField - ); + return isIdentityNumberField || isIndividualisedPersonalInformationField; }; const getCommonTextFieldProps = (field: ClerkTranslatorTextFieldEnum) => { @@ -344,6 +371,10 @@ export const ClerkTranslatorDetailsFields = ({ {t('individualisedInformation')} )} +
+ +
+

Muut osoitteet

; }