Carousel!
This commit is contained in:
@ -1,10 +1,10 @@
|
|||||||
import { Form, Input, Menu, MenuProps, Modal, Spin } from "antd";
|
import { Carousel, Form, Input, Menu, MenuProps, Modal, Spin } from "antd";
|
||||||
import {
|
import {
|
||||||
KeyOutlined,
|
KeyOutlined,
|
||||||
LoadingOutlined,
|
LoadingOutlined,
|
||||||
UserAddOutlined,
|
UserAddOutlined,
|
||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
import React, { useContext, useEffect, useState } from "react";
|
import React, { useContext, useEffect, useRef, useState } from "react";
|
||||||
import {
|
import {
|
||||||
TokenResponse,
|
TokenResponse,
|
||||||
useGetUserQuery,
|
useGetUserQuery,
|
||||||
@ -21,6 +21,8 @@ const AuthModal = (props: {
|
|||||||
setOpen: (arg0: boolean) => void;
|
setOpen: (arg0: boolean) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const messageApi = useContext(MessageContext);
|
||||||
|
const carousel = useRef();
|
||||||
|
|
||||||
const [loginForm] = Form.useForm();
|
const [loginForm] = Form.useForm();
|
||||||
const [registerForm] = Form.useForm();
|
const [registerForm] = Form.useForm();
|
||||||
@ -33,7 +35,11 @@ const AuthModal = (props: {
|
|||||||
}, [data, isFetching, useGetUserQuery]);
|
}, [data, isFetching, useGetUserQuery]);
|
||||||
|
|
||||||
const [current, setCurrent] = useState("login");
|
const [current, setCurrent] = useState("login");
|
||||||
const messageApi = useContext(MessageContext);
|
useEffect(() => {
|
||||||
|
if (carousel?.current !== undefined) {
|
||||||
|
carousel.current.goTo(["login", "register"].indexOf(current));
|
||||||
|
}
|
||||||
|
}, [current]);
|
||||||
|
|
||||||
const [loginUser, { isLoading: isLoggingIn }] = useLoginMutation();
|
const [loginUser, { isLoading: isLoggingIn }] = useLoginMutation();
|
||||||
const [registerUser, { isLoading: isRegistering }] = useRegisterMutation();
|
const [registerUser, { isLoading: isRegistering }] = useRegisterMutation();
|
||||||
@ -48,11 +54,11 @@ const AuthModal = (props: {
|
|||||||
.then((data: TokenResponse) => {
|
.then((data: TokenResponse) => {
|
||||||
store.dispatch(updateToken(data.access_token));
|
store.dispatch(updateToken(data.access_token));
|
||||||
})
|
})
|
||||||
|
.then(() => loginForm.resetFields())
|
||||||
.then(() => refetch())
|
.then(() => refetch())
|
||||||
.then(() => props.setOpen(false))
|
.then(() => props.setOpen(false))
|
||||||
.then(() => navigate("/dashboard"))
|
.then(() => navigate("/dashboard"))
|
||||||
.catch(() => messageApi.error(tr("Login failed!")));
|
.catch(() => messageApi.error(tr("Login failed!")));
|
||||||
loginForm.resetFields();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitRegisterForm = (formData: {
|
const submitRegisterForm = (formData: {
|
||||||
@ -63,6 +69,7 @@ const AuthModal = (props: {
|
|||||||
}) => {
|
}) => {
|
||||||
registerUser(formData)
|
registerUser(formData)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
.then(() => submitLoginForm(formData))
|
||||||
.then(() => props.setOpen(false))
|
.then(() => props.setOpen(false))
|
||||||
.catch(() => messageApi.error(tr("Registration failed!")));
|
.catch(() => messageApi.error(tr("Registration failed!")));
|
||||||
};
|
};
|
||||||
@ -108,7 +115,44 @@ const AuthModal = (props: {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
{current === "register" ? (
|
<Carousel
|
||||||
|
ref={carousel}
|
||||||
|
dots={false}
|
||||||
|
speed={200}
|
||||||
|
onSwipe={(dir) => setCurrent(dir === "left" ? "register" : "login")}
|
||||||
|
infinite={false}
|
||||||
|
>
|
||||||
|
<Form
|
||||||
|
form={loginForm}
|
||||||
|
onFinish={submitLoginForm}
|
||||||
|
layout="vertical"
|
||||||
|
requiredMark={false}
|
||||||
|
>
|
||||||
|
<Form.Item
|
||||||
|
name="username"
|
||||||
|
label={tr("Username")}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: tr("Please input your Username!"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="password"
|
||||||
|
label={tr("Password")}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: tr("Please input your Password!"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input type="password" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
<Form
|
<Form
|
||||||
form={registerForm}
|
form={registerForm}
|
||||||
onFinish={submitRegisterForm}
|
onFinish={submitRegisterForm}
|
||||||
@ -167,39 +211,7 @@ const AuthModal = (props: {
|
|||||||
<Input type="password" />
|
<Input type="password" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
) : (
|
</Carousel>
|
||||||
<Form
|
|
||||||
form={loginForm}
|
|
||||||
onFinish={submitLoginForm}
|
|
||||||
layout="vertical"
|
|
||||||
requiredMark={false}
|
|
||||||
>
|
|
||||||
<Form.Item
|
|
||||||
name="username"
|
|
||||||
label={tr("Username")}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: tr("Please input your Username!"),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="password"
|
|
||||||
label={tr("Password")}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: tr("Please input your Password!"),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input type="password" />
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
)}
|
|
||||||
</Spin>
|
</Spin>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import {
|
|||||||
SettingOutlined,
|
SettingOutlined,
|
||||||
UserOutlined,
|
UserOutlined,
|
||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
import { Layout, Menu, MenuProps, Popover, Select } from "antd";
|
import { Layout, Menu, MenuProps, Popover } from "antd";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import AuthModal from "./AuthModal";
|
import AuthModal from "./AuthModal";
|
||||||
import "./styles.css";
|
import "./styles.css";
|
||||||
|
|||||||
@ -17,7 +17,6 @@ type Queue = {
|
|||||||
|
|
||||||
const QueuesList = (): JSX.Element => {
|
const QueuesList = (): JSX.Element => {
|
||||||
const { data, isLoading } = useGetQueuesQuery({});
|
const { data, isLoading } = useGetQueuesQuery({});
|
||||||
console.log(isLoading);
|
|
||||||
return (
|
return (
|
||||||
<div className="card">
|
<div className="card">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@ -3,13 +3,13 @@
|
|||||||
"ru": "Организация очередей еще никогда не была настолько простой"
|
"ru": "Организация очередей еще никогда не была настолько простой"
|
||||||
},
|
},
|
||||||
"Log in": {
|
"Log in": {
|
||||||
"ru": "Войти"
|
"ru": "Вход"
|
||||||
},
|
},
|
||||||
"Log out": {
|
"Log out": {
|
||||||
"ru": "Выйти"
|
"ru": "Выйти"
|
||||||
},
|
},
|
||||||
"Register": {
|
"Register": {
|
||||||
"ru": "Зарегистрироваться"
|
"ru": "Регистрация"
|
||||||
},
|
},
|
||||||
"Username": {
|
"Username": {
|
||||||
"ru": "Логин"
|
"ru": "Логин"
|
||||||
@ -67,5 +67,8 @@
|
|||||||
},
|
},
|
||||||
"Page not found": {
|
"Page not found": {
|
||||||
"ru": "Страница не найдена"
|
"ru": "Страница не найдена"
|
||||||
|
},
|
||||||
|
"You have no queues! Create one here": {
|
||||||
|
"ru": "У вас нет очередей! Создайте новую"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user