Skip to content

Commit

Permalink
style(signin): style sign in and sign up for app authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunan-k committed Nov 27, 2023
1 parent 35e17ee commit 0419bae
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 50 deletions.
19 changes: 19 additions & 0 deletions app/Home.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@
transform: perspective(800px) rotateY(-10deg) rotateX(10deg);
}

.dark-blue-span {
font-weight: 600;
color: #a30ec9;
cursor: pointer;
}

.custom-file-upload {
border-bottom: 2px solid black;
padding: 0 0 12px 0;
cursor: pointer;
font-size: 16px;
font-weight: 400;
color: rgb(132, 129, 129);
}

.custom-file-upload input[type="file"] {
display: none;
}

@media (max-width: 1280px) {
.hero-img {
background-image: url(../public/images/heroBannerMobile.jpg);
Expand Down
48 changes: 48 additions & 0 deletions app/components/LoginContainer.tsx
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;
129 changes: 129 additions & 0 deletions app/components/SignIn.tsx
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;
141 changes: 117 additions & 24 deletions app/components/SignUp/SignUp.tsx → app/components/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import React, { useState } from "react";
import "@/Home.css";
import { useRouter } from "next/navigation";
import Flex from "@/styles/Flex.styled";
import Input from "@/styles/Input.styled";
import Container from "@/styles/Container.styled";
import { FaRegEye, FaRegEyeSlash } from "react-icons/fa6";
import Text from "@/styles/Text.styled";

const SignUp = () => {
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -108,37 +113,125 @@ const SignUp = () => {
};

return (
<section className="display-flex-col-login">
<input type="text" placeholder="name" onChange={(e) => setName(e.target.value)} />
<input type="email" placeholder="email" onChange={(e) => setEmail(e.target.value)} />
<div className="display-flex-row">
<input
<Flex flexDirection="column" gap="24px" width="75%">
<Input
value={name}
placeholder="Your name goes here..."
$outline="0"
$border="0"
borderBottom="2px solid black"
padding="0 0 12px 0"
$fontSize="16px"
$fontWeight="400"
type="text"
onChange={(e) => setName(e.target.value)}
width="100%"
height="40px"
/>
<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="Your secret goes here..."
$outline="0"
$border="0"
borderBottom="2px solid black"
padding="0 0 12px 0"
$fontSize="16px"
$fontWeight="400"
type={showPassword ? "text" : "password"}
placeholder="password"
onChange={(e) => setPassword(e.target.value)}
width="100%"
height="40px"
/>
<button onClick={() => setShowPassword((prev: boolean) => !prev)}>{showPassword ? "Hide" : "Show"}</button>
</div>
<div className="display-flex-row">
<input
<Container
cursor="pointer"
$position="absolute"
$right="12px"
$bottom="8px"
onClick={() => setShowPassword(!showPassword)}
>
{!showPassword ? <FaRegEye size={24} /> : <FaRegEyeSlash size={24} />}
</Container>
</Container>

<Container $position="relative">
<Input
value={confirmPassword}
placeholder="Confirm you secret"
$outline="0"
$border="0"
borderBottom="2px solid black"
padding="0 0 12px 0"
$fontSize="16px"
$fontWeight="400"
type={showPassword ? "text" : "password"}
placeholder="confirm password"
onChange={(e) => setConfirmPassword(e.target.value)}
width="100%"
height="40px"
/>
<button onClick={() => setShowPassword((prev: boolean) => !prev)}>{showPassword ? "Hide" : "Show"}</button>
</div>
<input
type="file"
accept="image/*"
onChange={(e) => {
if (e.target && e.target.files && e.target.files.length > 0) {
postDetails(e.target.files[0]);
}
}}
/>
<Container
cursor="pointer"
$position="absolute"
$right="12px"
$bottom="8px"
onClick={() => setShowPassword(!showPassword)}
>
{!showPassword ? <FaRegEye size={24} /> : <FaRegEyeSlash size={24} />}
</Container>
</Container>

<label className="custom-file-upload">
Upload your image
<Input
placeholder="Your secret goes here..."
$outline="0"
$border="0"
borderBottom="2px solid black"
padding="0 0 12px 0"
$fontSize="16px"
$fontWeight="400"
type="file"
accept="image/*"
onChange={(e) => {
if (e.target && e.target.files && e.target.files.length > 0) {
postDetails(e.target.files[0]);
}
}}
width="100%"
height="40px"
/>
</label>

<button onClick={submitHandler}>{loading ? "loading" : "Sign Up"}</button>
</section>
<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">
{loading ? "loading" : "Sign Up"}
</Text>
</Container>
</Flex>
);
};

Expand Down
Loading

0 comments on commit 0419bae

Please sign in to comment.