Skip to content

Commit e95d75f

Browse files
committed
Remove and consolidate form ty pes
1 parent ffac475 commit e95d75f

File tree

6 files changed

+49
-887
lines changed

6 files changed

+49
-887
lines changed

site/components/Form/FormTextField.tsx

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
import TextField, { TextFieldProps } from "@material-ui/core/TextField"
2-
import { FormikLike } from "../../util/formik"
2+
import { FormikContextType as FormikLike } from "formik"
33
import React from "react"
44
import { PasswordField } from "./PasswordField"
5-
import { FormFieldProps } from "./types"
5+
6+
/**
7+
* FormFieldProps are required props for creating form fields using a factory.
8+
*/
9+
export interface FormFieldProps<T> {
10+
/**
11+
* form is a reference to a form or subform and is used to compute common
12+
* states such as error and helper text
13+
*/
14+
form: FormikLike<T>
15+
/**
16+
* formFieldName is a field name associated with the form schema.
17+
*/
18+
formFieldName: keyof T
19+
}
20+
621

722
/**
823
* FormTextFieldProps extends form-related MUI TextFieldProps with Formik
@@ -12,31 +27,31 @@ import { FormFieldProps } from "./types"
1227
*/
1328
export interface FormTextFieldProps<T>
1429
extends Pick<
15-
TextFieldProps,
16-
| "autoComplete"
17-
| "autoFocus"
18-
| "children"
19-
| "className"
20-
| "disabled"
21-
| "fullWidth"
22-
| "helperText"
23-
| "id"
24-
| "InputLabelProps"
25-
| "InputProps"
26-
| "inputProps"
27-
| "label"
28-
| "margin"
29-
| "multiline"
30-
| "onChange"
31-
| "placeholder"
32-
| "required"
33-
| "rows"
34-
| "select"
35-
| "SelectProps"
36-
| "style"
37-
| "type"
38-
>,
39-
FormFieldProps<T> {
30+
TextFieldProps,
31+
| "autoComplete"
32+
| "autoFocus"
33+
| "children"
34+
| "className"
35+
| "disabled"
36+
| "fullWidth"
37+
| "helperText"
38+
| "id"
39+
| "InputLabelProps"
40+
| "InputProps"
41+
| "inputProps"
42+
| "label"
43+
| "margin"
44+
| "multiline"
45+
| "onChange"
46+
| "placeholder"
47+
| "required"
48+
| "rows"
49+
| "select"
50+
| "SelectProps"
51+
| "style"
52+
| "type"
53+
>,
54+
FormFieldProps<T> {
4055
/**
4156
* eventTransform is an optional transformer on the event data before it is
4257
* processed by formik.
@@ -105,9 +120,9 @@ export const formTextFieldFactory = <T,>(): React.FC<FormTextFieldProps<T>> => {
105120
}) => {
106121
const isError = form.touched[formFieldName] && Boolean(form.errors[formFieldName])
107122

108-
// Conversion to a string primitive is necessary as formFieldName is an in
109-
// indexable type such as a string, number or enum.
110-
const fieldId = FormikLike.getFieldId<T>(form, String(formFieldName))
123+
// TODO: When we need to bring back FormikLike / subforms, use
124+
// the `FormikLike.getFieldId` helper.
125+
const fieldId = String(formFieldName)
111126

112127
const Component = isPassword ? PasswordField : TextField
113128
const inputType = isPassword ? undefined : type

site/components/Form/types.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

site/pages/workspaces/create/[projectId].tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react"
22
import { useRouter } from "next/router"
3-
import { useFormik } from "formik"
4-
import { firstOrOnly, subForm, FormikLike } from "./../../../util"
3+
import { useFormik, FormikContext } from "formik"
4+
import { firstOrOnly } from "./../../../util"
55
import * as API from "../../../api"
66
import { FormPage, FormButton } from "../../../components/PageTemplates"
77
import { useRequestor } from "../../../hooks/useRequestor"
@@ -66,8 +66,6 @@ const CreateProjectPage: React.FC = () => {
6666
},
6767
})
6868

69-
const parametersForm: FormikLike<Record<string, string>> = subForm(form, "parameters")
70-
7169
const cancel = () => {
7270
router.push(`/workspaces/create`)
7371
}
@@ -126,8 +124,8 @@ const CreateProjectPage: React.FC = () => {
126124
return (
127125
<FormRow>
128126
<ParameterTextField
129-
form={parametersForm}
130-
formFieldName={param.id}
127+
form={form}
128+
formFieldName={"parameters." + param.id}
131129
fullWidth
132130
label={param.name}
133131
helperText={param.description}

0 commit comments

Comments
 (0)