-
Notifications
You must be signed in to change notification settings - Fork 3
PT-453 | Add cultural route support to enrolment form #495
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { IsPartOfCulturalRoute } from '../enrolmentForm/constants'; | ||
| import { validIsPartOfCulturalRouteToBoolean } from '../utils'; | ||
|
|
||
| describe('validIsPartOfCulturalRouteToBoolean', () => { | ||
| test.each<IsPartOfCulturalRoute | string>([ | ||
| IsPartOfCulturalRoute.YES, // Test that the enum version works | ||
| 'YES', // Test that the string version also works | ||
| ])('validIsPartOfCulturalRouteToBoolean(%p) returns true', (input) => { | ||
| expect(validIsPartOfCulturalRouteToBoolean(input)).toBe(true); | ||
| }); | ||
|
|
||
| test.each<IsPartOfCulturalRoute | string>([ | ||
| IsPartOfCulturalRoute.NO_OR_UNKNOWN, // Test that the enum version works | ||
| 'NO_OR_UNKNOWN', // Test that the string version also works | ||
| ])('validIsPartOfCulturalRouteToBoolean(%p) returns false', (input) => { | ||
| expect(validIsPartOfCulturalRouteToBoolean(input)).toBe(false); | ||
| }); | ||
|
|
||
| test.each(['', ' ', 'yes', 'NO', 'unanswered', null, undefined, true, 0, 1])( | ||
| 'validIsPartOfCulturalRouteToBoolean(%p) throws on invalid value', | ||
| (input) => { | ||
| expect(() => validIsPartOfCulturalRouteToBoolean(input)).toThrow( | ||
| `Invalid isPartOfCulturalRoute value ${input}` | ||
| ); | ||
| } | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/domain/enrolment/enrolmentForm/IsPartOfCulturalRouteField.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { Link } from '@city-of-helsinki/react-helsinki-headless-cms'; | ||
| import { useField } from 'formik'; | ||
| import { RadioButton, SelectionGroup } from 'hds-react'; | ||
| import { Trans, useTranslation } from 'next-i18next'; | ||
| import React from 'react'; | ||
|
|
||
| import { IsPartOfCulturalRoute, nameToLabelPath } from './constants'; | ||
| import type { I18nNamespace } from '../../../types'; | ||
|
|
||
| type Props = { | ||
| formikFieldName: string; | ||
| }; | ||
|
|
||
| /** | ||
| * React component for "Is part of cultural route?" field in the enrolment form, | ||
| * with choices of "No / I don't know" and "Yes". | ||
| */ | ||
| const IsPartOfCulturalRouteField: React.FC<Props> = ({ formikFieldName }) => { | ||
| const { t } = useTranslation<I18nNamespace>(); | ||
| const [field, meta] = useField(formikFieldName); | ||
| const errorText = meta.touched && meta.error ? t(meta.error) : undefined; | ||
| const readMoreUrl = t('enrolment:enrolmentForm.culturalRoute.readMoreUrl'); | ||
|
|
||
| return ( | ||
| <SelectionGroup | ||
| label={t(nameToLabelPath['isPartOfCulturalRoute'])} | ||
| direction="horizontal" | ||
| required | ||
| aria-required | ||
| errorText={errorText} | ||
| /* @ts-expect-error TS2322 SelectionGroup's types allow only string, but Trans works */ | ||
| helperText={ | ||
| <Trans | ||
| t={t} | ||
| i18nKey={'enrolment:enrolmentForm.culturalRoute.helperText'} | ||
| components={{ a: <Link href={readMoreUrl} /> }} | ||
| /> | ||
| } | ||
| > | ||
| <RadioButton | ||
| id="isPartOfCulturalRoute-noOrUnknown" | ||
| name={field.name} | ||
| value={IsPartOfCulturalRoute.NO_OR_UNKNOWN} | ||
| label={t('enrolment:enrolmentForm.culturalRoute.labelNoOrUnknown')} | ||
| checked={field.value === IsPartOfCulturalRoute.NO_OR_UNKNOWN} | ||
| onChange={field.onChange} | ||
| onBlur={field.onBlur} | ||
| /> | ||
| <RadioButton | ||
| id="isPartOfCulturalRoute-yes" | ||
| name={field.name} | ||
| value={IsPartOfCulturalRoute.YES} | ||
| label={t('enrolment:enrolmentForm.culturalRoute.labelYes')} | ||
| checked={field.value === IsPartOfCulturalRoute.YES} | ||
| onChange={field.onChange} | ||
| onBlur={field.onBlur} | ||
| /> | ||
| </SelectionGroup> | ||
| ); | ||
| }; | ||
|
|
||
| export default IsPartOfCulturalRouteField; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it changes the result or analysis any how, but now I could understand this is "No / I don't know what cultural route is / I don't want to give an answer".
I would have personally used just a checkbox. If I know what a cultural route is, I would check it. I'm enrolling and I need to check that all the information that I have given with form is valid. If we would really trust in users and in the given input, this would be easy boolean analysis and way easier to implement and even cleaner UI and UX. Now we are doing much work only to guide the report analysis, because the input would still be the same -- This implementation still does not answer to report analysis question whether or not the user has seen this question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked with the product owner about their needs and they wanted this so that people always choose a value, that they need to make a choice. So, making the user always choose a value for this is intentional and as per product owner's wishes.