2021-10-27 12:11:16 +00:00
|
|
|
import React, { useEffect } from "react";
|
2021-07-13 11:35:46 +00:00
|
|
|
import { useForm } from "react-hook-form";
|
|
|
|
import {
|
|
|
|
Text,
|
|
|
|
Stack,
|
|
|
|
Box,
|
|
|
|
FormControl,
|
|
|
|
FormErrorMessage,
|
|
|
|
InputGroup,
|
|
|
|
Button,
|
|
|
|
Input,
|
|
|
|
InputRightElement,
|
|
|
|
} 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";
|
|
|
|
import PasswordInput from "./PasswordInput";
|
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();
|
|
|
|
|
|
|
|
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
|
|
|
<Text color="gray.1200" fontSize="md">
|
2021-08-03 14:24:14 +00:00
|
|
|
To your Moonstream account
|
2021-07-13 11:35:46 +00:00
|
|
|
</Text>
|
|
|
|
<form onSubmit={handleSubmit(login)}>
|
|
|
|
<Stack width="100%" pt={4} spacing={3}>
|
|
|
|
<FormControl isInvalid={errors.username}>
|
|
|
|
<InputGroup>
|
|
|
|
<Input
|
|
|
|
_placeholder={{ textColor: "gray.1200" }}
|
|
|
|
autoComplete="username"
|
|
|
|
variant="filled"
|
2021-09-21 18:37:48 +00:00
|
|
|
colorScheme="blue"
|
2021-08-03 14:24:14 +00:00
|
|
|
placeholder="Your Moonstream username"
|
2021-07-13 11:35:46 +00:00
|
|
|
name="username"
|
2021-07-31 17:49:41 +00:00
|
|
|
{...register("username", { required: true })}
|
2021-07-13 11:35:46 +00:00
|
|
|
ref={register({ required: "Username is required!" })}
|
|
|
|
/>
|
|
|
|
<InputRightElement>
|
|
|
|
<CustomIcon icon="name" />
|
|
|
|
</InputRightElement>
|
|
|
|
</InputGroup>
|
2021-09-21 18:37:48 +00:00
|
|
|
<FormErrorMessage color="red.400" pl="1">
|
2021-07-13 11:35:46 +00:00
|
|
|
{errors.username && errors.username.message}
|
|
|
|
</FormErrorMessage>
|
|
|
|
</FormControl>
|
|
|
|
<FormControl isInvalid={errors.password}>
|
|
|
|
<PasswordInput
|
2021-08-03 14:24:14 +00:00
|
|
|
placeholder="Your Moonstream password"
|
2021-07-13 11:35:46 +00:00
|
|
|
name="password"
|
|
|
|
ref={register({ required: "Password is required!" })}
|
|
|
|
/>
|
2021-09-21 18:37:48 +00:00
|
|
|
<FormErrorMessage color="red.400" pl="1">
|
2021-07-13 11:35:46 +00:00
|
|
|
{errors.password && errors.password.message}
|
|
|
|
</FormErrorMessage>
|
|
|
|
</FormControl>
|
|
|
|
</Stack>
|
|
|
|
<Button
|
|
|
|
my={8}
|
|
|
|
type="submit"
|
|
|
|
width="100%"
|
|
|
|
variant="solid"
|
2021-09-21 18:37:48 +00:00
|
|
|
colorScheme="blue"
|
2021-07-13 11:35:46 +00:00
|
|
|
isLoading={isLoading}
|
|
|
|
>
|
|
|
|
Login
|
|
|
|
</Button>
|
|
|
|
</form>
|
2021-09-15 16:04:06 +00:00
|
|
|
<Text textAlign="center" fontSize="md" color="gray.1200">
|
|
|
|
{" "}
|
2021-07-13 11:35:46 +00:00
|
|
|
<Box
|
|
|
|
cursor="pointer"
|
2021-09-21 18:37:48 +00:00
|
|
|
color="blue.800"
|
2021-07-13 11:35:46 +00:00
|
|
|
as="span"
|
2021-11-09 12:28:41 +00:00
|
|
|
onClick={() => toggleModal({ type: MODAL_TYPES.FORGOT })}
|
2021-07-13 11:35:46 +00:00
|
|
|
>
|
2021-09-15 16:04:06 +00:00
|
|
|
Forgot your password?
|
2021-07-13 11:35:46 +00:00
|
|
|
</Box>
|
2021-09-15 16:04:06 +00:00
|
|
|
<Box height="1px" width="100%" background="#eaebf8" mb="1.875rem" />
|
|
|
|
</Text>
|
2021-07-13 11:35:46 +00:00
|
|
|
<Text textAlign="center" fontSize="md" color="gray.1200">
|
2021-11-08 16:23:09 +00:00
|
|
|
Don`t have an account?{" "}
|
|
|
|
<Box
|
2021-07-13 11:35:46 +00:00
|
|
|
cursor="pointer"
|
2021-09-21 18:37:48 +00:00
|
|
|
color="blue.800"
|
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;
|