Skip to content

Commit 1158645

Browse files
committed
handle formErrors
1 parent 7a14859 commit 1158645

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

site/src/components/WorkspaceStats/WorkspaceScheduleForm.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import TextField from "@material-ui/core/TextField"
99
import { useFormik } from "formik"
1010
import React from "react"
1111
import * as Yup from "yup"
12+
import { FieldErrors } from "../../api/errors"
1213
import { getFormHelpers } from "../../util/formUtils"
1314
import { FormFooter } from "../FormFooter/FormFooter"
1415
import { FullPageForm } from "../FullPageForm/FullPageForm"
@@ -32,6 +33,7 @@ export const Language = {
3233
}
3334

3435
export interface WorkspaceScheduleFormProps {
36+
fieldErrors?: FieldErrors
3537
isLoading: boolean
3638
onCancel: () => void
3739
onSubmit: (values: WorkspaceScheduleFormValues) => void
@@ -92,7 +94,12 @@ export const validationSchema = Yup.object({
9294
ttl: Yup.number().min(0).integer(),
9395
})
9496

95-
export const WorkspaceScheduleForm: React.FC<WorkspaceScheduleFormProps> = ({ isLoading, onCancel, onSubmit }) => {
97+
export const WorkspaceScheduleForm: React.FC<WorkspaceScheduleFormProps> = ({
98+
fieldErrors,
99+
isLoading,
100+
onCancel,
101+
onSubmit,
102+
}) => {
96103
const styles = useStyles()
97104

98105
const form = useFormik<WorkspaceScheduleFormValues>({
@@ -111,7 +118,7 @@ export const WorkspaceScheduleForm: React.FC<WorkspaceScheduleFormProps> = ({ is
111118
onSubmit,
112119
validationSchema,
113120
})
114-
const formHelpers = getFormHelpers<WorkspaceScheduleFormValues>(form)
121+
const formHelpers = getFormHelpers<WorkspaceScheduleFormValues>(form, fieldErrors)
115122

116123
const checkboxes: Array<{ value: boolean; name: string; label: string }> = [
117124
{ value: form.values.sunday, name: "sunday", label: Language.daySundayLabel },

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,12 @@ export const formValuesToTTLRequest = (values: WorkspaceScheduleFormValues): Typ
7878
}
7979
}
8080

81-
// TODO(Grey): React testing library for this
8281
export const WorkspaceSchedulePage: React.FC = () => {
8382
const navigate = useNavigate()
8483
const { workspace: workspaceQueryParam } = useParams()
8584
const workspaceId = firstOrItem(workspaceQueryParam, null)
86-
87-
// TODO(Grey): Consume the formSubmissionErrors in WorkspaceScheduleForm
8885
const [scheduleState, scheduleSend] = useMachine(workspaceSchedule)
89-
const { getWorkspaceError, workspace } = scheduleState.context
86+
const { formErrors, getWorkspaceError, workspace } = scheduleState.context
9087

9188
// Get workspace on mount and whenever workspaceId changes.
9289
// scheduleSend should not change.
@@ -104,6 +101,7 @@ export const WorkspaceSchedulePage: React.FC = () => {
104101
} else {
105102
return (
106103
<WorkspaceScheduleForm
104+
fieldErrors={formErrors}
107105
isLoading={scheduleState.tags.has("loading")}
108106
onCancel={() => {
109107
navigate(`/workspaces/${workspaceId}`)

0 commit comments

Comments
 (0)