Skip to content

Commit

Permalink
fruit name field
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Aug 16, 2024
1 parent 9db630c commit 354bcc7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
19 changes: 19 additions & 0 deletions src/components/FruitNameField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { TextField, type TextFieldProps } from "codeforlife/components/form"
import { type FC } from "react"

import { fruitNameSchema } from "../app/schemas"

export interface FruitNameFieldProps
extends Omit<TextFieldProps, "name" | "label" | "placeholder" | "schema"> {}

const FruitNameField: FC<FruitNameFieldProps> = props => (
<TextField
name="name"
label="Name"
placeholder="Enter the fruit's name"
schema={fruitNameSchema}
{...props}
/>
)

export default FruitNameField
2 changes: 2 additions & 0 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as FruitNameField } from "./FruitNameField"
export * from "./FruitNameField"
9 changes: 2 additions & 7 deletions src/pages/fruitDetail/FruitDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
useLazyRetrieveFruitQuery,
useUpdateFruitMutation,
} from "../../api/fruit"
import { fruitNameSchema } from "../../app/schemas"
import { FruitNameField } from "../../components"
import { paths } from "../../routes"

export interface FruitDetailProps {}
Expand All @@ -38,12 +38,7 @@ const FruitDetail: FC<FruitDetailProps> = () => {
})}
>
<Stack>
<forms.TextField
name="name"
label="Name"
placeholder="Enter the fruit's name"
schema={fruitNameSchema}
/>
<FruitNameField />
<forms.CheckboxField
name="is_citrus"
formControlLabelProps={{ label: "Is Citrus" }}
Expand Down
10 changes: 2 additions & 8 deletions src/pages/fruitList/CreateFruitForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormHelperText, Stack } from "@mui/material"
import { type FC } from "react"
import { submitForm } from "codeforlife/utils/form"

import { fruitNameSchema } from "../../app/schemas"
import { FruitNameField } from "../../components"
import { useCreateFruitMutation } from "../../api/fruit"

export interface CreateFruitFormProps {}
Expand All @@ -25,13 +25,7 @@ const CreateFruitForm: FC<CreateFruitFormProps> = () => {
})}
>
<Stack>
<forms.TextField
required
name="name"
label="Name"
placeholder="Enter the fruit's name"
schema={fruitNameSchema}
/>
<FruitNameField />
<forms.CheckboxField
name="is_citrus"
formControlLabelProps={{ label: "Is Citrus" }}
Expand Down

0 comments on commit 354bcc7

Please sign in to comment.