From 20ef1fcef337103771857da3b9eeeca15dcb4ed4 Mon Sep 17 00:00:00 2001 From: swve Date: Sat, 6 May 2023 09:45:41 +0200 Subject: [PATCH] feat: improve login page design --- front/app/login/page.tsx | 101 +++++++++++++++++++++++++++++++-------- 1 file changed, 81 insertions(+), 20 deletions(-) diff --git a/front/app/login/page.tsx b/front/app/login/page.tsx index 50698b2a..79d2d5a6 100644 --- a/front/app/login/page.tsx +++ b/front/app/login/page.tsx @@ -1,25 +1,37 @@ "use client"; import { useRouter } from 'next/navigation'; -import React from "react"; +import React, { useState } from "react"; +import { styled } from '@stitches/react'; import { Title } from "../../components/UI/Elements/Styles/Title"; import { loginAndGetToken } from "../../services/auth/auth"; +import FormLayout, { ButtonBlack, Flex, FormField, FormLabel, FormMessage, Input } from '@components/UI/Form/Form'; +import * as Form from '@radix-ui/react-form'; +import { BarLoader } from 'react-spinners'; +import Toast from '@components/UI/Toast/Toast'; +import { toast } from 'react-hot-toast'; const Login = () => { const [email, setEmail] = React.useState("admin@admin.admin"); const [password, setPassword] = React.useState("admin"); + const [isSubmitting, setIsSubmitting] = useState(false); const router = useRouter(); const handleSubmit = (e: any) => { e.preventDefault(); - console.log({ email, password }); - alert(JSON.stringify({ email, password })); - try { - loginAndGetToken(email, password); - router.push("/"); - } - catch (e) { - console.log(e); - } + setIsSubmitting(true); + toast.promise( + loginAndGetToken(email, password), + { + loading: 'Logging in...', + success: () => { + router.push('/'); + return Logged in successfully; + }, + error: Wrong credentials, + } + ); + + setIsSubmitting(false); }; const handleEmailChange = (e: any) => { @@ -32,19 +44,68 @@ const Login = () => { return (
- < > - Login + + + + + + + Email + Please provide an email + + + + + + + + Password + Please provide a password + + + + + + + + + + {isSubmitting ? : "Login"} + + + + + + -
- - - -
-
); }; +const LoginPage = styled('div', { + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + height: '100vh', + width: '100vw', + backgroundColor: '#f5f5f5', +}); + +const LoginBox = styled('div', { + display: 'flex', + flexDirection: 'column', + justifyContent: 'center', + alignItems: 'center', + height: '40vh', + width: '40vw', + backgroundColor: '#ffffff', + borderRadius: 10, + + '@media (max-width: 768px)': { + width: '100vw', + height: '100vh', + borderRadius: 0, + }, +}); + export default Login;