-
Notifications
You must be signed in to change notification settings - Fork 0
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
Get Contact page question labels and descriptions from back-end #744
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c3122c4
Get contact texts from BE
alimpens 5484de5
Remove unnecessary abstraction
alimpens 9978249
Revert changes to FormRenderer
alimpens 02a0fa5
Merge branch 'main' into get-static-form-texts-from-be
alimpens 999143e
Revert api client type import changes
alimpens 47eae02
Fix tests
alimpens ad07fc3
Fix build
alimpens 0e37335
Use explicit type guard
alimpens 19be415
Wrap fetches in try...catch block
alimpens 9cd061f
Fix tests
alimpens 20ed7ce
Merge branch 'main' of https://github.com/Amsterdam/meldingen-fronten…
alimpens f7750b8
Handle error
alimpens 54b7dfb
Split labels and descriptions in Contact component, make functions im…
alimpens 2199d31
Change static form mocks
alimpens bc029de
Add tests
alimpens d51a4c5
Change test description
alimpens aee2277
Merge branch 'main' into get-static-form-texts-from-be
alimpens 9369250
Update comment
alimpens e712f32
Update test description
alimpens 5335878
Merge branch 'main' into get-static-form-texts-from-be
alimpens 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 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 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 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 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 |
---|---|---|
|
@@ -4,15 +4,22 @@ import { Alert, Heading, Label, Paragraph, TextInput } from '@amsterdam/design-s | |
import { Grid, SubmitButton } from '@meldingen/ui' | ||
import { useActionState } from 'react' | ||
|
||
import type { StaticFormTextAreaComponentOutput } from 'apps/public/src/apiClientProxy' | ||
|
||
import { BackLink } from '../_components/BackLink' | ||
|
||
import { postContactForm } from './actions' | ||
|
||
const initialState: { message?: string } = {} | ||
|
||
export const Contact = () => { | ||
export const Contact = ({ formData }: { formData: StaticFormTextAreaComponentOutput[] }) => { | ||
const [formState, formAction] = useActionState(postContactForm, initialState) | ||
|
||
const emailLabel = formData[0].label | ||
const emailDescription = formData[0].description | ||
const telLabel = formData[1].label | ||
const telDescription = formData[1].description | ||
|
||
return ( | ||
<Grid paddingBottom="large" paddingTop="medium"> | ||
<Grid.Cell span={{ narrow: 4, medium: 6, wide: 6 }} start={{ narrow: 1, medium: 2, wide: 3 }}> | ||
Comment on lines
23
to
25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component needs internationalisation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. I didn't do that yet to prevent merge conflicts. |
||
|
@@ -39,9 +46,15 @@ export const Contact = () => { | |
</Alert> | ||
)} | ||
<Label htmlFor="email-input" optional className="ams-mb--sm"> | ||
Wat is uw e-mailadres? | ||
{emailLabel} | ||
</Label> | ||
{emailDescription && ( | ||
<Paragraph size="small" id="email-input-description"> | ||
{emailDescription} | ||
</Paragraph> | ||
)} | ||
<TextInput | ||
aria-describedby={emailDescription ? 'email-input-description' : undefined} | ||
name="email" | ||
id="email-input" | ||
type="email" | ||
|
@@ -51,9 +64,21 @@ export const Contact = () => { | |
className="ams-mb--sm" | ||
/> | ||
<Label htmlFor="tel-input" optional className="ams-mb--sm"> | ||
Wat is uw telefoonnummer? | ||
{telLabel} | ||
</Label> | ||
<TextInput name="phone" id="tel-input" type="tel" autoComplete="tel" className="ams-mb--sm" /> | ||
{telDescription && ( | ||
<Paragraph size="small" id="tel-input-description"> | ||
{telDescription} | ||
</Paragraph> | ||
)} | ||
<TextInput | ||
aria-describedby={telDescription ? 'tel-input-description' : undefined} | ||
autoComplete="tel" | ||
className="ams-mb--sm" | ||
id="tel-input" | ||
name="phone" | ||
type="tel" | ||
/> | ||
<SubmitButton>Volgende vraag</SubmitButton> | ||
</form> | ||
</Grid.Cell> | ||
|
This file contains 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 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 |
---|---|---|
@@ -1,9 +1,36 @@ | ||
import type { Metadata } from 'next' | ||
|
||
import type { StaticFormOutput, StaticFormTextAreaComponentOutput } from 'apps/public/src/apiClientProxy' | ||
import { getStaticForm, getStaticFormByStaticFormId } from 'apps/public/src/apiClientProxy' | ||
|
||
import { Contact } from './Contact' | ||
|
||
// TODO: Force dynamic rendering for now, because the api isn't accessible in the pipeline yet. | ||
// We can remove this when the api is deployed. | ||
export const dynamic = 'force-dynamic' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Stap 3 van 4 - Gegevens - Gemeente Amsterdam', | ||
} | ||
|
||
export default async () => <Contact /> | ||
const isTextArea = ( | ||
component: StaticFormOutput['components'][number], | ||
): component is StaticFormTextAreaComponentOutput => component.type === 'textarea' | ||
|
||
export default async () => { | ||
try { | ||
const contactFormId = await getStaticForm().then((response) => response.find((form) => form.type === 'contact')?.id) | ||
|
||
if (!contactFormId) throw new Error('Contact form id not found') | ||
|
||
const contactForm = (await getStaticFormByStaticFormId({ staticFormId: contactFormId })).components | ||
// A contact form is always an array of two text area components, but TypeScript doesn't know that | ||
// We use a type guard here to make sure we're always working with the right type | ||
const filteredContactForm = contactForm.filter(isTextArea) | ||
|
||
if (!filteredContactForm[0].label || !filteredContactForm[1].label) throw new Error('Contact form labels not found') | ||
return <Contact formData={filteredContactForm} /> | ||
} catch (error) { | ||
return (error as Error).message | ||
} | ||
} |
This file contains 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 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 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 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,28 @@ | ||
{ | ||
"components": [ | ||
{ | ||
"label": "First question", | ||
"description": "", | ||
"key": "textArea1", | ||
"type": "textarea", | ||
"input": true, | ||
"autoExpand": false, | ||
"showCharCount": false, | ||
"position": 1, | ||
"question": 1, | ||
"values": null | ||
}, | ||
{ | ||
"label": "Second question", | ||
"description": "", | ||
"key": "textArea2", | ||
"type": "textarea", | ||
"input": true, | ||
"autoExpand": false, | ||
"showCharCount": false, | ||
"position": 2, | ||
"question": 2, | ||
"values": null | ||
} | ||
] | ||
} |
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.
We didn't set a test coverage limit, but
branches
of this component are at 77% since the airadescribedby is not tested.