From 5ca48a9598cfb6559cc4dc08c8bf517d9388be53 Mon Sep 17 00:00:00 2001 From: Toby Date: Fri, 4 Oct 2024 01:38:06 +0400 Subject: [PATCH] registration page --- packages/client/src/pages/SignUp/SignUp.scss | 6 + packages/client/src/pages/SignUp/SignUp.tsx | 155 ++++++++++--------- packages/client/src/scss/form-mixin.scss | 2 +- 3 files changed, 93 insertions(+), 70 deletions(-) create mode 100644 packages/client/src/pages/SignUp/SignUp.scss diff --git a/packages/client/src/pages/SignUp/SignUp.scss b/packages/client/src/pages/SignUp/SignUp.scss new file mode 100644 index 0000000..aafb05a --- /dev/null +++ b/packages/client/src/pages/SignUp/SignUp.scss @@ -0,0 +1,6 @@ +@import '../../scss/form-mixin'; + +.registration-page { + @include page-background-layout(); + @include form-styles(); +} diff --git a/packages/client/src/pages/SignUp/SignUp.tsx b/packages/client/src/pages/SignUp/SignUp.tsx index 2474791..91eebf3 100644 --- a/packages/client/src/pages/SignUp/SignUp.tsx +++ b/packages/client/src/pages/SignUp/SignUp.tsx @@ -1,12 +1,34 @@ -import { useState } from 'react' +import './SignUp.scss' +import React, { useState } from 'react' import { signUpUser } from '@/store/reducers/auth-reducer' import { useAppDispatch } from '@/store' -import { useNavigate } from 'react-router-dom' -import { toast } from 'react-toastify' +import { Link, useNavigate } from 'react-router-dom' +import { Form } from '@/components/ui/Form/Form' import { Button } from '@/components/ui/Button/Button' +import SiteLogo from '@/assets/images/site-logo.svg' +import { CustomPageTitle } from '@/components/ui/CustomPageTitle/CustomPageTitle' +import { Input } from '@/components/ui/Input/Input' + +type UserType = { + first_name: string | null + second_name: string | null + login: string | null + password: string | null + email: string | null + phone: string | null +} + +const fieldLabels: { [key: string]: string } = { + first_name: 'Имя', + second_name: 'Фамилия', + login: 'Никнейм', + password: 'Пароль', + email: 'Email', + phone: 'Телефон', +} export const SignUp = () => { - const [form, setForm] = useState({ + const [formData, setFormData] = useState({ first_name: '', second_name: '', login: '', @@ -14,84 +36,79 @@ export const SignUp = () => { password: '', phone: '', }) + const [error, setError] = useState(null) const dispatch = useAppDispatch() const navigate = useNavigate() - const handleForm = (name: string, value: string) => { - setForm({ ...form, [name]: value }) - } + const handleInputChange = + (field: string) => (event: React.ChangeEvent) => { + setFormData(prevData => ({ + ...prevData, + [field]: event.target.value, + })) + } const handleSubmit = () => { - dispatch(signUpUser({ form: form })) + dispatch(signUpUser({ form: formData })) .unwrap() .then(() => { - navigate('/sign-in') + navigate('/game') }) .catch(error => { - toast.error(error.reason) + setError('Ошибка! Регистрация не выполнена.') }) } return ( - <> -
{ - e.preventDefault() - }}> - - - - - - -