From d1496b1ace67d8d055ea4380b4639df92ee96447 Mon Sep 17 00:00:00 2001
From: Alberto Defendi <1369-ahl-berto@users.noreply.gitlab.inf.unibz.it>
Date: Thu, 6 May 2021 14:44:07 +0200
Subject: [PATCH] Attach api registration call to form.

---
 .../AuthUser/SignUpForm/SignUpForm.tsx        | 170 ++++++++++++++----
 1 file changed, 134 insertions(+), 36 deletions(-)

diff --git a/src/components/AuthUser/SignUpForm/SignUpForm.tsx b/src/components/AuthUser/SignUpForm/SignUpForm.tsx
index b38fdab..0cf10dc 100644
--- a/src/components/AuthUser/SignUpForm/SignUpForm.tsx
+++ b/src/components/AuthUser/SignUpForm/SignUpForm.tsx
@@ -13,48 +13,42 @@ export const SignUpForm: FC = () => {
     firstName: string;
     lastName: string;
     email: string;
+    phoneNumber: number;
+    address: number;
+    name: string;
+    memberCardNumber: number;
+    notes: string;
   };
 
-  const defaultValues: FormData = {
-    username: '',
-    password: '',
-    firstName: '',
-    lastName: '',
-    email: '',
-  };
-
-  const { control, errors, handleSubmit } = useForm<FormData>({
-    defaultValues,
-  });
+  const { control, errors, handleSubmit } = useForm<FormData>();
 
   const onSubmit: SubmitHandler<FormData> = (values: FormData) => {
-    axios
-      .post(
-        '/api/web/seniors/',
-        {
-          user: {
-            username: 'test',
-            password: values.password,
-            firstName: 'a',
-            lastName: 'b',
-            email: values.email,
-          },
-          phone_number: '213432234',
-          home_address: {
-            address: 'test street, 3',
-          },
-          member_card_issuer: {
-            name: 'test issuer',
-          },
-          member_card_number: '33333333333',
+    axios.post(
+      '/api/web/seniors/',
+      {
+        user: {
+          username: values.username,
+          password: values.password,
+          firstName: values.firstName,
+          lastName: values.lastName,
+          email: values.email,
+        },
+        phone_number: values.phoneNumber,
+        home_address: {
+          address: values.address,
         },
-        {
-          headers: {
-            'Content-Type': 'application/json',
-          },
+        member_card_issuer: {
+          name: values.memberCardNumber,
         },
-      )
-      .then((res) => console.log(res));
+        member_card_number: values.memberCardNumber,
+        notes: values.notes,
+      },
+      {
+        headers: {
+          'Content-Type': 'application/json',
+        },
+      },
+    );
   };
 
   const classes = useStyles();
@@ -96,6 +90,110 @@ export const SignUpForm: FC = () => {
           error={!!errors.password}
           errorMessage="Insert valid password"
         />
+
+        <InputField
+          name="username"
+          control={control}
+          rules={{
+            maxLength: 150,
+            required: {
+              value: true,
+              message: 'Insert valid username',
+            },
+          }}
+          label="Username"
+          error={!!errors.username}
+          errorMessage="Insert valid username"
+        />
+
+        <InputField
+          name="firstName"
+          control={control}
+          rules={{
+            maxLength: 150,
+            required: {
+              value: true,
+              message: 'Insert valid first name',
+            },
+          }}
+          label="First name"
+          error={!!errors.firstName}
+          errorMessage="Insert valid first name"
+        />
+
+        <InputField
+          name="lastName"
+          control={control}
+          rules={{
+            maxLength: 150,
+            required: {
+              value: true,
+              message: 'Insert valid last name',
+            },
+          }}
+          label="Last name"
+          error={!!errors.lastName}
+          errorMessage="Insert valid last name"
+        />
+
+        <InputField
+          name="address"
+          control={control}
+          rules={{
+            required: {
+              value: true,
+              message: 'Insert valid address',
+            },
+          }}
+          label="Address"
+          error={!!errors.address}
+          errorMessage="Insert valid address"
+        />
+
+        <InputField
+          name="phoneNumber"
+          control={control}
+          rules={{
+            maxLength: 15,
+            required: {
+              value: true,
+              message: 'Insert valid phone number',
+            },
+          }}
+          label="Phone number"
+          error={!!errors.phoneNumber}
+          errorMessage="Insert valid phone number"
+        />
+
+        <InputField
+          name="memberCardNumber"
+          control={control}
+          rules={{
+            maxLength: 20,
+            required: {
+              value: true,
+              message: 'Insert valid card number',
+            },
+          }}
+          label="Card number"
+          error={!!errors.memberCardNumber}
+          errorMessage="Insert valid card number"
+        />
+
+        <InputField
+          name="notes"
+          control={control}
+          rules={{
+            required: {
+              value: true,
+              message: 'Add notes',
+            },
+          }}
+          label="Notes"
+          error={!!errors.notes}
+          errorMessage="Insert notes"
+        />
+
         <Button
           data-testid="Submit"
           type="submit"
-- 
GitLab