diff --git a/apps/console/src/pages/auth/RegisterPage.tsx b/apps/console/src/pages/auth/RegisterPage.tsx new file mode 100644 index 000000000..50f3ece26 --- /dev/null +++ b/apps/console/src/pages/auth/RegisterPage.tsx @@ -0,0 +1,144 @@ +import { useState } from "react"; +import { Link, useNavigate } from "react-router"; +import { Button, Field, useToast } from "@probo/ui"; +import { useTranslate } from "@probo/i18n"; +import { useMutation } from "@tanstack/react-query"; + +interface RegisterData { + email: string; + password: string; + fullName: string; +} + +export default function RegisterPage() { + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [fullName, setFullName] = useState(""); + const { __ } = useTranslate(); + const { toast } = useToast(); + const navigate = useNavigate(); + + const registerUser = async (data: RegisterData) => { + const response = await fetch( + `${import.meta.env.VITE_API_URL}/api/console/v1/auth/register`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + credentials: "include", + body: JSON.stringify(data), + } + ); + + if (!response.ok) { + const errorData = await response.json().catch(() => ({})); + return { success: false, error: errorData.message || __("Registration failed") }; + } + + return { success: true, data: await response.json() }; + }; + + const registerMutation = useMutation({ + mutationFn: registerUser, + onSuccess: (result) => { + if (result.success) { + toast({ + title: __("Success"), + description: __("Account created successfully"), + variant: "success", + }); + navigate("/", { replace: true }); + } else { + toast({ + title: __("Error"), + description: result.error, + variant: "error", + }); + } + }, + onError: () => { + toast({ + title: __("Error"), + description: __("Registration failed"), + variant: "error", + }); + }, + }); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + if (!email || !password || !fullName) { + toast({ + title: __("Error"), + description: __("Full name, email, and password are required"), + variant: "error", + }); + return; + } + + registerMutation.mutate({ + email, + password, + fullName, + }); + }; + + return ( + <> +
+ {__("Enter your information to create an account")} +
++ {__("Already have an account?")}{" "} + + {__("Log in here")} + +
+