Fakultas Ilmu Komputer UI

Commit a9224699 authored by Nabila Febri Viola's avatar Nabila Febri Viola
Browse files

[REFACTOR] Changes fetch to axios

parent 2b3cfb5f
......@@ -26,18 +26,3 @@ export const postUserLogout = () =>
detail: "SUCCESS",
},
})
export const postRegisterUser = async () =>
await fetch(`${BASE_API_URL}/auth/register-full/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: data,
})
.then(async response => {
return await response.json()
})
.then(async data => {
return data
})
......@@ -2,6 +2,7 @@ import React from "react"
import { Form } from "react-bootstrap"
import { useForm } from "react-hook-form"
import * as yup from "yup"
import axios from "axios"
import { BASE_API_URL } from "../config"
import ModalRegisterAccount from "./register-account"
......@@ -68,35 +69,28 @@ const ModalRegister = ({ show, handleClose }) => {
validationSchema: schema,
})
const onSubmit = async data => {
data =
'{"email": "' +
data.email +
'", "password": "' +
data.password +
'", "first_name": "' +
data.first_name +
'", "profile": ' +
JSON.stringify(data) +
"}"
await fetch(`${BASE_API_URL}/auth/register-full/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
await axios({
method: "post",
url: `${BASE_API_URL}/auth/register-full/`,
// url: "https://dblood-staging.netlify.app/auth/register-full/",
timeout: 60000,
data: {
email: data.email,
password: data.password,
first_name: data.first_name,
profile: data,
},
body: data,
})
.then(async response => {
return await response.json()
})
.then(async data => {
await window.alert(
"Silakan verifikasi email terlebih dahulu di" +
data.email +
.then(response => {
console.log(response.data)
window.alert(
"Silakan verifikasi email terlebih dahulu di " +
response.data.email +
" untuk login."
),
await location.reload()
location.reload()
})
.catch(error => console.error("timeout exceeded"))
}
return (
<>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment