diff --git a/src/components/AuthUser/SignUpForm/SignUpForm.tsx b/src/components/AuthUser/SignUpForm/SignUpForm.tsx index eebc44fda67efba7ece0a008ecf78242cad30f0f..b38fdabc87a838ad7838bf22f93bc0ab395eb6cf 100644 --- a/src/components/AuthUser/SignUpForm/SignUpForm.tsx +++ b/src/components/AuthUser/SignUpForm/SignUpForm.tsx @@ -8,42 +8,53 @@ import axios from 'axios'; // TODO: Replace notes with big input field export const SignUpForm: FC = () => { type FormData = { - user: { - username: string; - password: string; - firstName: string; - lastName: string; - email: string; - }; - phoneNumber: number; - homeAddress: { - address: string; - }; - memberCardIssuer: { - name: string; - }; - memberCardNumber: number; - notes: string; + username: string; + password: string; + firstName: string; + lastName: string; + email: string; }; - const { control, errors, handleSubmit } = useForm<FormData>(); + const defaultValues: FormData = { + username: '', + password: '', + firstName: '', + lastName: '', + email: '', + }; + + const { control, errors, handleSubmit } = useForm<FormData>({ + defaultValues, + }); const onSubmit: SubmitHandler<FormData> = (values: FormData) => { - axios.post( - '/api/web/seniors/', - { - user: values.user, - phone_number: values.phoneNumber, - home_address: values.homeAddress.address, - member_card_issuer: values.memberCardIssuer, - notes: values.notes, - }, - { - headers: { - 'Content-Type': 'application/json', + 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', }, - }, - ); + { + headers: { + 'Content-Type': 'application/json', + }, + }, + ) + .then((res) => console.log(res)); }; const classes = useStyles(); @@ -54,101 +65,6 @@ export const SignUpForm: FC = () => { onSubmit={handleSubmit(onSubmit)} data-testid="Form" > - <InputField - name="firstName" - control={control} - rules={{ - validate: (value: string) => /^[A-Za-z]$/.test(value), - required: { - value: true, - message: 'firstName is not valid', - }, - }} - label="First name" - error={!!errors.user?.firstName} - errorMessage="Insert firstName" - /> - - <InputField - name="lastName" - control={control} - rules={{ - validate: (value: string) => /^[A-Za-z]$/.test(value), - required: { - value: true, - message: 'lastName is not valid', - }, - }} - label="Last name" - error={!!errors.user?.lastName} - errorMessage="Insert lastName" - /> - - <InputField - name="phoneNumber" - control={control} - rules={{ - required: { - value: true, - message: 'phoneNumber is not valid', - }, - }} - label="Phone number" - 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="memberCardNumber" - control={control} - rules={{ - required: { - value: true, - message: 'memberCardNumber is not valid', - }, - }} - label="Card number" - error={!!errors.memberCardNumber} - errorMessage="Insert memberCardNumber" - /> - - <InputField - name="address" - control={control} - rules={{ - validate: (value: string) => /^[A-Za-z]$/.test(value), - required: { - value: true, - message: 'address is not valid', - }, - }} - label="Home address" - error={!!errors.homeAddress?.address} - errorMessage="Insert address" - /> - - <InputField - name="notes" - control={control} - label="Notes" - error={!!errors.notes} - errorMessage="Insert valid password" - /> - <InputField name="email" control={control} @@ -161,7 +77,7 @@ export const SignUpForm: FC = () => { }, }} label="Email" - error={!!errors.user?.email} + error={!!errors.email} errorMessage="Insert email" /> @@ -177,10 +93,9 @@ export const SignUpForm: FC = () => { }, }} label="Password" - error={!!errors.user?.password} + error={!!errors.password} errorMessage="Insert valid password" /> - <Button data-testid="Submit" type="submit"