Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(new-primary-school): Child info page #17514

Merged
merged 10 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/application/core/src/lib/fieldBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export const buildTextField = (
min,
readOnly,
rightAlign,
tooltip,
onChange,
} = data
return {
Expand All @@ -315,6 +316,7 @@ export const buildTextField = (
rightAlign,
max,
min,
tooltip,
onChange,
type: FieldTypes.TEXT,
component: FieldComponents.TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const transformApplicationToNewPrimarySchoolDTO = (
application: Application,
): FormDto => {
const {
differentPlaceOfResidence,
childInfo,
parents,
siblings,
Expand Down Expand Up @@ -95,13 +94,18 @@ export const transformApplicationToNewPrimarySchoolDTO = (
user: {
name: childInfo.name,
nationalId: childInfo.nationalId,
preferredName: childInfo.preferredName,
pronouns: childInfo.pronouns,
...(childInfo.usePronounAndPreferredName?.includes(YES)
? {
preferredName: childInfo.preferredName,
pronouns: childInfo.pronouns,
}
: {}),
domicile: {
address: childInfo.address.streetAddress,
postCode: childInfo.address.postalCode,
},
...(differentPlaceOfResidence === YES && childInfo.placeOfResidence
...(childInfo.differentPlaceOfResidence === YES &&
childInfo.placeOfResidence
? {
residence: {
address: childInfo.placeOfResidence.streetAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
FieldBaseProps,
FieldComponents,
FieldTypes,
FormTextWithLocale,
} from '@island.is/application/types'
import { TextFormField } from '@island.is/application/ui-fields'
import { useLocale } from '@island.is/localization'
import { FC, useEffect } from 'react'
import { useFormContext } from 'react-hook-form'
import { formatTextWithLocale } from '@island.is/application/core'
import { Locale } from '@island.is/shared/types'

interface DynamicDisabledTextProps {
field: {
props: {
value: FormTextWithLocale
}
}
}

const DynamicDisabledText: FC<
React.PropsWithChildren<FieldBaseProps & DynamicDisabledTextProps>
> = ({ field, application }) => {
const { lang: locale, formatMessage } = useLocale()
const { setValue } = useFormContext()
const {
title,
id,
width,
props: { value },
} = field

const defaultValue = formatTextWithLocale(
value,
application,
locale as Locale,
formatMessage,
)

useEffect(() => {
setValue(id, defaultValue)
}, [id, defaultValue, setValue])

return (
<TextFormField
application={application}
showFieldName
field={{
id,
disabled: true,
defaultValue,
title,
width,
type: FieldTypes.TEXT,
component: FieldComponents.TEXT,
children: undefined,
}}
/>
)
}

export default DynamicDisabledText
HjorturJ marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { OptionsType } from '../../../lib/constants'
import { newPrimarySchoolMessages } from '../../../lib/messages'
import {
getApplicationAnswers,
getGenderMessage,
getSelectedOptionLabel,
} from '../../../lib/newPrimarySchoolUtils'
import { ReviewGroupProps } from './props'
Expand All @@ -25,16 +26,16 @@ export const Child = ({
goToScreen,
}: ReviewGroupProps) => {
const { formatMessage } = useLocale()
const { childInfo, differentPlaceOfResidence } = getApplicationAnswers(
application.answers,
)
const { childInfo } = getApplicationAnswers(application.answers)

const {
options: pronounOptions,
loading,
error,
} = useFriggOptions(OptionsType.PRONOUN)

const genderMessage = getGenderMessage(application)

return (
<ReviewGroup
isEditable={editable}
Expand Down Expand Up @@ -86,11 +87,15 @@ export const Child = ({
/>
</GridColumn>
</GridRow>
{(childInfo.preferredName?.trim().length > 0 ||
childInfo.pronouns?.length > 0 ||
differentPlaceOfResidence === YES) && (
<GridRow rowGap={2}>
{childInfo.preferredName?.trim().length > 0 && (
<GridRow rowGap={2}>
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(newPrimarySchoolMessages.shared.gender)}
value={formatMessage(genderMessage)}
/>
</GridColumn>
{childInfo.usePronounAndPreferredName?.includes(YES) &&
childInfo.preferredName?.trim().length > 0 && (
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(
Expand All @@ -101,8 +106,9 @@ export const Child = ({
/>
</GridColumn>
)}
{childInfo.pronouns?.length > 0 && (
<GridColumn span={['12/12', '12/12', '12/12', '12/12']}>
{childInfo.usePronounAndPreferredName?.includes(YES) &&
childInfo.pronouns?.length > 0 && (
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(
newPrimarySchoolMessages.childrenNParents
Expand All @@ -121,19 +127,18 @@ export const Child = ({
/>
</GridColumn>
)}
{differentPlaceOfResidence === YES && (
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(
newPrimarySchoolMessages.childrenNParents
.childInfoPlaceOfResidence,
)}
value={`${childInfo.placeOfResidence?.streetAddress}, ${childInfo.placeOfResidence?.postalCode}`}
/>
</GridColumn>
)}
</GridRow>
)}
{childInfo.differentPlaceOfResidence === YES && (
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(
newPrimarySchoolMessages.childrenNParents
.childInfoPlaceOfResidence,
)}
value={`${childInfo.placeOfResidence?.streetAddress}, ${childInfo.placeOfResidence?.postalCode}`}
/>
</GridColumn>
)}
</GridRow>
</>
)}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as FriggOptionsAsyncSelectField } from './FriggOptionsAsyncSelectField'
export { default as Grade } from './Grade'
export { default as DynamicDisabledText } from './DynamicDisabledText'
export { default as ContactsTableRepeater } from './ContactsTableRepeater'
export { Review } from './Review'
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
buildCheckboxField,
buildCustomField,
buildMultiField,
buildRadioField,
Expand All @@ -11,6 +12,7 @@ import { newPrimarySchoolMessages } from '../../../lib/messages'
import {
getApplicationAnswers,
getApplicationExternalData,
getGenderMessage,
} from '../../../lib/newPrimarySchoolUtils'

export const childInfoSubSection = buildSubSection({
Expand Down Expand Up @@ -67,10 +69,40 @@ export const childInfoSubSection = buildSubSection({
defaultValue: (application: Application) =>
getApplicationExternalData(application.externalData).applicantCity,
}),
buildCustomField(
{
id: 'childInfo.gender',
component: 'DynamicDisabledText',
title: newPrimarySchoolMessages.shared.gender,
},
{
value: (application: Application) => getGenderMessage(application),
},
),
buildCheckboxField({
helgifr marked this conversation as resolved.
Show resolved Hide resolved
helgifr marked this conversation as resolved.
Show resolved Hide resolved
id: 'childInfo.usePronounAndPreferredName',
title: '',
spacing: 0,
options: [
{
value: YES,
label:
newPrimarySchoolMessages.childrenNParents
.usePronounAndPreferredName,
},
],
}),
helgifr marked this conversation as resolved.
Show resolved Hide resolved
buildTextField({
id: 'childInfo.preferredName',
title:
newPrimarySchoolMessages.childrenNParents.childInfoPreferredName,
tooltip:
newPrimarySchoolMessages.childrenNParents.preferredNameTooltip,
condition: (answers) => {
const { childInfo } = getApplicationAnswers(answers)

return !!childInfo?.usePronounAndPreferredName?.includes(YES)
},
defaultValue: (application: Application) =>
getApplicationExternalData(application.externalData)
.childInformation.preferredName ?? undefined,
Expand All @@ -79,6 +111,11 @@ export const childInfoSubSection = buildSubSection({
{
id: 'childInfo.pronouns',
title: newPrimarySchoolMessages.childrenNParents.childInfoPronouns,
condition: (answers) => {
helgifr marked this conversation as resolved.
Show resolved Hide resolved
const { childInfo } = getApplicationAnswers(answers)

return !!childInfo?.usePronounAndPreferredName?.includes(YES)
},
component: 'FriggOptionsAsyncSelectField',
defaultValue: (application: Application) =>
getApplicationExternalData(application.externalData)
Expand All @@ -96,6 +133,9 @@ export const childInfoSubSection = buildSubSection({
id: 'childInfo.differentPlaceOfResidence',
title:
newPrimarySchoolMessages.childrenNParents.differentPlaceOfResidence,
description:
newPrimarySchoolMessages.childrenNParents
.differentPlaceOfResidenceDescription,
width: 'half',
required: true,
space: 4,
Expand All @@ -117,9 +157,9 @@ export const childInfoSubSection = buildSubSection({
width: 'half',
required: true,
condition: (answers) => {
const { differentPlaceOfResidence } = getApplicationAnswers(answers)
const { childInfo } = getApplicationAnswers(answers)

return differentPlaceOfResidence === YES
return childInfo?.differentPlaceOfResidence === YES
},
}),
buildTextField({
Expand All @@ -129,9 +169,9 @@ export const childInfoSubSection = buildSubSection({
format: '###',
required: true,
condition: (answers) => {
const { differentPlaceOfResidence } = getApplicationAnswers(answers)
const { childInfo } = getApplicationAnswers(answers)

return differentPlaceOfResidence === YES
return childInfo?.differentPlaceOfResidence === YES
},
}),
],
Expand Down
Loading
Loading