This commit is contained in:
2024-10-28 16:16:53 +05:00
parent 77aabed207
commit d6809ff538
30 changed files with 1250 additions and 658 deletions
+3 -1
View File
@@ -191,7 +191,9 @@ function DashboardPage() {
</div>
<div className="flex justify-between items-center px-4 py-2 h-12 border-r border-b border-[#DAE0E5]">
<p className="text-sm font-semibold">Расписание</p>
<div className="flex items-center gap-4">
<p className="text-sm font-semibold">Расписание</p>
</div>
<div className="flex items-center gap-4">
<p className="text-sm font-semibold">
{format(selectedDay, "PPPP", { locale: ru })}
+3 -3
View File
@@ -5,11 +5,11 @@ import { useEffect } from "react";
import useAuthStore from "../stores/useAuthStore";
function HomePage() {
const accessToken = useAuthStore().accessToken;
const { user } = useAuthStore();
const navigate = useNavigate();
useEffect(() => {
if (accessToken) {
if (user?.accessToken) {
navigate("/dashboard");
} else {
navigate("/login");
@@ -17,7 +17,7 @@ function HomePage() {
}, []);
return (
<div className="p-8 flex flex-col gap-4 w-fit">
<div className="flex flex-col gap-4 p-8 w-fit">
<p>HomePage</p>
<Link to="/login">
<Button type="button">Login</Button>
+39 -40
View File
@@ -1,62 +1,61 @@
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useEffect, useState } from "react";
import ky from "ky";
// import ReCAPTCHA from "react-google-recaptcha";
import { useState } from "react";
import Form from "../components/Form";
import Label from "../components/Label";
import Input from "../components/Input";
import Button from "../components/Button";
import { Link, useNavigate } from "react-router-dom";
import useAuthStore from "../stores/useAuthStore";
import toast from "react-hot-toast";
import IError from "../types/IError";
import IUser from "../types/IUser";
import api from "../utils/api";
function LoginPage() {
const [username, setUsername] = useState<string>();
const [password, setPassword] = useState<string>();
// const recaptchaRef = useRef(null);
const [accessToken, setAccessToken, setUser] = useAuthStore((state) => [
state.accessToken,
state.setAccessToken,
state.setUser,
]);
const [isLoading, setisLoading] = useState<boolean>(false);
const [loading, setLoading] = useState(false);
const { setUser } = useAuthStore();
const navigate = useNavigate();
async function login() {
setisLoading(true);
setLoading(true);
const result: any = await ky
.post(import.meta.env.VITE_API_URL + "/login", {
json: {
username,
password,
},
})
.json();
try {
const result: IUser | IError = await api
.post("login", {
credentials: "include",
json: { username, password },
})
.json();
if (result.error) {
alert(result.error);
return;
if ("error" in result) {
setLoading(false);
toast.error(`Error: ${result.error}`);
return;
}
setUser({
id: result.id,
username: "username",
accessToken: result.accessToken,
companyId: result.companyId,
name: result.name,
role: result.role,
buildIds: result.buildIds,
});
navigate("/dashboard");
} catch (error) {
setLoading(false);
toast.error((error as Error).message);
}
setAccessToken(result.accessToken);
setUser(result.user);
navigate("/dashboard");
setTimeout(() => {
setisLoading(false);
}, 3000);
}
useEffect(() => {
if (accessToken) {
navigate("/dashboard");
}
}, []);
return (
<div className="min-h-screen flex flex-col justify-center items-center p-8 flex-1 ">
<div className=" bg-white rounded-lg shadow-md overflow-hidden">
<div className="flex flex-col items-center justify-center flex-1 min-h-screen p-8 ">
<div className="overflow-hidden bg-white rounded-lg shadow-md ">
<div className="flex flex-col gap-6 p-12">
<p className="text-2xl font-semibold">Вход</p>
<Form handleSubmit={login}>
@@ -88,12 +87,12 @@ function LoginPage() {
type="submit"
size="medium"
className="mt-10"
loading={isLoading}
loading={loading}
>
Войти
</Button>
</Form>
<div className="self-center flex gap-6">
<div className="flex self-center gap-6">
<Link to="/registration" className="text-xs text-[#49A1F5]">
Нет аккаунта?
</Link>