2022-11-15 21:39:25 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2021-07-13 11:35:46 +00:00
|
|
|
import { useForm } from "react-hook-form";
|
|
|
|
import {
|
|
|
|
Text,
|
|
|
|
Stack,
|
|
|
|
Box,
|
|
|
|
FormControl,
|
|
|
|
InputGroup,
|
|
|
|
Input,
|
|
|
|
InputRightElement,
|
2022-11-15 21:39:25 +00:00
|
|
|
Button,
|
2021-07-13 11:35:46 +00:00
|
|
|
} from "@chakra-ui/react";
|
2021-07-31 17:49:41 +00:00
|
|
|
import CustomIcon from "./CustomIcon";
|
2021-07-13 11:35:46 +00:00
|
|
|
import { useLogin } from "../core/hooks";
|
2021-10-27 13:01:26 +00:00
|
|
|
import { MODAL_TYPES } from "../core/providers/OverlayProvider/constants";
|
2021-07-13 11:35:46 +00:00
|
|
|
|
|
|
|
const SignIn = ({ toggleModal }) => {
|
|
|
|
const { handleSubmit, errors, register } = useForm();
|
|
|
|
const { login, isLoading, data } = useLogin();
|
2022-11-17 11:07:20 +00:00
|
|
|
const [showPassword, setShowPassword] = useState(false);
|
2021-07-13 11:35:46 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-09 12:28:41 +00:00
|
|
|
toggleModal({ type: MODAL_TYPES.OFF });
|
2021-07-13 11:35:46 +00:00
|
|
|
}, [data, toggleModal]);
|
|
|
|
|
|
|
|
return (
|
2021-10-27 12:11:16 +00:00
|
|
|
<>
|
2021-07-13 11:35:46 +00:00
|
|
|
<form onSubmit={handleSubmit(login)}>
|
2022-11-15 21:39:25 +00:00
|
|
|
<Stack width="100%" spacing={3}>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
fontSize: "18px",
|
|
|
|
fontWeight: 400,
|
|
|
|
color: errors.username ? "#EE8686" : "white",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{errors.username ? errors.username.message : "Username"}
|
|
|
|
</div>
|
2021-07-13 11:35:46 +00:00
|
|
|
<FormControl isInvalid={errors.username}>
|
2022-11-15 21:39:25 +00:00
|
|
|
<InputGroup bg="black">
|
2021-07-13 11:35:46 +00:00
|
|
|
<Input
|
|
|
|
autoComplete="username"
|
2022-11-17 11:07:20 +00:00
|
|
|
variant="bw"
|
2022-11-15 21:39:25 +00:00
|
|
|
placeholder="Enter your username or email"
|
2021-07-13 11:35:46 +00:00
|
|
|
name="username"
|
2021-07-31 17:49:41 +00:00
|
|
|
{...register("username", { required: true })}
|
2022-11-15 21:39:25 +00:00
|
|
|
ref={register({ required: "Username is required" })}
|
2021-07-13 11:35:46 +00:00
|
|
|
/>
|
|
|
|
</InputGroup>
|
|
|
|
</FormControl>
|
2022-11-15 21:39:25 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
fontSize: "18px",
|
|
|
|
color: errors.password ? "#EE8686" : "white",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{errors.password ? errors.password.message : "Password"}
|
|
|
|
</div>
|
2021-07-13 11:35:46 +00:00
|
|
|
<FormControl isInvalid={errors.password}>
|
2022-11-15 21:39:25 +00:00
|
|
|
<InputGroup bg="black">
|
|
|
|
<Input
|
|
|
|
autoComplete="current-password"
|
2022-11-17 11:07:20 +00:00
|
|
|
variant="bw"
|
2022-11-15 21:39:25 +00:00
|
|
|
placeholder="Enter your password"
|
|
|
|
name="password"
|
|
|
|
type={showPassword ? "text" : "password"}
|
|
|
|
ref={register({ required: "Password is required" })}
|
|
|
|
/>
|
2022-11-17 16:47:38 +00:00
|
|
|
<InputRightElement
|
|
|
|
onClick={() => setShowPassword(!showPassword)}
|
|
|
|
style={{ cursor: "pointer" }}
|
|
|
|
>
|
2022-11-15 21:39:25 +00:00
|
|
|
<CustomIcon icon="password" />
|
|
|
|
</InputRightElement>
|
|
|
|
</InputGroup>
|
2021-07-13 11:35:46 +00:00
|
|
|
</FormControl>
|
2022-11-15 21:39:25 +00:00
|
|
|
<Text textAlign="start" fontSize="18px">
|
|
|
|
{" "}
|
|
|
|
<Box
|
|
|
|
cursor="pointer"
|
|
|
|
color="#EE8686"
|
|
|
|
as="span"
|
|
|
|
onClick={() => toggleModal({ type: MODAL_TYPES.FORGOT })}
|
|
|
|
>
|
|
|
|
Forgot your password?
|
|
|
|
</Box>
|
|
|
|
</Text>
|
2021-07-13 11:35:46 +00:00
|
|
|
</Stack>
|
2022-11-15 21:39:25 +00:00
|
|
|
|
2021-07-13 11:35:46 +00:00
|
|
|
<Button
|
2022-11-15 21:39:25 +00:00
|
|
|
mt="30px"
|
|
|
|
mb="10px"
|
2022-11-17 11:07:20 +00:00
|
|
|
h="46px"
|
|
|
|
fontSize="lg"
|
|
|
|
variant="plainOrange"
|
2021-07-13 11:35:46 +00:00
|
|
|
type="submit"
|
|
|
|
width="100%"
|
|
|
|
isLoading={isLoading}
|
|
|
|
>
|
|
|
|
Login
|
|
|
|
</Button>
|
|
|
|
</form>
|
2022-11-15 21:39:25 +00:00
|
|
|
|
|
|
|
<Text textAlign="center" fontSize="md" color="white">
|
2021-11-08 16:23:09 +00:00
|
|
|
Don`t have an account?{" "}
|
|
|
|
<Box
|
2021-07-13 11:35:46 +00:00
|
|
|
cursor="pointer"
|
2022-11-15 21:39:25 +00:00
|
|
|
color="#EE8686"
|
2021-07-13 11:35:46 +00:00
|
|
|
as="span"
|
2021-11-15 16:01:20 +00:00
|
|
|
onClick={() => toggleModal({ type: MODAL_TYPES.SIGNUP })}
|
2021-07-13 11:35:46 +00:00
|
|
|
>
|
2021-09-15 16:04:06 +00:00
|
|
|
Register
|
2021-11-08 16:23:09 +00:00
|
|
|
</Box>
|
2021-07-13 11:35:46 +00:00
|
|
|
</Text>
|
2021-10-27 12:11:16 +00:00
|
|
|
</>
|
2021-07-13 11:35:46 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SignIn;
|