-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from IgorDuino/dev
registration
- Loading branch information
Showing
4 changed files
with
113 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { useRouter } from "next/navigation"; | ||
import { registeration } from "@/lib/api/api"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { Input } from "@/components/ui/input"; | ||
import { Label } from "@/components/ui/label"; | ||
|
||
export default function RegistrationForm() { | ||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [password2, setPassword2] = useState(""); | ||
const [loading, setLoading] = useState(false); | ||
const [error, setError] = useState(""); | ||
const router = useRouter(); | ||
|
||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
setLoading(true); | ||
|
||
try { | ||
const response = await registeration(username, password, password2); | ||
if (response.status == 204) { | ||
router.push("/auth"); | ||
} else { | ||
setError(`Error: ${await response.text()}`); | ||
} | ||
} catch (error) { | ||
setError(error as string); | ||
console.log(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="container py-24 lg:py-32"> | ||
<Card className="mx-auto max-w-sm"> | ||
<CardHeader> | ||
<CardTitle className="text-2xl">Registration</CardTitle> | ||
<CardDescription> | ||
Enter your name and come up with a password | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<form onSubmit={handleSubmit} className="grid gap-4"> | ||
<div className="grid gap-2"> | ||
<Label htmlFor="username">Username</Label> | ||
<Input | ||
id="username" | ||
placeholder="Username" | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
required | ||
/> | ||
</div> | ||
<div className="grid gap-2"> | ||
<div className="flex items-center"> | ||
<Label htmlFor="password">Password</Label> | ||
</div> | ||
<Input | ||
id="password" | ||
type="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
required | ||
/> | ||
</div> | ||
<div className="grid gap-2"> | ||
<div className="flex items-center"> | ||
<Label htmlFor="password">Password repeat</Label> | ||
</div> | ||
<Input | ||
id="password" | ||
type="password" | ||
value={password2} | ||
onChange={(e) => setPassword2(e.target.value)} | ||
required | ||
/> | ||
</div> | ||
{error && <p className="text-sm text-red-500">{error}</p>} | ||
<Button variant="action" className="w-full" disabled={loading}> | ||
{loading ? "Loading..." : "Sign Up"} | ||
</Button> | ||
</form> | ||
</CardContent> | ||
</Card> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters