|
1 | 1 | import Panel from "src/components/Panel";
|
2 | 2 | import { useRouter } from "next/router";
|
3 |
| -import FormWrapper, { FormField } from "src/components/FormWrapper"; |
4 |
| -import { searchCharacterSchema } from "src/schemas/SearchCharacter"; |
5 |
| -import { FormButton } from "../community/guilds"; |
| 3 | +import { SubmitHandler, useForm } from "react-hook-form"; |
| 4 | +import { z } from "zod"; |
| 5 | +import { zodResolver } from "@hookform/resolvers/zod"; |
| 6 | +import { Container, VStack } from "@chakra-ui/react"; |
| 7 | +import TextInput from "@component/TextInput"; |
| 8 | +import { FormField } from "@component/FormField"; |
6 | 9 |
|
7 |
| -const fields: FormField[] = [ |
8 |
| - { |
9 |
| - type: "text", |
10 |
| - name: "name", |
11 |
| - label: { text: "Character Name" }, |
12 |
| - }, |
13 |
| -]; |
14 |
| - |
15 |
| -const buttons: FormButton[] = [{ type: "submit", btnType: "primary", value: "Submit" }]; |
| 10 | +const schema = z.object({ |
| 11 | + name: z.string(), |
| 12 | +}); |
16 | 13 |
|
17 | 14 | export default function Character() {
|
| 15 | + const { |
| 16 | + register, |
| 17 | + handleSubmit, |
| 18 | + formState: { errors }, |
| 19 | + } = useForm<z.infer<typeof schema>>({ |
| 20 | + resolver: zodResolver(schema), |
| 21 | + }); |
18 | 22 | const router = useRouter();
|
19 | 23 |
|
20 |
| - const onSubmit = async (values: any) => { |
21 |
| - router.push(`/character/${values.name}`); |
| 24 | + const onSubmit: SubmitHandler<z.infer<typeof schema>> = async ({ name }) => { |
| 25 | + router.push(`/character/${name}`); |
22 | 26 | };
|
23 | 27 |
|
24 | 28 | return (
|
25 | 29 | <Panel header="Search Character">
|
26 |
| - <FormWrapper validationSchema={searchCharacterSchema} onSubmit={onSubmit} fields={fields} buttons={buttons} /> |
| 30 | + <form onSubmit={handleSubmit(onSubmit)}> |
| 31 | + <Container alignContent={"center"} padding={2}> |
| 32 | + <VStack spacing={5}> |
| 33 | + <FormField key={"name"} error={errors.name?.message} name="name" label="name"> |
| 34 | + <TextInput type="submit" {...register("name")} /> |
| 35 | + </FormField> |
| 36 | + </VStack> |
| 37 | + </Container> |
| 38 | + </form> |
27 | 39 | </Panel>
|
28 | 40 | );
|
29 | 41 | }
|
0 commit comments