Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { authService } from "@/src/api";
- import { ColorModeSwitcher, Logo } from "@/src/components/ui";
- import { ViewIcon, ViewOffIcon } from "@chakra-ui/icons";
- import {
- Box,
- Button,
- Container,
- Flex,
- FormControl,
- FormErrorMessage,
- FormLabel,
- Heading,
- Input,
- InputGroup,
- InputRightElement,
- Link,
- Stack,
- Text,
- useToast,
- } from "@chakra-ui/react";
- import { yupResolver } from "@hookform/resolvers/yup";
- import Head from "next/head";
- import NextLink from "next/link";
- import { useRouter } from "next/router";
- import { useState } from "react";
- import { useForm } from "react-hook-form";
- import { ISignInSubmitData } from "./SignIn.interface";
- import { loginSchema } from "./SignIn.schema";
- export const SignIn = () => {
- const toast = useToast();
- const router = useRouter();
- const {
- register,
- handleSubmit,
- formState: { errors },
- resetField,
- } = useForm<ISignInSubmitData>({
- resolver: yupResolver(loginSchema),
- });
- const [show, setShow] = useState(false);
- const handleClick = () => setShow(!show);
- const onSubmit = async (data: ISignInSubmitData) => {
- try {
- const response = await authService.signIn({
- url: "/users/login",
- username: data.name,
- password: data.password,
- });
- resetField("name");
- resetField("password");
- toast({
- title: "Login was successful!",
- status: "success",
- duration: 2000,
- isClosable: true,
- position: "top",
- });
- router.push("/");
- } catch (error) {
- toast({
- title: (error as Error).message,
- status: "error",
- duration: 2000,
- isClosable: true,
- position: "top",
- });
- }
- };
- return (
- <>
- "Верстка"
- </>
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment