From ba7da0a61f2fc331b368318351373c1bc0521c82 Mon Sep 17 00:00:00 2001
From: Alberto Defendi <1369-ahl-berto@users.noreply.gitlab.inf.unibz.it>
Date: Thu, 15 Apr 2021 14:38:02 +0200
Subject: [PATCH] Implement history push

---
 .../AuthUser/SignInForm/SignInForm.tsx        | 30 +++++++++++--------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/components/AuthUser/SignInForm/SignInForm.tsx b/src/components/AuthUser/SignInForm/SignInForm.tsx
index b2f3884..c88e37b 100644
--- a/src/components/AuthUser/SignInForm/SignInForm.tsx
+++ b/src/components/AuthUser/SignInForm/SignInForm.tsx
@@ -4,6 +4,8 @@ import { SubmitHandler, useForm } from 'react-hook-form';
 import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
 import { Button } from '@material-ui/core';
 import { InputField } from 'components/AuthUser/SignInForm/InputField/InputField';
+import { useHistory } from 'react-router-dom';
+import { AuthRoutes } from 'components/api/routes';
 
 const useStyles = makeStyles((theme: Theme) =>
   createStyles({
@@ -22,8 +24,9 @@ const useStyles = makeStyles((theme: Theme) =>
   }),
 );
 
-// TODO: real time form validation
 export const SignInForm: FC = () => {
+  const history = useHistory();
+
   interface FormData {
     email: string;
     password: string;
@@ -39,19 +42,22 @@ export const SignInForm: FC = () => {
   });
 
   const onSubmit: SubmitHandler<FormData> = (values: FormData) => {
-    axios.post(
-      '/api/web/login',
-      {
-        username: values.email,
-        password: values.password,
-      },
-      {
-        headers: {
-          'Content-Type': 'application/json',
+    axios
+      .post(
+        '/api/web/login',
+        {
+          username: values.email,
+          password: values.password,
         },
-      },
-    );
+        {
+          headers: {
+            'Content-Type': 'application/json',
+          },
+        },
+      )
+      .then(() => history.replace(AuthRoutes.dashboard));
   };
+
   const classes = useStyles();
   return (
     <>
-- 
GitLab