Skip to content

Commit

Permalink
unify form helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
nl0 committed May 30, 2024
1 parent 3e4b9bc commit 197100b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 63 deletions.
21 changes: 9 additions & 12 deletions catalog/app/containers/Admin/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as React from 'react'
import type * as RF from 'react-final-form'
import * as M from '@material-ui/core'

export interface FieldProps {
interface FieldOwnProps {
errors: Record<string, React.ReactNode>
input: RF.FieldInputProps<string>
meta: RF.FieldMetaState<string>
}

export type FieldProps = FieldOwnProps & RF.FieldRenderProps<string> & M.TextFieldProps

// TODO: re-use components/Form/TextField
export function Field({
input,
Expand All @@ -16,8 +16,9 @@ export function Field({
helperText,
InputLabelProps,
...rest
}: FieldProps & M.TextFieldProps) {
const error = meta.submitFailed && (meta.error || meta.submitError)
}: FieldProps) {
const error =
meta.submitFailed && (meta.error || (!meta.dirtySinceLastSubmit && meta.submitError))
const props = {
error: !!error,
helperText: error ? errors[error] || error : helperText,
Expand Down Expand Up @@ -80,16 +81,12 @@ const useFormErrorStyles = M.makeStyles((t) => ({
},
}))

interface FormErrorProps {
errors: Record<string, React.ReactNode>
interface FormErrorProps extends M.TypographyProps {
error?: string
errors: Record<string, React.ReactNode>
}

export function FormError({
error,
errors,
...rest
}: FormErrorProps & M.TypographyProps) {
export function FormError({ error, errors, ...rest }: FormErrorProps) {
const classes = useFormErrorStyles()
if (!error) return null
return (
Expand Down
49 changes: 0 additions & 49 deletions catalog/app/containers/Admin/RFForm.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion catalog/app/containers/Admin/RolesAndPolicies/Policies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { mkFormError, mapInputErrors } from 'utils/formTools'
import * as Types from 'utils/types'
import validate, * as validators from 'utils/validators'

import * as Form from '../RFForm'
import * as Form from '../Form'
import * as Table from '../Table'

import AssociatedRoles from './AssociatedRoles'
Expand Down
2 changes: 1 addition & 1 deletion catalog/app/containers/Admin/RolesAndPolicies/Roles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import assertNever from 'utils/assertNever'
import * as Types from 'utils/types'
import * as validators from 'utils/validators'

import * as Form from '../RFForm'
import * as Form from '../Form'
import * as Table from '../Table'

import AttachedPolicies from './AttachedPolicies'
Expand Down

0 comments on commit 197100b

Please sign in to comment.