From 646c1168349643eb01db53b5e06bf986a16b86d7 Mon Sep 17 00:00:00 2001 From: l3wdfut4pwr Date: Tue, 17 Mar 2026 14:06:58 +0200 Subject: simple registration prototype --- src/components/header/authdialog/RegisterForm.tsx | 115 ++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/components/header/authdialog/RegisterForm.tsx (limited to 'src/components/header/authdialog/RegisterForm.tsx') diff --git a/src/components/header/authdialog/RegisterForm.tsx b/src/components/header/authdialog/RegisterForm.tsx new file mode 100644 index 0000000..20a7c14 --- /dev/null +++ b/src/components/header/authdialog/RegisterForm.tsx @@ -0,0 +1,115 @@ +'use client'; +import { useState } from 'react'; +import { Button } from '@/components/ui/button'; +import GoogleIcon from '../../../../public/icons/google.svg'; +import { InputField } from '@/components/ui/inputfield'; +import { validate, registerUser } from './register'; +import { useAuthContext } from '@/lib/contexts/Auth.context'; + +export default function RegisterForm() { + const [errors, setErrors] = useState({}); + const [loading, setLoading] = useState(false); + const { setUser } = useAuthContext(); + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setLoading(true); + setErrors({}); + + const formData = new FormData(e.currentTarget); + const username = formData.get('username')?.toString() || ''; + const email = formData.get('email')?.toString() || ''; + const password = formData.get('password')?.toString() || ''; + const passwordConfirm = + formData.get('passwordConfirm')?.toString() || ''; + + const validationErrors = validate( + username, + email, + password, + passwordConfirm, + ); + + if (Object.keys(validationErrors).length > 0) { + setErrors(validationErrors); + setLoading(false); + return; + } + + const { data, error } = await registerUser(username, email, password); + + if (error) { + setErrors(error); + } else if (data) { + setUser({ + id: data.id, + username: data.username, + }); + } + + setLoading(false); + }; + + return ( +
+ + +
+
+ + {errors.username && ( +

+ {errors.username} +

+ )} +
+ +
+ + {errors.email && ( +

+ {errors.email} +

+ )} +
+ +
+ + {errors.password && ( +

+ {errors.password} +

+ )} +
+ +
+ + {errors.passwordConfirm && ( +

+ {errors.passwordConfirm} +

+ )} +
+
+ + {errors.general &&

{errors.general}

} + + +
+ ); +} -- cgit v1.3-3-g829e