feat: add character creation page components and hooks
Co-authored-by: aider (ollama/qwen2.5-coder:7b) <aider@aider.chat>
This commit is contained in:
@@ -1,10 +1,16 @@
|
|||||||
import MenuButton from "@/components/MenuButton";
|
import MenuButton from "@/components/MenuButton";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-screen">
|
<div className="flex flex-col h-screen">
|
||||||
<main className="flex-1 flex flex-col items-center justify-center gap-6">
|
<main className="flex-1 flex flex-col items-center justify-center gap-6">
|
||||||
<MenuButton text="Characters" url="/characters" />
|
<MenuButton text="Characters" url="/characters" />
|
||||||
|
<Link href="/create-character">
|
||||||
|
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||||
|
Create Character
|
||||||
|
</button>
|
||||||
|
</Link>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { useCharacterForm } from "@/hooks/useCharacterForm";
|
||||||
|
|
||||||
|
const CharacterForm: React.FC = () => {
|
||||||
|
const { handleSubmit, register, errors } = useCharacterForm();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="name">Name:</label>
|
||||||
|
<input
|
||||||
|
id="name"
|
||||||
|
name="name"
|
||||||
|
ref={register({ required: true })}
|
||||||
|
className={`border p-2 ${errors.name ? "border-red-500" : ""}`}
|
||||||
|
/>
|
||||||
|
{errors.name && <span className="text-red-500">This field is required</span>}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="species">Species:</label>
|
||||||
|
<select id="species" name="species" ref={register}>
|
||||||
|
<option value="">Select a species</option>
|
||||||
|
{/* Add options for different species */}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="class">Class:</label>
|
||||||
|
<select id="class" name="class" ref={register}>
|
||||||
|
<option value="">Select a class</option>
|
||||||
|
{/* Add options for different classes */}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||||
|
Create Character
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CharacterForm;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
const ClassSelector: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2>Classes</h2>
|
||||||
|
{/* Add logic to display and select classes */}
|
||||||
|
{/* Allow users to add custom class entries */}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ClassSelector;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
const SpeciesSelector: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2>Species</h2>
|
||||||
|
{/* Add logic to display and select species */}
|
||||||
|
{/* Allow users to add custom species entries */}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SpeciesSelector;
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
|
||||||
|
const useCharacterForm = () => {
|
||||||
|
const { register, handleSubmit, errors } = useForm();
|
||||||
|
|
||||||
|
const onSubmit = (data: any) => {
|
||||||
|
console.log(data);
|
||||||
|
// Handle form submission logic here
|
||||||
|
};
|
||||||
|
|
||||||
|
return { register, handleSubmit, errors };
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useCharacterForm;
|
||||||
Reference in New Issue
Block a user