moonstream/frontend/src/components/SignIn.js

113 wiersze
3.2 KiB
JavaScript
Czysty Zwykły widok Historia

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,
2021-09-15 16:04:06 +00:00
Link,
2021-07-13 11:35:46 +00:00
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;
}
toggleModal(MODAL_TYPES.OFF);
2021-07-13 11:35:46 +00:00
}, [data, toggleModal]);
return (
<>
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"
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>
<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!" })}
/>
<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"
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"
color="blue.800"
2021-07-13 11:35:46 +00:00
as="span"
onClick={() => toggleModal(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-09-15 16:04:06 +00:00
{/* Don`t have an account?{" "} */}
We are in early access. If you would like to use Moonstream,{" "}
<Link href={"https://discord.gg/V3tWaP36"} color="orange.900">
2021-09-15 16:04:06 +00:00
contact us on Discord.
</Link>
{/* <Box
2021-07-13 11:35:46 +00:00
cursor="pointer"
color="blue.800"
2021-07-13 11:35:46 +00:00
as="span"
2021-09-15 16:04:06 +00:00
onClick={() => toggleModal("register")}
2021-07-13 11:35:46 +00:00
>
2021-09-15 16:04:06 +00:00
Register
</Box> */}
2021-07-13 11:35:46 +00:00
</Text>
</>
2021-07-13 11:35:46 +00:00
);
};
export default SignIn;