Skip to content

Commit 53b0d8e

Browse files
kylemhdavidvicos1
authored andcommitted
Merge branch 'migrate-forms-typescript' of github.com:OperationCode/front-end into migrate-forms-typescript
2 parents b1a84bd + 1119ba1 commit 53b0d8e

11 files changed

Lines changed: 437 additions & 530 deletions

File tree

‎components/Form/Checkbox/Checkbox.tsx‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
import classNames from 'classnames';
2-
import { ErrorMessage } from 'formik';
2+
import { ErrorMessage, FieldProps } from 'formik';
33
import { CHECKBOX, CHECKBOX_ERROR } from 'common/constants/testIDs';
44
import Alert from 'components/Alert/Alert';
55
import Label from 'components/Form/Label/Label';
66
import styles from './Checkbox.module.css';
77

8-
export interface CheckboxPropsType {
8+
export interface CheckboxPropsType extends FieldProps {
99
/**
1010
* Applies a label that to the form input.
1111
*/
1212
label: React.ReactNode | string;
1313
/**
1414
* Sets the name and value for the input element.
1515
*/
16-
field: {
17-
name: string;
18-
value?: string;
19-
};
20-
form: {
21-
touched: Record<string, any>;
22-
errors?: Record<string, string>;
23-
};
2416
/**
2517
* Passes an idea to the root input element.
2618
*/

‎components/Form/Input/Input.tsx‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames';
2-
import { ErrorMessage } from 'formik';
2+
import { ErrorMessage, FieldProps } from 'formik';
33
import { INPUT, INPUT_ERROR, INPUT_FEEDBACK_GROUPING } from 'common/constants/testIDs';
44
import Alert from 'components/Alert/Alert';
55
import Label from 'components/Form/Label/Label';
@@ -36,14 +36,6 @@ export type InputPropsType = {
3636
/**
3737
* Sets the name and value for the input element.
3838
*/
39-
field: {
40-
name: string;
41-
value?: string;
42-
};
43-
form: {
44-
touched: Record<string, any>;
45-
errors?: Record<string, string>;
46-
};
4739
/**
4840
* Passes the input type to the base input element.
4941
* @default 'text'
@@ -67,7 +59,7 @@ export type InputPropsType = {
6759
* @default true
6860
*/
6961
hasValidationStyling?: boolean;
70-
};
62+
} & FieldProps;
7163

7264
function Input({
7365
className,

‎components/Form/Select/Select.tsx‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
1-
import { ErrorMessage } from 'formik';
1+
import { ErrorMessage, FieldProps } from 'formik';
22
import Alert from 'components/Alert/Alert';
33
import Label from 'components/Form/Label/Label';
44
import ThemedReactSelect from './ThemedReactSelect';
55
import styles from './Select.module.css';
66

7-
type FieldType = {
8-
name: string;
9-
value: string | string[] | number | number[] | boolean | boolean[];
10-
};
11-
12-
type TouchedType = Record<string, any>;
13-
14-
type ErrorsType = {
15-
[key: string]: string;
16-
};
17-
18-
type FormType = {
19-
touched: TouchedType;
20-
errors: ErrorsType;
21-
setFieldTouched: (name: string) => void;
22-
setFieldValue: (name: string, value: string | string[]) => void;
23-
};
24-
257
type SelectOptionType = {
268
label: string;
279
value: string;
@@ -30,16 +12,14 @@ type SelectOptionType = {
3012
type SelectOptionsType = SelectOptionType[];
3113

3214
export type SelectPropsType = {
33-
field: FieldType;
34-
form: FormType;
3515
options: SelectOptionsType;
3616
label: string;
3717
hasValidationStyling?: boolean;
3818
id?: string;
3919
isLabelHidden?: boolean;
4020
isMulti?: boolean;
4121
isSearchable?: boolean;
42-
};
22+
} & FieldProps;
4323

4424
export default function Select({
4525
field: { name, value: fieldValue },

‎components/Form/Select/ThemedReactSelect.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// eslint-disable-next-line no-restricted-imports
22
import ReactSelect from 'react-select'; // the only spot this import is allowed
3+
import { FormikTouched } from 'formik';
34
import {
45
primary,
56
rgbValuesPrimary,
@@ -16,6 +17,8 @@ type OptionsType = OptionType[];
1617

1718
type ValueType = string | OptionType | OptionsType;
1819

20+
type TouchedType = FormikTouched<any> | FormikTouched<any>[] | boolean;
21+
1922
export type ThemedReactSelect = {
2023
options: OptionsType;
2124
disabled?: boolean;
@@ -25,7 +28,7 @@ export type ThemedReactSelect = {
2528
instanceId?: string;
2629
isMulti?: boolean;
2730
isSearchable?: boolean;
28-
isTouched?: any[] | boolean;
31+
isTouched?: TouchedType;
2932
name?: string;
3033
onBlur?: () => void;
3134
onChange?: (selected: any) => void;

0 commit comments

Comments
 (0)