ebleach7

kettle

May 6th, 2023
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { authService } from "@/src/api";
  2. import { ColorModeSwitcher, Logo } from "@/src/components/ui";
  3. import { ViewIcon, ViewOffIcon } from "@chakra-ui/icons";
  4. import {
  5.   Box,
  6.   Button,
  7.   Container,
  8.   Flex,
  9.   FormControl,
  10.   FormErrorMessage,
  11.   FormLabel,
  12.   Heading,
  13.   Input,
  14.   InputGroup,
  15.   InputRightElement,
  16.   Link,
  17.   Stack,
  18.   Text,
  19.   useToast,
  20. } from "@chakra-ui/react";
  21. import { yupResolver } from "@hookform/resolvers/yup";
  22. import Head from "next/head";
  23. import NextLink from "next/link";
  24. import { useRouter } from "next/router";
  25. import { useState } from "react";
  26. import { useForm } from "react-hook-form";
  27. import { ISignInSubmitData } from "./SignIn.interface";
  28. import { loginSchema } from "./SignIn.schema";
  29.  
  30. export const SignIn = () => {
  31.   const toast = useToast();
  32.   const router = useRouter();
  33.  
  34.   const {
  35.     register,
  36.     handleSubmit,
  37.     formState: { errors },
  38.     resetField,
  39.   } = useForm<ISignInSubmitData>({
  40.     resolver: yupResolver(loginSchema),
  41.   });
  42.  
  43.   const [show, setShow] = useState(false);
  44.   const handleClick = () => setShow(!show);
  45.  
  46.   const onSubmit = async (data: ISignInSubmitData) => {
  47.     try {
  48.       const response = await authService.signIn({
  49.         url: "/users/login",
  50.         username: data.name,
  51.         password: data.password,
  52.       });
  53.  
  54.       resetField("name");
  55.       resetField("password");
  56.       toast({
  57.         title: "Login was successful!",
  58.         status: "success",
  59.         duration: 2000,
  60.         isClosable: true,
  61.         position: "top",
  62.       });
  63.  
  64.       router.push("/");
  65.     } catch (error) {
  66.       toast({
  67.         title: (error as Error).message,
  68.         status: "error",
  69.         duration: 2000,
  70.         isClosable: true,
  71.         position: "top",
  72.       });
  73.     }
  74.   };
  75.  
  76.   return (
  77.     <>
  78.     "Верстка"
  79.     </>
  80.   );
  81. };
  82.  
Advertisement
Add Comment
Please, Sign In to add comment