подключил регистрацию

This commit is contained in:
Андрей Дувакин 2025-11-29 21:58:14 +05:00
parent 1929318d55
commit 7bd89686a9
2 changed files with 61 additions and 25 deletions

View File

@ -1,6 +1,7 @@
import {Button, Col, Flex, Form, Input, Select, Typography} from "antd";
import {UserOutlined, MailOutlined, LockOutlined} from "@ant-design/icons";
import {Button, Col, DatePicker, Flex, Form, Input, Select, Tooltip, Typography} from "antd";
import {UserOutlined, MailOutlined, LockOutlined, InfoCircleOutlined, CalendarOutlined} from "@ant-design/icons";
import useRegisterPage from "./useRegisterPage.js";
import dayjs from "dayjs";
const {Title, Text} = Typography;
@ -23,23 +24,9 @@ const RegisterPage = () => {
onFinish={onFinish}
layout="vertical"
>
<Form.Item
label="Роль"
name="role"
rules={[{required: true, message: "Выберите роль"}]}
>
<Select
placeholder="Выберите роль"
size="large"
>
<Select.Option value="student">Студент</Select.Option>
<Select.Option value="teacher">Преподаватель</Select.Option>
</Select>
</Form.Item>
<Form.Item
label="Имя"
name="firstName"
name="first_name"
rules={[{required: true, message: "Введите имя"}]}
>
<Input
@ -51,7 +38,7 @@ const RegisterPage = () => {
<Form.Item
label="Фамилия"
name="lastName"
name="last_name"
rules={[{required: true, message: "Введите фамилию"}]}
>
<Input
@ -75,6 +62,19 @@ const RegisterPage = () => {
size="large"
/>
</Form.Item>
<Form.Item
name="birthdate"
label="Дата рождения"
rules={[{required: true, message: "Введите дату рождения"}]}
>
<DatePicker
suffixIcon={<CalendarOutlined/>}
format="DD.MM.YYYY"
style={{width: "100%"}}
size="large"
maxDate={dayjs()}
/>
</Form.Item>
<Form.Item
label="Логин"
@ -87,6 +87,13 @@ const RegisterPage = () => {
size="large"
/>
</Form.Item>
<Tooltip
title="Пароль должен содержать не менее 8 символов, включая хотя бы одну букву и одну цифру и один специальный символ"
>
<Typography.Title level={3} style={{width: 30}}>
<InfoCircleOutlined/>
</Typography.Title>
</Tooltip>
<Form.Item
label="Пароль"
@ -105,7 +112,7 @@ const RegisterPage = () => {
<Form.Item
label="Подтверждение пароля"
name="confirmPassword"
name="repeat_password"
dependencies={['password']}
rules={[
{required: true, message: "Подтвердите пароль"},

View File

@ -1,9 +1,18 @@
import { message } from 'antd';
import { useNavigate } from 'react-router-dom';
import {message, notification} from 'antd';
import {useNavigate} from 'react-router-dom';
import {useRegisterUserMutation} from "../../../Api/usersApi.js";
const useRegisterPage = () => {
const navigate = useNavigate();
const [
createUser,
{
isLoading,
isError,
}
] = useRegisterUserMutation();
const pageContainerStyle = {
width: 450,
padding: 40,
@ -12,10 +21,30 @@ const useRegisterPage = () => {
backgroundColor: "white",
};
const onFinish = (values) => {
console.log('Регистрация:', values);
message.success('Регистрация выполнена успешно!');
navigate('/login');
const onFinish = async (values) => {
const payload = {
...values,
birthdate: values.birthdate
? values.birthdate.format("YYYY-MM-DD")
: null,
};
console.log(payload)
try {
await createUser(payload);
notification.success({
title: "Успешно",
message: "Пользователь успешно создан",
placement: "topRight",
})
navigate('/login');
} catch {
notification.error({
title: "Ошибка",
message: "Пользователь не создан",
placement: "topRight",
})
}
};
return {