fix(dashboard-v2): fix redirect after creating an account
This commit is contained in:
parent
efed2045af
commit
38407f6a31
|
@ -32,14 +32,16 @@ export const SignUpForm = ({ onSuccess, onFailure }) => (
|
||||||
validationSchema={registrationSchema}
|
validationSchema={registrationSchema}
|
||||||
onSubmit={async ({ email, password }, { setErrors }) => {
|
onSubmit={async ({ email, password }, { setErrors }) => {
|
||||||
try {
|
try {
|
||||||
await accountsService.post("user", {
|
const user = await accountsService
|
||||||
json: {
|
.post("user", {
|
||||||
email,
|
json: {
|
||||||
password,
|
email,
|
||||||
},
|
password,
|
||||||
});
|
},
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
|
||||||
onSuccess();
|
onSuccess(user);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
let isFormErrorSet = false;
|
let isFormErrorSet = false;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { navigate } from "gatsby";
|
|
||||||
import bytes from "pretty-bytes";
|
import bytes from "pretty-bytes";
|
||||||
|
|
||||||
import AuthLayout from "../../layouts/AuthLayout";
|
import AuthLayout from "../../layouts/AuthLayout";
|
||||||
|
@ -10,6 +9,7 @@ import { SignUpForm } from "../../components/forms/SignUpForm";
|
||||||
import { usePortalSettings } from "../../contexts/portal-settings";
|
import { usePortalSettings } from "../../contexts/portal-settings";
|
||||||
import { PlansProvider, usePlans } from "../../contexts/plans";
|
import { PlansProvider, usePlans } from "../../contexts/plans";
|
||||||
import { Metadata } from "../../components/Metadata";
|
import { Metadata } from "../../components/Metadata";
|
||||||
|
import { useUser } from "../../contexts/user";
|
||||||
|
|
||||||
const FreePortalHeader = () => {
|
const FreePortalHeader = () => {
|
||||||
const { plans } = usePlans();
|
const { plans } = usePlans();
|
||||||
|
@ -47,14 +47,14 @@ const State = {
|
||||||
const SignUpPage = () => {
|
const SignUpPage = () => {
|
||||||
const [state, setState] = useState(State.Pure);
|
const [state, setState] = useState(State.Pure);
|
||||||
const { settings } = usePortalSettings();
|
const { settings } = usePortalSettings();
|
||||||
|
const { mutate: refreshUserState } = useUser();
|
||||||
|
|
||||||
useEffect(() => {
|
const onUserCreated = useCallback(
|
||||||
if (state === State.Success) {
|
(newUser) => {
|
||||||
const timer = setTimeout(() => navigate(settings.isSubscriptionRequired ? "/upgrade" : "/"), 3000);
|
refreshUserState(newUser);
|
||||||
|
},
|
||||||
return () => clearTimeout(timer);
|
[refreshUserState]
|
||||||
}
|
);
|
||||||
}, [state, settings.isSubscriptionRequired]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PlansProvider>
|
<PlansProvider>
|
||||||
|
@ -70,7 +70,7 @@ const SignUpPage = () => {
|
||||||
|
|
||||||
{state !== State.Success && (
|
{state !== State.Success && (
|
||||||
<>
|
<>
|
||||||
<SignUpForm onSuccess={() => setState(State.Success)} onFailure={() => setState(State.Failure)} />
|
<SignUpForm onSuccess={onUserCreated} onFailure={() => setState(State.Failure)} />
|
||||||
|
|
||||||
<p className="text-sm text-center mt-8">
|
<p className="text-sm text-center mt-8">
|
||||||
Already have an account? <HighlightedLink to="/auth/login">Sign in</HighlightedLink>
|
Already have an account? <HighlightedLink to="/auth/login">Sign in</HighlightedLink>
|
||||||
|
@ -78,14 +78,6 @@ const SignUpPage = () => {
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{state === State.Success && (
|
|
||||||
<div>
|
|
||||||
<p className="text-primary font-semibold">Please check your inbox and confirm your email address.</p>
|
|
||||||
<p>You will be redirected to your dashboard shortly.</p>
|
|
||||||
<HighlightedLink to="/">Click here to go there now.</HighlightedLink>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{state === State.Failure && (
|
{state === State.Failure && (
|
||||||
<p className="text-error text-center">Something went wrong, please try again later.</p>
|
<p className="text-error text-center">Something went wrong, please try again later.</p>
|
||||||
)}
|
)}
|
||||||
|
|
Reference in New Issue