Skip to content

Commit 709f6dc

Browse files
committed
Fix search character form
1 parent a9f16a9 commit 709f6dc

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/pages/character/index.tsx

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
import Panel from "src/components/Panel";
22
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";
69

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+
});
1613

1714
export default function Character() {
15+
const {
16+
register,
17+
handleSubmit,
18+
formState: { errors },
19+
} = useForm<z.infer<typeof schema>>({
20+
resolver: zodResolver(schema),
21+
});
1822
const router = useRouter();
1923

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}`);
2226
};
2327

2428
return (
2529
<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>
2739
</Panel>
2840
);
2941
}

0 commit comments

Comments
 (0)