Skip to content

Commit 5e4a44f

Browse files
committed
Revert "Remove and consolidate form ty pes"
This reverts commit e95d75f.
1 parent e5e02f9 commit 5e4a44f

File tree

6 files changed

+875
-7
lines changed

6 files changed

+875
-7
lines changed

site/components/Form/FormTextField.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import TextField, { TextFieldProps } from "@material-ui/core/TextField"
2+
import { FormikLike } from "../../util/formik"
23
import React from "react"
34
import { PasswordField } from "./PasswordField"
4-
import { FormikContextType } from "formik"
55

66
/**
77
* FormFieldProps are required props for creating form fields using a factory.
@@ -11,7 +11,22 @@ export interface FormFieldProps<T> {
1111
* form is a reference to a form or subform and is used to compute common
1212
* states such as error and helper text
1313
*/
14-
form: FormikContextType<T>
14+
form: FormikLike<T>
15+
/**
16+
* formFieldName is a field name associated with the form schema.
17+
*/
18+
formFieldName: keyof T
19+
}
20+
21+
/**
22+
* FormFieldProps are required props for creating form fields using a factory.
23+
*/
24+
export interface FormFieldProps<T> {
25+
/**
26+
* form is a reference to a form or subform and is used to compute common
27+
* states such as error and helper text
28+
*/
29+
form: FormikLike<T>
1530
/**
1631
* formFieldName is a field name associated with the form schema.
1732
*/
@@ -124,7 +139,7 @@ export const formTextFieldFactory = <T,>(): React.FC<FormTextFieldProps<T>> => {
124139

125140
// Conversion to a string primitive is necessary as formFieldName is an in
126141
// indexable type such as a string, number or enum.
127-
const fieldId = String(formFieldName)
142+
const fieldId = FormikLike.getFieldId<T>(form, String(formFieldName))
128143

129144
const Component = isPassword ? PasswordField : TextField
130145
const inputType = isPassword ? undefined : type

site/components/Form/types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { FormikLike } from "../../util/formik"
2+
3+
/**
4+
* FormFieldProps are required props for creating form fields using a factory.
5+
*/
6+
export interface FormFieldProps<T> {
7+
/**
8+
* form is a reference to a form or subform and is used to compute common
9+
* states such as error and helper text
10+
*/
11+
form: FormikLike<T>
12+
/**
13+
* formFieldName is a field name associated with the form schema.
14+
*/
15+
formFieldName: keyof T
16+
}

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

Lines changed: 6 additions & 4 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, FormikContext } from "formik"
4-
import { firstOrOnly } from "./../../../util"
3+
import { useFormik } from "formik"
4+
import { firstOrOnly, subForm, FormikLike } from "./../../../util"
55
import * as API from "../../../api"
66
import { FormPage, FormButton } from "../../../components/PageTemplates"
77
import { useRequestor } from "../../../hooks/useRequestor"
@@ -66,6 +66,8 @@ const CreateProjectPage: React.FC = () => {
6666
},
6767
})
6868

69+
const parametersForm: FormikLike<Record<string, string>> = subForm(form, "parameters")
70+
6971
const cancel = () => {
7072
router.push(`/workspaces/create`)
7173
}
@@ -124,8 +126,8 @@ const CreateProjectPage: React.FC = () => {
124126
return (
125127
<FormRow>
126128
<ParameterTextField
127-
form={form}
128-
formFieldName={"parameters." + param.id}
129+
form={parametersForm}
130+
formFieldName={param.id}
129131
fullWidth
130132
label={param.name}
131133
helperText={param.description}

0 commit comments

Comments
 (0)