feat: migrate sign up screen to react-hook-form
This commit is contained in:
parent
f0c34e2044
commit
f21cd9b7f9
1 changed files with 53 additions and 29 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { useState } from 'react';
|
|
||||||
import { Center, Heading, Image, ScrollView, Text, VStack } from '@gluestack-ui/themed';
|
import { Center, Heading, Image, ScrollView, Text, VStack } from '@gluestack-ui/themed';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
|
import { Controller, useForm } from 'react-hook-form';
|
||||||
|
|
||||||
import BackgroundImg from '@assets/background.png';
|
import BackgroundImg from '@assets/background.png';
|
||||||
import Logo from '@assets/logo.svg';
|
import Logo from '@assets/logo.svg';
|
||||||
|
|
@ -13,18 +13,10 @@ import { Button } from '@components/Button';
|
||||||
export function SignUp() {
|
export function SignUp() {
|
||||||
const navigation = useNavigation<AuthNavigatorRoutesProps>();
|
const navigation = useNavigation<AuthNavigatorRoutesProps>();
|
||||||
|
|
||||||
const [name, setName] = useState('');
|
const { control } = useForm();
|
||||||
const [email, setEmail] = useState('');
|
|
||||||
const [password, setPassword] = useState('');
|
|
||||||
const [confirmPassword, setConfirmPassword] = useState('');
|
|
||||||
|
|
||||||
function handleSignUp() {
|
function handleSignUp() {
|
||||||
console.debug({
|
// do something again
|
||||||
name,
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
confirmPassword,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleGoBack = () => {
|
const handleGoBack = () => {
|
||||||
|
|
@ -54,28 +46,60 @@ export function SignUp() {
|
||||||
<Center gap="$2" flex={1}>
|
<Center gap="$2" flex={1}>
|
||||||
<Heading color="$gray100">Crie sua a conta</Heading>
|
<Heading color="$gray100">Crie sua a conta</Heading>
|
||||||
|
|
||||||
<Input placeholder="Nome" autoCorrect={false} onChangeText={setName} />
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="name"
|
||||||
|
render={({ field: { onChange, value } }) => (
|
||||||
|
<Input
|
||||||
|
placeholder="Nome"
|
||||||
|
autoCorrect={false}
|
||||||
|
onChangeText={onChange}
|
||||||
|
value={value}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="email"
|
||||||
|
render={({ field: { onChange, value } }) => (
|
||||||
<Input
|
<Input
|
||||||
placeholder="E-mail"
|
placeholder="E-mail"
|
||||||
keyboardType="email-address"
|
keyboardType="email-address"
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
autoCorrect={false}
|
autoCorrect={false}
|
||||||
onChangeText={setEmail}
|
onChangeText={onChange}
|
||||||
|
value={value}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="password"
|
||||||
|
render={({ field: { onChange, value } }) => (
|
||||||
<Input
|
<Input
|
||||||
placeholder="Senha"
|
placeholder="Senha"
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
secureTextEntry
|
secureTextEntry
|
||||||
onChangeText={setPassword}
|
onChangeText={onChange}
|
||||||
|
value={value}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="confirmPassword"
|
||||||
|
render={({ field: { onChange, value } }) => (
|
||||||
<Input
|
<Input
|
||||||
placeholder="Confirme a senha"
|
placeholder="Confirme a senha"
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
secureTextEntry
|
secureTextEntry
|
||||||
onChangeText={setConfirmPassword}
|
onChangeText={onChange}
|
||||||
|
value={value}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button title="Criar e acessar" onPress={handleSignUp} />
|
<Button title="Criar e acessar" onPress={handleSignUp} />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue