Skip to content

Commit

Permalink
AKR(Backend & Frontend) ONR multiple address feature continues
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Feb 13, 2024
1 parent d2eca11 commit a7282b3
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fi.oph.akr.api.dto.clerk;

import java.util.List;
import lombok.Builder;
import lombok.NonNull;

Expand All @@ -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<ClerkTranslatorAddressDTO> address
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,11 @@ private static Iterator<String> cyclicIterator(final String... values) {

private final Iterator<String> countries = cyclicIterator("Suomi", "suomi", "SUOMI", "Finland", "", null);

private final Iterator<String> streetsVTJ = cyclicIterator(
"Downing Street 1",
null
);
private final Iterator<String> streetsVTJ = cyclicIterator("Downing Street 1", null);

private final Iterator<String> postalCodesVTJ = cyclicIterator(
"00100",
null
);
private final Iterator<String> postalCodesVTJ = cyclicIterator("00100", null);

private final Iterator<String> townsVTJ = cyclicIterator(
"London",
null
);
private final Iterator<String> townsVTJ = cyclicIterator("London", null);

private final Iterator<String> countriesVTJ = cyclicIterator("UK", "DEU", "", null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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<ClerkTranslatorAddressDTO> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -38,9 +39,13 @@ export const NewTranslatorBasicInformation = ({
handleFieldChange(field, checked);
};

const handleAddressChange = (addresses: Array<ClerkTranslatorAddress>) => {
handleFieldChange('address', addresses);
};

const handleFieldChange = (
field: keyof ClerkTranslatorBasicInformation,
fieldValue: string | boolean | undefined,
fieldValue: string | boolean | Array<ClerkTranslatorAddress> | undefined,
) => {
const updatedTranslatorDetails = {
...translator,
Expand All @@ -60,6 +65,7 @@ export const NewTranslatorBasicInformation = ({
onTextFieldChange={(field: keyof ClerkTranslatorTextFields) =>
handleTextFieldChange(field)
}
onAddressChange={handleAddressChange}
// onComboBoxChange={(field: keyof ClerkTranslatorBasicInformation) =>
// handleComboBoxChange(field)
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const ClerkTranslatorDetails = () => {

const handleFieldChange = (
field: keyof ClerkTranslatorBasicInformation,
fieldValue: string | boolean | undefined,
fieldValue: string | boolean | Array<ClerkTranslatorAddress> | undefined,
) => {
const updatedTranslatorDetails = {
...translatorDetails,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import {
FormControlLabel,
FormHelperTextProps,
Radio,
RadioGroup,
TableCell,
TableHead,
TableRow,
} from '@mui/material';
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 {
Expand All @@ -25,26 +28,28 @@ 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,
[ClerkTranslatorTextFieldEnum.FirstName]: 255,
[ClerkTranslatorTextFieldEnum.NickName]: 255,
[ClerkTranslatorTextFieldEnum.Email]: 255,
[ClerkTranslatorTextFieldEnum.PhoneNumber]: 255,
[ClerkTranslatorTextFieldEnum.Street]: 255,
[ClerkTranslatorTextFieldEnum.PostalCode]: 255,
[ClerkTranslatorTextFieldEnum.Town]: 255,
[ClerkTranslatorTextFieldEnum.Country]: 255,
[ClerkTranslatorTextFieldEnum.ExtraInformation]: 4096,
};

Expand Down Expand Up @@ -126,6 +131,38 @@ const ClerkTranslatorDetailsTextField = ({
);
};

const ClerkTranslatorPrimaryAddress = ({
addresses,
}: {
addresses: Array<ClerkTranslatorAddress>;
}) => {
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 (
<div>
<Text>{selectedAddress.street}</Text>
<Text>
{selectedAddress.postalCode} {selectedAddress.town}
</Text>
<Text>{selectedAddress.country}</Text>
<br />
<Text>
Osoitteen lähde: {t(selectedAddress.source)} ({t(selectedAddress.type)})
</Text>
</div>
);
};

const ClerkTranslatorAddressFields = ({
addresses,
onAddressChange,
Expand All @@ -147,57 +184,60 @@ const ClerkTranslatorAddressFields = ({
<TableCell>Kaupunki</TableCell>
<TableCell>Maa</TableCell>
<TableCell>Osoitteen lähde</TableCell>
<TableCell>Valitse osoitelähde</TableCell>
<TableCell>Toiminnot</TableCell>
</TableRow>
</TableHead>
);

const handleSelectAsPrimary = (address: ClerkTranslatorAddress) => () =>
onAddressChange(
addresses.map((addr) => ({
...addr,
selected: addr.type === address.type && addr.source === address.source,
})),
);

const getRowDetails = (address: ClerkTranslatorAddress) => (
<TableRow>
<TableCell>{address[ClerkTranslatorTextFieldEnum.Street]}</TableCell>
<TableCell>{address[ClerkTranslatorTextFieldEnum.PostalCode]}</TableCell>
<TableCell>{address[ClerkTranslatorTextFieldEnum.Town]}</TableCell>
<TableCell>{address[ClerkTranslatorTextFieldEnum.Country]}</TableCell>
<TableCell>{address[ClerkTranslatorAddressFieldEnum.Street]}</TableCell>
<TableCell>
{address[ClerkTranslatorAddressFieldEnum.PostalCode]}
</TableCell>
<TableCell>{address[ClerkTranslatorAddressFieldEnum.Town]}</TableCell>
<TableCell>{address[ClerkTranslatorAddressFieldEnum.Country]}</TableCell>
<TableCell>
{t(address.source)}
<br /> ({t(address.type)})
</TableCell>
<TableCell>
<RadioGroup
className="rows gapped-xxs"
name="full-exam-group"
onChange={() => {
onAddressChange(
addresses.map((addr) => ({
...addr,
selected:
addr.source === address.source && addr.type === address.type,
})),
);
}}
<CustomButton
data-testid="meeting-dates-page__add-btn"
variant={Variant.Outlined}
color={Color.Secondary}
disabled={editDisabled}
onClick={handleSelectAsPrimary(address)}
>
<FormControlLabel
disabled={editDisabled}
data-testid="enrollment-checkbox-full-exam"
control={<Radio aria-describedby="full-exam-error" />}
checked={address.selected}
label={'Käytä lähdettä'}
/>
</RadioGroup>
Vaihda lähteeksi
</CustomButton>
</TableCell>
</TableRow>
);

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,
});

return (
<CustomTable
className=""
header={<AddressHeader />}
data={addresses.map(addIdToData)}
data={addresses.filter(filterNonSelected).map(addIdToData)}
getRowDetails={getRowDetails}
stickyHeader
/>
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -344,6 +371,10 @@ export const ClerkTranslatorDetailsFields = ({
<InfoText>{t('individualisedInformation')}</InfoText>
</div>
)}
<div className="columns align-items-start gapped">
<ClerkTranslatorPrimaryAddress addresses={translator?.address || []} />
</div>
<H3>Muut osoitteet</H3>
<div className="columns align-items-start gapped">
<ClerkTranslatorAddressFields
addresses={translator?.address || []}
Expand Down
11 changes: 7 additions & 4 deletions frontend/packages/akr/src/enums/clerkTranslator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ export enum AuthorisationBasisEnum {
VIR = 'VIR',
}

export enum ClerkTranslatorAddressFieldEnum {
Street = 'street',
PostalCode = 'postalCode',
Town = 'town',
Country = 'country',
}

export enum ClerkTranslatorTextFieldEnum {
FirstName = 'firstName',
LastName = 'lastName',
NickName = 'nickName',
IdentityNumber = 'identityNumber',
Email = 'email',
PhoneNumber = 'phoneNumber',
Street = 'street',
PostalCode = 'postalCode',
Town = 'town',
Country = 'country',
ExtraInformation = 'extraInformation',
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/akr/src/interfaces/clerkTranslator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface ClerkTranslatorAddress {
country?: string;
source: string;
type: string;
selected: boolean;
selected?: boolean;
}

export interface ClerkTranslatorTextFields {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ const initialState: ClerkNewTranslatorState = {
firstName: '',
nickName: '',
identityNumber: '',
street: '',
postalCode: '',
town: '',
country: '',
address: [],
email: '',
phoneNumber: '',
extraInformation: '',
Expand Down Expand Up @@ -57,10 +54,6 @@ const clerkNewTranslatorSlice = createSlice({
state.translator.lastName = person.lastName;
state.translator.firstName = person.firstName;
state.translator.nickName = person.nickName;
state.translator.street = person.street;
state.translator.postalCode = person.postalCode;
state.translator.town = person.town;
state.translator.country = person.country;
},
rejectClerkNewTranslator(state) {
state.status = APIResponseStatus.Error;
Expand Down
Loading

0 comments on commit a7282b3

Please sign in to comment.