Skip to content

Commit b113feb

Browse files
authored
Core 1079 port adoption and interest pages to ts (#2763)
* Adoption & Interest pages * General page * Cover partners page filter-remover * General page test coverage * adoption and interest tests * Make role-selector test less flaky * Prettier
1 parent f010391 commit b113feb

File tree

18 files changed

+491
-255
lines changed

18 files changed

+491
-255
lines changed

src/app/components/book-checkbox/book-checkbox.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import React from 'react';
22
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
33
import {faCheck} from '@fortawesome/free-solid-svg-icons/faCheck';
44
import {treatSpaceOrEnterAsClick} from '~/helpers/events';
5-
import type { SalesforceBook } from '~/helpers/books';
5+
import type {SalesforceBook} from '~/helpers/books';
66
import cn from 'classnames';
77
import './book-checkbox.scss';
88

9-
export default function BookCheckbox({book, name, checked, toggle, disabled}: {
9+
export default function BookCheckbox({
10+
book,
11+
name,
12+
checked,
13+
toggle,
14+
disabled
15+
}: {
1016
book: SalesforceBook;
11-
name: string;
17+
name?: string;
1218
checked: boolean;
1319
toggle: (b: SalesforceBook) => void;
1420
disabled?: boolean;
@@ -36,6 +42,7 @@ export default function BookCheckbox({book, name, checked, toggle, disabled}: {
3642
className="indicator"
3743
tabIndex={disabled ? -1 : 0}
3844
role="checkbox"
45+
aria-label={label}
3946
aria-checked={checked}
4047
aria-disabled={disabled}
4148
onKeyDown={treatSpaceOrEnterAsClick}

src/app/components/book-selector/book-selector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Subject({
1818
}: {
1919
subject: string;
2020
books: SalesforceBook[];
21-
name: string;
21+
name?: string;
2222
selectedBooks: SalesforceBook[];
2323
toggleBook: (b: SalesforceBook) => void;
2424
limitReached: boolean;
@@ -64,12 +64,12 @@ const defaultIncludeFilter = () => true;
6464

6565
type PropsFromOutside = {
6666
prompt: string;
67-
name: string;
67+
name?: string;
6868
selectedBooks: SalesforceBook[];
6969
toggleBook: (b: SalesforceBook) => void;
7070
limit?: number;
7171
additionalInstructions?: string;
72-
includeFilter?: () => boolean;
72+
includeFilter?: (b: SalesforceBook) => boolean;
7373
};
7474

7575
type Books = Parameters<typeof salesforceTitles>[0]

src/app/components/form-input/form-input.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export default function FormInput({
152152
inputProps,
153153
suggestions
154154
}: {
155-
label: string;
155+
label?: string;
156156
longLabel?: string;
157157
inputProps: InputProps;
158158
suggestions?: string[];
@@ -211,7 +211,11 @@ export default function FormInput({
211211
return (
212212
<label className="form-input">
213213
<div className="control-group">
214-
{label && <label className="field-label" htmlFor={id}>{label}</label>}
214+
{label && (
215+
<label className="field-label" htmlFor={id}>
216+
{label}
217+
</label>
218+
)}
215219
{longLabel && (
216220
<label className="field-long-label">{longLabel}</label>
217221
)}

src/app/components/multi-page-form/multi-page-form.tsx

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from 'react';
2-
import usePaginatorContext, {PaginatorContextProvider} from '~/components/paginator/paginator-context';
2+
import usePaginatorContext, {
3+
PaginatorContextProvider
4+
} from '~/components/paginator/paginator-context';
35
import usePagesContext, {PagesContextProvider} from './pages-context';
46
import {FormattedMessage} from 'react-intl';
57
import ButtonRow from './buttons';
@@ -13,24 +15,22 @@ function MarkupChildren({children}: {children: React.ReactNode[]}) {
1315
const {isVisible} = usePaginatorContext();
1416
const {validatedPages, activeRef} = usePagesContext();
1517

16-
return (
17-
children.map((child, i) => {
18-
const isActive = isVisible(i);
19-
const pageNumber = i + 1;
20-
const isValidated = pageNumber in validatedPages;
18+
return children.map((child, i) => {
19+
const isActive = isVisible(i);
20+
const pageNumber = i + 1;
21+
const isValidated = pageNumber in validatedPages;
2122

22-
return (
23-
<div
24-
className={isValidated ? 'validated' : undefined}
25-
hidden={!isActive}
26-
ref={isActive ? activeRef : null}
27-
key={i}
28-
>
29-
{child}
30-
</div>
31-
);
32-
})
33-
);
23+
return (
24+
<div
25+
className={isValidated ? 'validated' : undefined}
26+
hidden={!isActive}
27+
ref={isActive ? activeRef : null}
28+
key={i}
29+
>
30+
{child}
31+
</div>
32+
);
33+
});
3434
}
3535

3636
function PageCount() {
@@ -39,32 +39,41 @@ function PageCount() {
3939

4040
return (
4141
<div className="page-count">
42-
<FormattedMessage id="form.step-of" values={{current: currentPage, total: pages}} />
42+
<FormattedMessage
43+
id="form.step-of"
44+
values={{current: currentPage, total: pages}}
45+
/>
4346
</div>
4447
);
4548
}
4649

4750
type MultiPageFormProps = {
4851
children: React.ReactNode[];
49-
validatePage?: (p: unknown) => boolean;
50-
onPageChange?: (p: unknown) => boolean;
52+
validatePage?: (p: number) => boolean;
53+
onPageChange?: (p: number) => void;
5154
onSubmit: (form: HTMLFormElement) => void;
5255
submitting: boolean;
5356
// onSubmit is redefined above to be simpler
5457
} & Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onSubmit'>;
5558

5659
function MultiPageFormInContext({
5760
children,
58-
validatePage=pass, onPageChange=pass, onSubmit,
59-
submitting, ...formParams
61+
validatePage = pass,
62+
onPageChange = pass,
63+
onSubmit,
64+
submitting,
65+
...formParams
6066
}: MultiPageFormProps) {
6167
const formRef = React.useRef<HTMLFormElement>(null);
6268

6369
return (
6470
<div className="multi-page-form">
6571
<form
66-
acceptCharset="UTF-8" className="form"
67-
method="post" ref={formRef} {...formParams}
72+
acceptCharset="UTF-8"
73+
className="form"
74+
method="post"
75+
ref={formRef}
76+
{...formParams}
6877
aria-label="form"
6978
>
7079
<PagesContextProvider
@@ -76,10 +85,9 @@ function MultiPageFormInContext({
7685
>
7786
<MarkupChildren children={children} />
7887
<PageCount />
79-
{
80-
submitting &&
81-
<div className="big-message">Submitting...</div>
82-
}
88+
{submitting && (
89+
<div className="big-message">Submitting...</div>
90+
)}
8391
<ButtonRow disabled={submitting} {...{formRef, onSubmit}} />
8492
</PagesContextProvider>
8593
</form>

src/app/components/multi-page-form/pages-context.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ import {useState, useRef, useEffect, useCallback} from 'react';
22
import usePaginatorContext from '~/components/paginator/paginator-context';
33
import buildContext from '~/components/jsx-helpers/build-context';
44

5-
function useContextValue({pages, validatePage, onPageChange}: {
5+
function useContextValue({
6+
pages,
7+
validatePage,
8+
onPageChange
9+
}: {
610
pages: number;
7-
validatePage: (p: unknown) => boolean;
8-
onPageChange: (p: unknown) => void;
11+
validatePage: (p: number) => boolean;
12+
onPageChange: (p: number) => void;
913
}) {
1014
const [validatedPages, setValidatedPages] = useState({});
1115
const activeRef = useRef<HTMLDivElement>(null);
1216
const {currentPage} = usePaginatorContext();
13-
const validateCurrentPage = useCallback(
14-
() => {
15-
const invalid = activeRef.current?.querySelector(':invalid');
17+
const validateCurrentPage = useCallback(() => {
18+
const invalid = activeRef.current?.querySelector(':invalid');
1619

17-
setValidatedPages({[currentPage]: true, ...validatedPages});
18-
return invalid === null && validatePage(currentPage);
19-
},
20-
[currentPage, validatedPages, validatePage]
21-
);
20+
setValidatedPages({[currentPage]: true, ...validatedPages});
21+
return invalid === null && validatePage(currentPage);
22+
}, [currentPage, validatedPages, validatePage]);
2223

2324
useEffect(() => {
2425
onPageChange(currentPage);
@@ -29,7 +30,4 @@ function useContextValue({pages, validatePage, onPageChange}: {
2930

3031
const {useContext, ContextProvider} = buildContext({useContextValue});
3132

32-
export {
33-
useContext as default,
34-
ContextProvider as PagesContextProvider
35-
};
33+
export {useContext as default, ContextProvider as PagesContextProvider};

src/app/helpers/use-document-head.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ export default function useDocumentHead({
151151
noindex = false
152152
}: {
153153
title?: string;
154-
description?: string;
154+
description?: string | null;
155155
noindex?: boolean;
156156
}) {
157157
useEffect(() => {
158-
setPageTitleAndDescription(title, description);
158+
setPageTitleAndDescription(title, description ?? undefined);
159159
}, [title, description]);
160160

161161
useEffect(() => {

0 commit comments

Comments
 (0)