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): Reason page - Data implementation #16304

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ export const transformApplicationToNewPrimarySchoolDTO = (
phone: relative.phoneNumber,
role: relative.relation,
})),
// TODO: Skoða hvernig ég veit hvaða ástæða var valin (ég er ekki með lista yfir ástæður)
...(reasonForApplication ===
ReasonForApplicationOptions.SIBLINGS_IN_THE_SAME_PRIMARY_SCHOOL
ReasonForApplicationOptions.SIBLINGS_IN_SAME_SCHOOL
? siblings.map((sibling) => ({
name: sibling.fullName,
nationalId: sibling.nationalId,
// TODO: Siblings relation valmöguleikar eru ekki í key-options endapunktinum => Júní ætlar að bæta því við (Þurfum að passa að þeir valmöguleikar komi ekki upp í dropdown á aðstandenda síðunni)
// TODO: Siblings relation options are not in the key-options endpoint => Júní has added "sibling" (We need to make sure that those options do not appear in the dropdown on the relatives page)
// TODO: We are waiting for a reply from MMS if this is important information or if we should remove it
role: sibling.relation,
}))
: []),
Expand Down Expand Up @@ -114,7 +114,6 @@ export const transformApplicationToNewPrimarySchoolDTO = (
},
agents,
registration: {
// TODO: Skoða hvernig ég veit hvaða ástæða var valin (ég er ekki með lista yfir ástæður)
defaultOrg: primaryOrgId,
...(reasonForApplication !== ReasonForApplicationOptions.MOVING_ABROAD
? {
Expand All @@ -127,7 +126,7 @@ export const transformApplicationToNewPrimarySchoolDTO = (
}),
reason: reasonForApplication,
...(reasonForApplication ===
ReasonForApplicationOptions.TRANSFER_OF_LEGAL_DOMICILE
ReasonForApplicationOptions.MOVING_MUNICIPALITY
? {
newDomicile: {
address: reasonForApplicationStreetAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const FriggOptionsAsyncSelectField: FC<
> = ({ error, field, application }) => {
const { lang } = useLocale()
const { title, props, defaultValue, id } = field
const { isMulti = true, optionsType, placeholder } = props
const { isMulti = false, optionsType, placeholder } = props

return (
<AsyncSelectFormField
Expand Down Expand Up @@ -58,7 +58,7 @@ const FriggOptionsAsyncSelectField: FC<
},
})

return (
const options =
data?.friggOptions?.flatMap(({ options }) =>
options.flatMap(({ value, key }) => {
let content = value.find(
Expand All @@ -72,7 +72,16 @@ const FriggOptionsAsyncSelectField: FC<
return { value: key ?? '', label: content ?? '' }
}),
) ?? []

const otherIndex = options.findIndex(
(option) => option.value === 'other',
)

if (otherIndex >= 0) {
options.push(options.splice(otherIndex, 1)[0])
}

return options
},
isMulti,
backgroundColor: 'blue',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const RelativesTableRepeater: FC<React.PropsWithChildren<FieldBaseProps>> = ({
}) => {
const { id, title } = field

const relationFriggOptions = useFriggOptions(OptionsType.RELATION)
const { options: relationFriggOptions } = useFriggOptions(
OptionsType.RELATION,
)

return (
<TableRepeaterFormField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const Review: FC<ReviewScreenProps> = ({
{reasonForApplication !== ReasonForApplicationOptions.MOVING_ABROAD && (
<>
{reasonForApplication ===
ReasonForApplicationOptions.SIBLINGS_IN_THE_SAME_PRIMARY_SCHOOL && (
ReasonForApplicationOptions.SIBLINGS_IN_SAME_SCHOOL && (
<Siblings {...childProps} />
)}
<School {...childProps} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { YES } from '@island.is/application/types'
import { DataValue, ReviewGroup } from '@island.is/application/ui-components'
import { GridColumn, GridRow, Stack, Text } from '@island.is/island-ui/core'
import {
GridColumn,
GridRow,
SkeletonLoader,
Stack,
Text,
} from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import { format as formatKennitala } from 'kennitala'
import { useFriggOptions } from '../../../hooks/useFriggOptions'
import { OptionsType } from '../../../lib/constants'
import { newPrimarySchoolMessages } from '../../../lib/messages'
import {
getApplicationAnswers,
getSelectedOptionLabel,
} from '../../../lib/newPrimarySchoolUtils'
import { ReviewGroupProps } from './props'
import { useFriggOptions } from '../../../hooks/useFriggOptions'
import { OptionsType } from '../../../lib/constants'
import { coreErrorMessages } from '@island.is/application/core'

export const Child = ({
application,
Expand All @@ -22,7 +29,11 @@ export const Child = ({
application.answers,
)

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

return (
<ReviewGroup
Expand All @@ -37,77 +48,93 @@ export const Child = ({
</Text>
</GridColumn>
</GridRow>
<GridRow rowGap={2}>
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(newPrimarySchoolMessages.shared.fullName)}
value={childInfo.name}
/>
</GridColumn>
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(newPrimarySchoolMessages.shared.nationalId)}
value={formatKennitala(childInfo.nationalId)}
/>
</GridColumn>
</GridRow>
<GridRow rowGap={2}>
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(newPrimarySchoolMessages.shared.address)}
value={childInfo.address.streetAddress}
/>
</GridColumn>
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(
newPrimarySchoolMessages.shared.municipality,
)}
value={`${childInfo.address.postalCode}, ${childInfo.address.city}`}
/>
</GridColumn>
</GridRow>
{(childInfo.preferredName ||
childInfo.pronouns?.length > 0 ||
differentPlaceOfResidence === YES) && (
<GridRow rowGap={2}>
{childInfo.preferredName && (
{childInfo.pronouns?.length > 0 && loading ? (
<SkeletonLoader height={40} width="100%" borderRadius="large" />
) : (
veronikasif marked this conversation as resolved.
Show resolved Hide resolved
<>
<GridRow rowGap={2}>
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(
newPrimarySchoolMessages.childrenNParents
.childInfoPreferredName,
newPrimarySchoolMessages.shared.fullName,
)}
value={childInfo.preferredName}
value={childInfo.name}
/>
</GridColumn>
)}
{childInfo.pronouns?.length > 0 && (
<GridColumn span={['12/12', '12/12', '12/12', '12/12']}>
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(
newPrimarySchoolMessages.childrenNParents.childInfoPronouns,
newPrimarySchoolMessages.shared.nationalId,
)}
value={childInfo.pronouns
.map((pronoun) =>
getSelectedOptionLabel(pronounOptions, pronoun),
)
.join(', ')}
value={formatKennitala(childInfo.nationalId)}
/>
</GridColumn>
</GridRow>
<GridRow rowGap={2}>
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(newPrimarySchoolMessages.shared.address)}
value={childInfo.address.streetAddress}
/>
</GridColumn>
)}
{differentPlaceOfResidence === YES && (
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(
newPrimarySchoolMessages.childrenNParents
.childInfoPlaceOfResidence,
newPrimarySchoolMessages.shared.municipality,
)}
value={`${childInfo.placeOfResidence?.streetAddress}, ${childInfo.placeOfResidence?.postalCode}`}
value={`${childInfo.address.postalCode}, ${childInfo.address.city}`}
/>
</GridColumn>
</GridRow>
{(childInfo.preferredName?.trim().length > 0 ||
childInfo.pronouns?.length > 0 ||
differentPlaceOfResidence === YES) && (
<GridRow rowGap={2}>
{childInfo.preferredName?.trim().length > 0 && (
<GridColumn span={['12/12', '12/12', '12/12', '5/12']}>
<DataValue
label={formatMessage(
newPrimarySchoolMessages.childrenNParents
.childInfoPreferredName,
)}
value={childInfo.preferredName}
/>
</GridColumn>
)}
{childInfo.pronouns?.length > 0 && (
<GridColumn span={['12/12', '12/12', '12/12', '12/12']}>
<DataValue
label={formatMessage(
newPrimarySchoolMessages.childrenNParents
.childInfoPronouns,
)}
value={childInfo.pronouns
.map((pronoun) =>
getSelectedOptionLabel(pronounOptions, pronoun),
)
.join(', ')}
error={
error
? formatMessage(coreErrorMessages.failedDataProvider)
: undefined
}
/>
</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>
)}
</GridRow>
</>
)}
</Stack>
</ReviewGroup>
Expand Down
Loading