Skip to content

Commit 5df7455

Browse files
authored
Prefill fields on HCB apply form via query parameters (#1068)
1 parent 9e9e845 commit 5df7455

File tree

4 files changed

+31
-29
lines changed

4 files changed

+31
-29
lines changed

components/hcb/apply-button.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
import { Button, Text, Image, Flex } from 'theme-ui'
22
import Icon from '../icon'
3+
import Link from 'next/link'
34

45
export default function ApplyButton() {
56
return (
6-
<Button
7-
variant="ctaLg"
8-
as="a"
9-
href="/hcb/apply"
10-
sx={{
11-
width: '100%',
12-
height: '4.2rem'
13-
// borderRadius: '1.5rem',
14-
}}
15-
>
16-
<Flex
7+
<Link href="/hcb/apply" passHref legacyBehavior>
8+
<Button
9+
variant="ctaLg"
10+
as="a"
1711
sx={{
18-
alignItems: 'center',
19-
gap: 3,
20-
mr: '-32px' // Man...
12+
width: '100%',
13+
height: '4.2rem'
14+
// borderRadius: '1.5rem',
2115
}}
2216
>
23-
<Text color="white" sx={{ fontWeight: 'bold', fontSize: 4 }}>
24-
Apply now
25-
</Text>
26-
<Icon glyph="view-forward" size={46} color="white" />
27-
</Flex>
28-
</Button>
17+
<Flex
18+
sx={{
19+
alignItems: 'center',
20+
gap: 3,
21+
mr: '-32px' // Man...
22+
}}
23+
>
24+
<Text color="white" sx={{ fontWeight: 'bold', fontSize: 4 }}>
25+
Apply now
26+
</Text>
27+
<Icon glyph="view-forward" size={46} color="white" />
28+
</Flex>
29+
</Button>
30+
</Link>
2931
)
3032
}

components/hcb/apply/checkbox.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import { useEffect, useState } from 'react'
22
import Icon from '../../icon'
3+
import { useRouter } from 'next/router'
34

45
export default function Checkbox({ name, defaultChecked = false, size = 38 }) {
56
const [checked, setChecked] = useState(defaultChecked)
67
const toggle = () => setChecked(!checked)
8+
const router = useRouter()
79

810
/* Fill in the field with the value from sessionStorage.
911
For other input elements, the value is set in the Field component,
1012
but these checkboxes hold their state in useState rather than in the DOM. */
1113
useEffect(() => {
12-
const value = sessionStorage.getItem('bank-signup-' + name)
14+
const value = router.query[name] || sessionStorage.getItem('bank-signup-' + name)
1315
if (value) {
1416
const input = document.getElementById(name)
15-
input && setChecked(value === 'true')
17+
input && setChecked(!!value)
1618
}
17-
}, [name])
19+
}, [router.query, name])
1820

1921
return (
2022
<>

components/hcb/apply/field.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export default function Field({
1818
/* Fill in the field input element with the value from sessionStorage.
1919
Note: the custom checkbox component does this in its own useEffect hook. */
2020
useEffect(() => {
21-
const value = sessionStorage.getItem('bank-signup-' + name)
21+
const value = router.query[name] || sessionStorage.getItem('bank-signup-' + name)
2222
if (value) {
2323
const input = document.getElementById(name)
2424
if (input) input.value = value
2525
}
26-
}, [name])
26+
}, [router.query, name])
2727

2828
return (
2929
<FlexCol gap={2} width={'100%'}>

pages/hcb/apply/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default function Apply() {
6767

6868
// Set the query url parameter to 1 if it's not present
6969
if (!step || step < 1) {
70-
router.push(
70+
router.replace(
7171
{
7272
pathname: router.pathname,
7373
query: { ...router.query, step: 1 }
@@ -110,9 +110,7 @@ export default function Apply() {
110110
<Box sx={{ gridArea: 'form', overflowY: 'auto' }}>
111111
<FormContainer ref={formContainer}>
112112
{step === 1 && <HCBInfo />}
113-
{step === 2 && (
114-
<OrganizationInfoForm requiredFields={requiredFields} />
115-
)}
113+
{step === 2 && <OrganizationInfoForm requiredFields={requiredFields} />}
116114
{step === 3 && <PersonalInfoForm requiredFields={requiredFields} />}
117115
</FormContainer>
118116
</Box>

0 commit comments

Comments
 (0)