From d32a6a4532177190788502d77172566aed01358f Mon Sep 17 00:00:00 2001
From: Alberto Defendi <1369-ahl-berto@users.noreply.gitlab.inf.unibz.it>
Date: Sat, 3 Apr 2021 09:58:34 +0200
Subject: [PATCH] Link onChange, value to InputField to retrieve form data

---
 .../AuthUser/SignInForm/InputField.tsx         |  6 +++++-
 .../AuthUser/SignInForm/SignInForm.tsx         | 18 ++++++------------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/components/AuthUser/SignInForm/InputField.tsx b/src/components/AuthUser/SignInForm/InputField.tsx
index a2dc677..fc11e0a 100644
--- a/src/components/AuthUser/SignInForm/InputField.tsx
+++ b/src/components/AuthUser/SignInForm/InputField.tsx
@@ -6,10 +6,12 @@ type Props = {
   label: string;
   error: boolean;
   errorMessage: string;
+  value: string;
+  onChange: any;
 };
 
 export const InputField: FC<Props> = (props: Props) => {
-  const { id, label, error, errorMessage } = props;
+  const { id, label, error, errorMessage, onChange, value } = props;
   return (
     <TextField
       variant="outlined"
@@ -19,6 +21,8 @@ export const InputField: FC<Props> = (props: Props) => {
       id={id}
       label={label}
       name={id}
+      onChange={onChange}
+      value={value}
       autoComplete={id}
       autoFocus
       error={error}
diff --git a/src/components/AuthUser/SignInForm/SignInForm.tsx b/src/components/AuthUser/SignInForm/SignInForm.tsx
index 924d4d7..7bd78fe 100644
--- a/src/components/AuthUser/SignInForm/SignInForm.tsx
+++ b/src/components/AuthUser/SignInForm/SignInForm.tsx
@@ -55,15 +55,11 @@ export const SignInForm: FC = () => {
           name="email"
           control={control}
           defaultValues
-          rules={{
-            required: {
-              value: true,
-              message: intl.formatMessage({ id: 'email' }),
-            },
-          }}
-          render={() => (
+          render={({ onChange, value }) => (
             <InputField
               id="email"
+              value={value}
+              onChange={onChange}
               label={intl.formatMessage({ id: 'email' })}
               error={!!errors.email}
               errorMessage={intl.formatMessage({ id: 'error' })}
@@ -74,13 +70,11 @@ export const SignInForm: FC = () => {
         <Controller
           name="password"
           control={control}
-          defaultValues
-          rules={{
-            required: { value: true, message: 'Enter a password' },
-          }}
-          render={() => (
+          render={({ onChange, value }) => (
             <InputField
               id="password"
+              value={value}
+              onChange={onChange}
               label="Password"
               error={!!errors.password}
               errorMessage="Incorrect entry."
-- 
GitLab