Fakultas Ilmu Komputer UI

Commit fd988c5d authored by Muhammad Fairuzi Teguh's avatar Muhammad Fairuzi Teguh
Browse files

[REFACTOR] fix handleSuccess to appear after completing google profile

parent ad7bee5c
Pipeline #49761 failed with stages
in 2 minutes and 51 seconds
This diff is collapsed.
......@@ -13,7 +13,7 @@
"@material-ui/pickers": "^3.2.10",
"apexcharts": "^3.18.1",
"bootstrap": "^4.4.1",
"gatsby": "^2.19.7",
"gatsby": "^2.18.25",
"gatsby-plugin-offline": "^3.0.32",
"gatsby-plugin-page-creator": "^2.2.4",
"gatsby-plugin-react-helmet": "^3.1.21",
......@@ -56,7 +56,7 @@
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^1.7.0",
"gatsby-cli": "^2.10.2",
"gatsby-cli": "^2.10.13",
"identity-obj-proxy": "^3.0.0",
"jest": "^25.1.0",
"prettier": "^1.19.1",
......
......@@ -7,7 +7,7 @@ import ModalCompleteProfile from "./complete-profile"
import { withAuthenticated } from "./authenticated-only"
import moment from "moment"
const ModalGoogleCompleteProfile = ({ show, handleClose }) => {
const ModalGoogleCompleteProfile = ({ show, handleClose, handleSuccess }) => {
const { user, logout, getAndSetUserProfile } = useAuth()
const { control, register, handleSubmit, errors } = useForm({
......@@ -24,10 +24,10 @@ const ModalGoogleCompleteProfile = ({ show, handleClose }) => {
data.birthdate = moment(data.birthdate).format("YYYY-MM-DD")
await postUserProfile(data)
.then(() => {
.then(async () => {
window.alert("Profil Anda sudah disimpan.")
getAndSetUserProfile()
handleClose()
const newUser = await getAndSetUserProfile()
handleSuccess(newUser)
})
.catch(error => {
if (error.response) {
......
......@@ -16,8 +16,8 @@ const ModalLogin = ({ show, handleClose, handleSuccess }) => {
setLoginError(null)
setIsLoadingLogin(true)
try {
await login(data.email, data.password)
handleSuccess()
const user = await login(data.email, data.password)
handleSuccess(user)
} catch (error) {
const message = error.response
? "Email atau password salah."
......@@ -34,8 +34,8 @@ const ModalLogin = ({ show, handleClose, handleSuccess }) => {
setLoginError(null)
setIsLoadingLogin(true)
try {
await loginOAuth(data.tokenId)
handleSuccess()
const user = await loginOAuth(data.tokenId)
handleSuccess(user)
} catch (error) {
const message = error.response
? error.response.data.detail
......
......@@ -36,6 +36,7 @@ const AuthProvider = ({ children, ...otherProps }) => {
} else {
toggleShowModalGoogleCompleteProfile(false)
}
return newUser
} catch (error) {
// do nothing if the token is invalid
console.log(error)
......@@ -52,7 +53,7 @@ const AuthProvider = ({ children, ...otherProps }) => {
const refresh_token = result.data.refresh
setRefreshToken(refresh_token)
axios.defaults.headers.common = { Authorization: `Bearer ${access_token}` }
getAndSetUserProfile()
return await getAndSetUserProfile()
}
const loginOAuth = async tokenId => {
const result = await postUserLoginOAuth(tokenId)
......@@ -60,7 +61,7 @@ const AuthProvider = ({ children, ...otherProps }) => {
const refresh_token = result.data.refresh
setRefreshToken(refresh_token)
axios.defaults.headers.common = { Authorization: `Bearer ${access_token}` }
getAndSetUserProfile()
return await getAndSetUserProfile()
}
const loginToken = access_token => {
axios.defaults.headers.common = { Authorization: `Bearer ${access_token}` }
......@@ -132,9 +133,12 @@ const AuthProvider = ({ children, ...otherProps }) => {
<ModalLogin
show={showModalLogin}
handleClose={toggleShowModalLogin}
handleSuccess={() => {
handleSuccess={newUser => {
toggleShowModalLogin()
nextActionLogin()
if (newUser.profile.body_weight) {
nextActionLogin()
setNextActionLogin(() => noop)
}
}}
/>
<ModalRegister
......@@ -148,6 +152,11 @@ const AuthProvider = ({ children, ...otherProps }) => {
<ModalGoogleCompleteProfile
show={showModalGoogleCompleteProfile}
handleClose={toggleShowModalGoogleCompleteProfile}
handleSuccess={newUser => {
toggleShowModalGoogleCompleteProfile(false)
nextActionLogin()
setNextActionLogin(() => noop)
}}
/>
<ModalEventDonorSubmission
show={showModalEventDonorSubmission}
......
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