diff --git a/src/pages/account/createcharacter.tsx b/src/pages/account/createcharacter.tsx index 0c86723..5befccd 100644 --- a/src/pages/account/createcharacter.tsx +++ b/src/pages/account/createcharacter.tsx @@ -1,18 +1,17 @@ -import React from "react"; -import Panel from "../../components/Panel"; -import { withSessionSsr } from "../../lib/session"; -import { Select, Text, Container, VStack, Wrap } from "@chakra-ui/react"; +import { withSessionSsr } from "@lib/session"; +import { Select, Text, VStack } from "@chakra-ui/react"; import TextInput from "@component/TextInput"; import Button from "@component/Button"; import { FormField } from "@component/FormField"; import { z } from "zod"; -import { useForm } from "react-hook-form"; +import { useForm, SubmitHandler } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; -import { SubmitHandler } from "react-hook-form"; -import { Vocation } from "@shared/enums/Vocation"; +import { getVocationNames, getVocationByName } from "@shared/enums/Vocation"; import { trpc } from "@util/trpc"; import { useFormFeedback } from "@hook/useFormFeedback"; -import { Sex } from "@shared/enums/Sex"; +import { getSexNames, getSexByName } from "@shared/enums/Sex"; +import { Content } from "@component/Content"; +import { useRouter } from "next/router"; const bannedSequences = ["tutor", "cancer", "suck", "sux", "fuck"]; const bannedWords = ["gm", "cm", "god"]; @@ -49,8 +48,8 @@ const schema = z.object({ }, { message: "Contains illegal words" }, ), - vocation: z.nativeEnum(Vocation), - sex: z.nativeEnum(Sex), + vocation: z.enum(getVocationNames() as any).transform((val) => getVocationByName(val)), + sex: z.enum(getSexNames() as any).transform((val) => getSexByName(val)), }); export default function CreateCharacter() { @@ -64,32 +63,35 @@ export default function CreateCharacter() { }); const createCharacter = trpc.account.createCharacter.useMutation(); const { handleResponse, showResponse } = useFormFeedback(); + const router = useRouter(); const onSubmit: SubmitHandler> = async ({ name, vocation, sex }) => { handleResponse(async () => { await createCharacter.mutateAsync({ name, vocation, sex }); showResponse("Character created.", "success"); + router.push("/account"); }); reset(); }; return ( - - - Please choose a name, vocation and sex for your character.
- In any case the name must not violate the naming conventions stated in the Rules or your character might get deleted or name locked. -
-
- - + + Create Character + + + Please choose a name, vocation and sex for your character.
+ In any case the name must not violate the naming conventions stated in the Rules or your character might get deleted or name locked. +
+ + - {Object.entries(Sex).map(([key, value]) => ( - ))} - -