import React, { useEffect, useState } from 'react'; import { Alert, Box, Button, Collapse, Paper, TextField, Toolbar, Typography } from "@mui/material"; import { LoadingButton } from "@mui/lab"; import { useForm } from "react-hook-form"; import { useSignInMutation } from "../graphql/tscode"; import { Link, useLocation } from "react-router-dom"; import { observer } from "mobx-react"; import { useInjection } from "inversify-react"; import { AuthStore } from "../stores/AuthStore"; import SetTitle from "../components/SetTitle"; type LoginPageProps = {} type Inputs = { username: string, password: string, } const SignInPage = observer(({}: LoginPageProps) => { const authStore = useInjection(AuthStore); const location = useLocation(); const { register, handleSubmit, formState: { errors } } = useForm() const [ signUpSuccess, setSignUpSuccess ] = useState(false); const [ notSignedIn, setNotSignedIn ] = useState(false); useEffect(() => { switch (location.state) { case 'not_signed_in': setNotSignedIn(true) setTimeout(() => { setNotSignedIn(false) }, 5000) break case 'signup_success': setSignUpSuccess(true) setTimeout(() => { setSignUpSuccess(false) }, 5000) } }, []) const [ signInFunction, { data, loading, error } ] = useSignInMutation({ onCompleted: (result) => authStore.setToken(result.signIn) }) const onSubmit = async (data: Inputs) => { try { await signInFunction({ variables: data }) } catch (e) { console.log(e) } } return ( Signing In {error && {error?.message}} You have signed up! You should sign in motherfucker! Sign In
{authStore.token}
) }); export default SignInPage;