mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
feat: sync the isVerified state of authed user
This commit is contained in:
@@ -1,27 +1,46 @@
|
||||
// @ts-nocheck
|
||||
import { useEffect } from 'react';
|
||||
import { useHistory, useParams } from 'react-router-dom';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useLocation, useHistory } from 'react-router-dom';
|
||||
import { useAuthSignUpVerify } from '@/hooks/query';
|
||||
import { AppToaster } from '@/components';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
|
||||
function useQuery() {
|
||||
const { search } = useLocation();
|
||||
return useMemo(() => new URLSearchParams(search), [search]);
|
||||
}
|
||||
|
||||
export default function EmailConfirmation() {
|
||||
const { mutateAsync: authSignupVerify } = useAuthSignUpVerify();
|
||||
const params = useParams();
|
||||
const history = useHistory();
|
||||
const query = useQuery();
|
||||
|
||||
const token = params.token;
|
||||
const email = params.email;
|
||||
const token = query.get('token');
|
||||
const email = query.get('email');
|
||||
|
||||
useEffect(() => {
|
||||
if (!token || !email) {
|
||||
history.push('register/email_confirmation');
|
||||
history.push('/auth/login');
|
||||
}
|
||||
}, [history, token, email]);
|
||||
|
||||
useEffect(() => {
|
||||
authSignupVerify(token, email)
|
||||
.then(() => {})
|
||||
.catch((error) => {});
|
||||
}, [token, email, authSignupVerify]);
|
||||
authSignupVerify({ token, email })
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: 'Your email has been verified, Congrats!',
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
history.push('/');
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
message: 'Something went wrong',
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
history.push('/');
|
||||
});
|
||||
}, [token, email, authSignupVerify, history]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user