Fakultas Ilmu Komputer UI

Verified Commit 2a404a42 authored by Giovan Isa Musthofa's avatar Giovan Isa Musthofa
Browse files

[CHORES] Add simple error handling for modal-register.js

parent 460c3948
Pipeline #39382 passed with stages
in 5 minutes and 19 seconds
......@@ -6,6 +6,18 @@ axios.defaults.baseURL = BASE_API_URL
export const getListJadwalDonor = date =>
axios.get(`/donor/jadwal/?date=${date}`)
export const postRegisterFull = data =>
axios.post(
"/auth/register-full/",
{
email: data.email,
password: data.password,
first_name: data.first_name,
profile: data,
},
{ mode: "cors" }
)
export const postUserLogin = (email, password) =>
axios.post(
"/auth/access/",
......
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 { postRegisterFull } from "../api"
import ModalRegisterAccount from "./register-account"
......@@ -69,27 +67,25 @@ const ModalRegister = ({ show, handleClose }) => {
validationSchema: schema,
})
const onSubmit = async data => {
await axios({
method: "post",
url: `${BASE_API_URL}/auth/register-full/`,
timeout: 60000,
data: {
email: data.email,
password: data.password,
first_name: data.first_name,
profile: data,
},
postRegisterFull({
email: data.email,
password: data.password,
first_name: data.first_name,
profile: data,
})
.then(response => {
console.log(response.data)
window.alert(
"Silakan verifikasi email terlebih dahulu di " +
response.data.email +
" untuk login."
),
location.reload()
)
})
.catch(error => {
console.log(error)
if (error.response) {
window.alert(JSON.stringify(error.response.data))
}
})
.catch(error => console.error("timeout exceeded"))
}
return (
<>
......
......@@ -20,6 +20,7 @@ const AuthProvider = props => {
setUser(user)
} catch (error) {
// do nothing if the token is invalid
console.log(error)
}
}
useEffect(() => {
......
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