Skip to content

fix: UX issues in template settings form's default auto-stop field #5330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Override label through Yup instead
  • Loading branch information
presleyp committed Dec 6, 2022
commit 8fd2a7a4b9b945b0ebe33260642e0e46a532434b
14 changes: 3 additions & 11 deletions site/src/util/formUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ interface FormHelpers {

export const getFormHelpers =
<T>(form: FormikContextType<T>, error?: Error | unknown) =>
(
name: keyof T,
HelperText: ReactNode = "",
friendlyLabel?: string,
): FormHelpers => {
(name: keyof T, HelperText: ReactNode = ""): FormHelpers => {
const apiValidationErrors =
isApiError(error) && hasApiFieldErrors(error)
? (mapApiErrorToFieldErrors(error.response.data) as FormikErrors<T>)
Expand All @@ -60,15 +56,11 @@ export const getFormHelpers =
const apiError = getIn(apiValidationErrors, name)
const frontendError = getIn(form.errors, name)
const returnError = apiError ?? frontendError
const friendlyError =
friendlyLabel && returnError
? returnError.replace(name, friendlyLabel)
: returnError
return {
...form.getFieldProps(name),
id: name,
error: touched && Boolean(friendlyError),
helperText: touched ? friendlyError || HelperText : HelperText,
error: touched && Boolean(returnError),
helperText: touched ? returnError || HelperText : HelperText,
}
}

Expand Down