feat: use axios on sign up screen
This commit is contained in:
parent
9d13887c36
commit
ec444dd9e9
2 changed files with 19 additions and 7 deletions
|
|
@ -4,6 +4,8 @@ import { Controller, useForm } from 'react-hook-form';
|
|||
import * as yup from 'yup';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
|
||||
import { api } from '@services/api';
|
||||
|
||||
import BackgroundImg from '@assets/background.png';
|
||||
import Logo from '@assets/logo.svg';
|
||||
|
||||
|
|
@ -11,6 +13,7 @@ import { AuthNavigatorRoutesProps } from '@routes/auth.routes';
|
|||
|
||||
import { Input } from '@components/Input';
|
||||
import { Button } from '@components/Button';
|
||||
import axios from 'axios';
|
||||
|
||||
type FormData = {
|
||||
name: string;
|
||||
|
|
@ -40,13 +43,17 @@ export function SignUp() {
|
|||
resolver: yupResolver(signUpSchema),
|
||||
});
|
||||
|
||||
function handleSignUp({ name, email, password, confirmPassword }: FormData) {
|
||||
console.debug({
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
confirmPassword,
|
||||
});
|
||||
async function handleSignUp({ name, email, password }: FormData) {
|
||||
try {
|
||||
const response = await api.post('/users', { name, email, password });
|
||||
console.debug(response.data);
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
console.error(error.response?.data);
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const handleGoBack = () => {
|
||||
|
|
|
|||
5
src/services/api.ts
Normal file
5
src/services/api.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export const api = axios.create({
|
||||
baseURL: 'http://192.168.0.53:3333',
|
||||
});
|
||||
Loading…
Reference in a new issue