-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(signin): style sign in and sign up for app authentication
- Loading branch information
Showing
11 changed files
with
320 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Flex from "@/styles/Flex.styled"; | ||
import Theme from "@/styles/Theme.styled"; | ||
import React, { useState } from "react"; | ||
import SignUp from "./SignUp"; | ||
import "../Home.css"; | ||
import Text from "@/styles/Text.styled"; | ||
import Container from "@/styles/Container.styled"; | ||
import SignIn from "./SignIn"; | ||
|
||
const LoginContainer = () => { | ||
const [signIn, setSignIn] = useState(true); | ||
|
||
return ( | ||
<Flex | ||
backgroundColor={Theme.colors.white} | ||
height="100vh" | ||
padding="48px" | ||
mPadding="24px" | ||
justifyContent="center" | ||
alignItems="center" | ||
> | ||
<Container width="50%" padding="48px" mPadding="0" mWidth="100%"> | ||
<Text fontSize="30px" fontWeight="500" margin="0 0 12px 0"> | ||
{signIn ? "Sign In" : "Sign Up"} | ||
</Text> | ||
<Text fontSize="16px" fontWeight="400" margin="0 0 4px 0"> | ||
{signIn ? "If you don’t have an account" : "If you already have an account"} | ||
</Text> | ||
<Text fontSize="16px" fontWeight="400" margin="0 0 40px 0"> | ||
You can{" "} | ||
{signIn ? ( | ||
<span onClick={() => setSignIn(!signIn)} className="dark-blue-span"> | ||
Register here ! | ||
</span> | ||
) : ( | ||
<span onClick={() => setSignIn(!signIn)} className="dark-blue-span"> | ||
Login here ! | ||
</span> | ||
)} | ||
</Text> | ||
{signIn ? <SignIn /> : <SignUp />} | ||
</Container> | ||
<Flex className="sign-in-up-preview" $mDisplay="none" width="45%" height="75%" margin="0 24px 0 0"></Flex> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default LoginContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
import { useState } from "react"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { loginSubmitHandler } from "@/utils/http"; | ||
import { ChatState } from "@/contexts/ChatProvider"; | ||
import Flex from "@/styles/Flex.styled"; | ||
import Input from "@/styles/Input.styled"; | ||
import Container from "@/styles/Container.styled"; | ||
import { FaRegEye } from "react-icons/fa6"; | ||
import { FaRegEyeSlash } from "react-icons/fa6"; | ||
import Text from "@/styles/Text.styled"; | ||
|
||
const SignIn = () => { | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [showPassword, setShowPassword] = useState(false); | ||
const { setUser } = ChatState()!; | ||
const router = useRouter(); | ||
|
||
const { mutateAsync, isPending } = useMutation({ | ||
mutationFn: loginSubmitHandler, | ||
onSuccess: (responseData) => { | ||
setUser(responseData); | ||
localStorage.setItem("userInfo", JSON.stringify(responseData)); | ||
router.push("/chats"); | ||
}, | ||
onError: (err) => { | ||
// eslint-disable-next-line no-console | ||
console.error("Login error:", err); | ||
} | ||
}); | ||
|
||
const submitHandler = async () => { | ||
if (!email || !password) { | ||
// console.log("Fill email and password"); | ||
return; | ||
} | ||
|
||
const data = { email, password }; | ||
try { | ||
await mutateAsync({ data }); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error("Error:", error); | ||
return; | ||
} | ||
}; | ||
|
||
function guestSubmitHandler() { | ||
setEmail("[email protected]"); | ||
setPassword("123456"); | ||
} | ||
|
||
return ( | ||
<Flex flexDirection="column" gap="24px" width="75%"> | ||
<Input | ||
value={email} | ||
placeholder="Your mail goes here..." | ||
$outline="0" | ||
$border="0" | ||
borderBottom="2px solid black" | ||
padding="0 0 12px 0" | ||
$fontSize="16px" | ||
$fontWeight="400" | ||
type="email" | ||
onChange={(e) => setEmail(e.target.value)} | ||
width="100%" | ||
height="40px" | ||
/> | ||
<Container $position="relative"> | ||
<Input | ||
value={password} | ||
placeholder="Password" | ||
type={showPassword ? "text" : "password"} | ||
onChange={(e) => setPassword(e.target.value)} | ||
padding="0 0 12px 0" | ||
$fontSize="16px" | ||
$fontWeight="400" | ||
$outline="0" | ||
$border="0" | ||
borderBottom="2px solid black" | ||
width="100%" | ||
height="40px" | ||
/> | ||
<Container | ||
cursor="pointer" | ||
$position="absolute" | ||
$right="12px" | ||
$bottom="8px" | ||
onClick={() => setShowPassword(!showPassword)} | ||
> | ||
{!showPassword ? <FaRegEye size={24} /> : <FaRegEyeSlash size={24} />} | ||
</Container> | ||
</Container> | ||
<Container | ||
width="100%" | ||
textAlign="center" | ||
hBackgroundColor="black" | ||
padding="8px 12px" | ||
cursor="pointer" | ||
onClick={submitHandler} | ||
border="2px solid black" | ||
hColor="white" | ||
> | ||
<Text fontWeight="600" fontSize="18px"> | ||
{isPending ? "Submitting..." : "Login"} | ||
</Text> | ||
</Container> | ||
<Container | ||
width="100%" | ||
textAlign="center" | ||
hBackgroundColor="black" | ||
padding="8px 12px" | ||
cursor="pointer" | ||
onClick={guestSubmitHandler} | ||
border="2px solid black" | ||
hColor="white" | ||
> | ||
<Text fontWeight="600" fontSize="18px"> | ||
Guest User | ||
</Text> | ||
</Container> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default SignIn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.