diff --git a/src/app/auth/register/page.tsx b/src/app/auth/register/page.tsx index afc95c9..70adca3 100644 --- a/src/app/auth/register/page.tsx +++ b/src/app/auth/register/page.tsx @@ -2,49 +2,73 @@ import { useState } from "react"; import { useRouter } from "next/navigation"; +import Link from "next/link"; import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider"; import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered'; import FooterBase from '@/components/sections/footer/FooterBase'; -import Input from '@/components/form/Input'; -import ButtonDirectionalHover from '@/components/button/ButtonDirectionalHover/ButtonDirectionalHover'; -import { Mail, Lock, User, UserPlus } from 'lucide-react'; +import { Mail, Lock, User, Eye, EyeOff, Check } from 'lucide-react'; export default function RegisterPage() { const router = useRouter(); - const [name, setName] = useState(""); - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); - const [confirmPassword, setConfirmPassword] = useState(""); + const [formData, setFormData] = useState({ + name: "", email: "", password: "", confirmPassword: ""}); + const [showPassword, setShowPassword] = useState(false); + const [showConfirm, setShowConfirm] = useState(false); const [error, setError] = useState(""); - const [isLoading, setIsLoading] = useState(false); + const [loading, setLoading] = useState(false); + const [agreedToTerms, setAgreedToTerms] = useState(false); + + const handleChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFormData((prev) => ({ ...prev, [name]: value })); + }; const handleRegister = async (e: React.FormEvent) => { e.preventDefault(); setError(""); - if (password !== confirmPassword) { - setError("Senhas não correspondem"); + if (!agreedToTerms) { + setError("Você deve concordar com os Termos e Condições"); return; } - setIsLoading(true); + if (formData.password !== formData.confirmPassword) { + setError("As senhas não conferem"); + return; + } + + if (formData.password.length < 8) { + setError("A senha deve ter pelo menos 8 caracteres"); + return; + } + + setLoading(true); try { const response = await fetch("/api/auth/register", { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ name, email, password }), + body: JSON.stringify({ + name: formData.name, + email: formData.email, + password: formData.password, + }), }); if (!response.ok) { const data = await response.json(); - throw new Error(data.message || "Registration failed"); + setError(data.message || "Falha ao registrar"); + return; } - await router.push("/auth/login?registered=true"); - } catch (err: any) { - setError(err.message); + const data = await response.json(); + localStorage.setItem("authToken", data.token); + localStorage.setItem("user", JSON.stringify(data.user)); + router.push("/dashboard"); + } catch (err) { + setError("Erro ao conectar ao servidor"); + console.error(err); } finally { - setIsLoading(false); + setLoading(false); } }; @@ -64,123 +88,144 @@ export default function RegisterPage() { -
+
-
-
-
- -

Registrar

-
-

Crie sua conta FitFlow Pro

-
+
+

Registre-se

+

Comece sua transformação com FitFlow Pro

-
+ {error && ( +
+ {error} +
+ )} + +
- +
- - +
- +
- - +
- +
- - + +
- +
- - + +
- {error && ( -
-

{error}

-
- )} - -
- handleRegister(new Event('submit') as unknown as React.FormEvent)} - disabled={isLoading} - className="flex-1" +
+ setAgreedToTerms(e.target.checked)} + className="mt-1 w-5 h-5 rounded cursor-pointer" /> +
+ + -
-

- Já tem conta?{" "} - - Faça login - -

-
+

+ Já tem uma conta?{" "} + + Faça login aqui + +

@@ -190,16 +235,26 @@ export default function RegisterPage() { columns={[ { title: "Produto", items: [ - { label: "Dashboard", href: "dashboard" }, + { label: "Dashboard", href: "/dashboard" }, { label: "Treino", href: "training" }, { label: "Nutrição", href: "nutrition" }, + { label: "Cardio Hub", href: "cardio" } + ] + }, + { + title: "Comunidade", items: [ + { label: "Comunidade", href: "community" }, + { label: "Perfil", href: "profile" }, + { label: "Rankings", href: "rankings" }, + { label: "Blog", href: "blog" } ] }, { title: "Empresa", items: [ - { label: "Sobre", href: "/" }, + { label: "Sobre", href: "about" }, { label: "Contato", href: "contact" }, { label: "Privacidade", href: "privacy" }, + { label: "Termos", href: "terms" } ] } ]} @@ -209,4 +264,4 @@ export default function RegisterPage() {
); -} +} \ No newline at end of file