From 5288637d19682aed34ffc57d5cb8c2e9e00800d5 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Wed, 16 Apr 2025 15:00:44 +0300 Subject: [PATCH] feat: pseudo login --- src/components/ui/Input.module.scss | 2 +- src/components/ui/Input.tsx | 18 +++++++---- src/pages/login.tsx | 46 ++++++++++++++++++++++------- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/components/ui/Input.module.scss b/src/components/ui/Input.module.scss index 2248225..edda006 100644 --- a/src/components/ui/Input.module.scss +++ b/src/components/ui/Input.module.scss @@ -1,5 +1,5 @@ @reference "../../index.scss"; .input_field { - @apply w-full rounded-[4rem] border border-gray-300 bg-white p-2 leading-8 placeholder:transition focus:outline-0 focus:placeholder:opacity-25; + @apply w-full rounded-[4rem] border bg-white p-2 leading-8 placeholder:transition focus:outline-0 focus:placeholder:opacity-25; } diff --git a/src/components/ui/Input.tsx b/src/components/ui/Input.tsx index 24adec2..ffe4f7c 100644 --- a/src/components/ui/Input.tsx +++ b/src/components/ui/Input.tsx @@ -10,6 +10,10 @@ const input = tv({ center: "text-center", left: "text-left", }, + "border-error": { + true: "border-red-500 placeholder:text-red-500", + false: "border-gray-300", + }, }, defaultVariants: { "text-align": "left", @@ -21,7 +25,7 @@ interface InputProps { placeholder?: string; textAlign?: "center" | "left"; error?: string; - ref: Ref | null; + textRef?: Ref | null; } const Input: FunctionComponent = ({ @@ -29,17 +33,21 @@ const Input: FunctionComponent = ({ placeholder = "", textAlign, error = "", - ref = null, + textRef = null, }: InputProps) => { return (
-

+

{error}

diff --git a/src/pages/login.tsx b/src/pages/login.tsx index dbd51c0..9515e8f 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -5,28 +5,52 @@ import { UrlsTitle } from "@/enums/urls"; import { useAppContext } from "@/providers/AuthProvider"; import { FunctionComponent } from "preact"; import { useLocation } from "preact-iso"; +import "preact/debug"; +import { useRef, useState } from "preact/hooks"; import classes from "./login.module.scss"; + +const testUser = { + login: "test", + password: "test", +}; const LoginPage: FunctionComponent = () => { const { isLoggedIn } = useAppContext(); const { route } = useLocation(); - return ( + const loginRef = useRef(null); + const passwordRef = useRef(null); + const [loginError, setLoginError] = useState(""); + const [passwordError, setPasswordError] = useState(""); + const login = async () => { + if (!loginRef.current || !passwordRef.current) return; + setLoginError(""); + setPasswordError(""); + if (!loginRef.current.value.length || !passwordRef.current.value.length) { + if (!loginRef.current.value.length) setLoginError("Введите логин"); + if (!passwordRef.current.value.length) setPasswordError("Введите пароль"); + return; + } + if (loginRef.current.value !== testUser.login || passwordRef.current.value !== testUser.password) { + setLoginError("Неправильный логин или пароль"); + return; + } + isLoggedIn.value = true; + localStorage.setItem("loggedIn", "true"); + route("/profile/tasks", true); + }; + if (isLoggedIn.value) route("/profile/tasks", true); + return !isLoggedIn.value ? (

Антихвост

- - -
+ ) : ( +

Redirecting...

); };