From d7fe0406d1a55ec36fb85ce609d55c691051703c Mon Sep 17 00:00:00 2001
From: Alberto Defendi <1369-ahl-berto@users.noreply.gitlab.inf.unibz.it>
Date: Tue, 4 May 2021 14:53:02 +0200
Subject: [PATCH] Include data asked by backend

---
 .../AuthUser/SignUpForm/SignUpForm.tsx        | 80 +++++++++++++------
 1 file changed, 57 insertions(+), 23 deletions(-)

diff --git a/src/components/AuthUser/SignUpForm/SignUpForm.tsx b/src/components/AuthUser/SignUpForm/SignUpForm.tsx
index 11e6f95..eebc44f 100644
--- a/src/components/AuthUser/SignUpForm/SignUpForm.tsx
+++ b/src/components/AuthUser/SignUpForm/SignUpForm.tsx
@@ -4,25 +4,39 @@ import { Button } from '@material-ui/core';
 import { InputField } from 'components/AuthUser/InputField/InputField';
 import { useStyles } from 'components/AuthUser/SignUpForm/useStyles';
 import axios from 'axios';
-
+// TODO: Data validation
+// TODO: Replace notes with big input field
 export const SignUpForm: FC = () => {
   type FormData = {
-    firstName: string;
-    lastName: string;
+    user: {
+      username: string;
+      password: string;
+      firstName: string;
+      lastName: string;
+      email: string;
+    };
     phoneNumber: number;
-    homeAddress: string;
-    cardNumber: number;
-    email: string;
-    password: string;
+    homeAddress: {
+      address: string;
+    };
+    memberCardIssuer: {
+      name: string;
+    };
+    memberCardNumber: number;
+    notes: string;
   };
 
   const { control, errors, handleSubmit } = useForm<FormData>();
 
   const onSubmit: SubmitHandler<FormData> = (values: FormData) => {
     axios.post(
-      '/api/web/',
+      '/api/web/seniors/',
       {
-        values,
+        user: values.user,
+        phone_number: values.phoneNumber,
+        home_address: values.homeAddress.address,
+        member_card_issuer: values.memberCardIssuer,
+        notes: values.notes,
       },
       {
         headers: {
@@ -51,7 +65,7 @@ export const SignUpForm: FC = () => {
             },
           }}
           label="First name"
-          error={!!errors.firstName}
+          error={!!errors.user?.firstName}
           errorMessage="Insert firstName"
         />
 
@@ -66,7 +80,7 @@ export const SignUpForm: FC = () => {
             },
           }}
           label="Last name"
-          error={!!errors.lastName}
+          error={!!errors.user?.lastName}
           errorMessage="Insert lastName"
         />
 
@@ -74,7 +88,6 @@ export const SignUpForm: FC = () => {
           name="phoneNumber"
           control={control}
           rules={{
-            validate: (value: string) => /^[/d]$/.test(value),
             required: {
               value: true,
               message: 'phoneNumber is not valid',
@@ -84,35 +97,56 @@ export const SignUpForm: FC = () => {
           error={!!errors.phoneNumber}
           errorMessage="Insert phoneNumber"
         />
+        <InputField
+          name="memberCardIssuer"
+          control={control}
+          rules={{
+            validate: (value: string) => /^[A-Za-z]$/.test(value),
+            required: {
+              value: true,
+              message: 'memberCardIssuer is not valid',
+            },
+          }}
+          label="Member card issuer"
+          error={!!errors.memberCardIssuer?.name}
+          errorMessage="Insert memberCardIssuer"
+        />
 
         <InputField
-          name="cardNumber"
+          name="memberCardNumber"
           control={control}
           rules={{
-            validate: (value: string) => /^[/d]$/.test(value),
             required: {
               value: true,
-              message: 'cardNumber is not valid',
+              message: 'memberCardNumber is not valid',
             },
           }}
           label="Card number"
-          error={!!errors.cardNumber}
-          errorMessage="Insert cardNumber"
+          error={!!errors.memberCardNumber}
+          errorMessage="Insert memberCardNumber"
         />
 
         <InputField
-          name="homeAddress"
+          name="address"
           control={control}
           rules={{
             validate: (value: string) => /^[A-Za-z]$/.test(value),
             required: {
               value: true,
-              message: 'homeAddress is not valid',
+              message: 'address is not valid',
             },
           }}
           label="Home address"
-          error={!!errors.homeAddress}
-          errorMessage="Insert homeAddress"
+          error={!!errors.homeAddress?.address}
+          errorMessage="Insert address"
+        />
+
+        <InputField
+          name="notes"
+          control={control}
+          label="Notes"
+          error={!!errors.notes}
+          errorMessage="Insert valid password"
         />
 
         <InputField
@@ -127,7 +161,7 @@ export const SignUpForm: FC = () => {
             },
           }}
           label="Email"
-          error={!!errors.email}
+          error={!!errors.user?.email}
           errorMessage="Insert email"
         />
 
@@ -143,7 +177,7 @@ export const SignUpForm: FC = () => {
             },
           }}
           label="Password"
-          error={!!errors.password}
+          error={!!errors.user?.password}
           errorMessage="Insert valid password"
         />
 
-- 
GitLab