click signup redirects to the right place in jam-ui
This commit is contained in:
parent
624853c868
commit
753f35b24d
|
|
@ -57,9 +57,9 @@ const JKRegistrationForm = ({ hasLabel, jamTrack, jamTrackArtistName }) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const addJamTrackToCart = async () => {
|
const addJamTrackToCart = async () => {
|
||||||
try{
|
try {
|
||||||
await addToCart(jamTrack);
|
await addToCart(jamTrack);
|
||||||
}catch(error){
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -68,15 +68,15 @@ const JKRegistrationForm = ({ hasLabel, jamTrack, jamTrackArtistName }) => {
|
||||||
console.log('jamTrack', jamTrack);
|
console.log('jamTrack', jamTrack);
|
||||||
console.log('jamTrackArtistName', jamTrackArtistName);
|
console.log('jamTrackArtistName', jamTrackArtistName);
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
if(jamTrack){
|
if (jamTrack) {
|
||||||
console.log('adding jamtrack to cart');
|
console.log('adding jamtrack to cart');
|
||||||
addJamTrackToCart();
|
addJamTrackToCart();
|
||||||
}else if(jamTrackArtistName){
|
} else if (jamTrackArtistName) {
|
||||||
console.log('redirecting to jamtracks artist landing');
|
console.log('redirecting to jamtracks artist landing');
|
||||||
history.push(`/jamtracks?artist=${jamTrackArtistName}`);
|
history.push(`/jamtracks?artist=${jamTrackArtistName}`);
|
||||||
}else{
|
} else {
|
||||||
console.log('redirecting to downloads');
|
console.log('redirecting to profile');
|
||||||
history.push('/public/downloads');
|
history.push('/profile');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [currentUser, jamTrack, jamTrackArtistName]);
|
}, [currentUser, jamTrack, jamTrackArtistName]);
|
||||||
|
|
@ -146,7 +146,7 @@ const JKRegistrationForm = ({ hasLabel, jamTrack, jamTrackArtistName }) => {
|
||||||
|
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<Button color="primary" block className="mt-3" disabled={isDisabled}>
|
<Button color="primary" block className="mt-3" disabled={isDisabled}>
|
||||||
{t('signup')}
|
{t('signup')}
|
||||||
</Button>
|
</Button>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,27 @@
|
||||||
import React, { Fragment } from 'react';
|
import React, { Fragment, useEffect } from 'react';
|
||||||
import { Col, Row } from 'reactstrap';
|
import { Col, Row } from 'reactstrap';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link, useHistory, useLocation } from 'react-router-dom';
|
||||||
import LoginForm from '../LoginForm';
|
import LoginForm from '../LoginForm';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useAuth } from '../../../context/UserAuth';
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
const { t } = useTranslation('auth');
|
const { t } = useTranslation('auth');
|
||||||
|
const { isAuthenticated, isLoading } = useAuth();
|
||||||
|
const history = useHistory();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isLoading && isAuthenticated) {
|
||||||
|
const { from } = location.state || { from: { pathname: '/profile' } };
|
||||||
|
const finalDestination = from.pathname === '/' ? { pathname: '/profile' } : from;
|
||||||
|
history.replace(finalDestination);
|
||||||
|
}
|
||||||
|
}, [isAuthenticated, isLoading, history, location]);
|
||||||
|
|
||||||
|
if (isLoading || isAuthenticated) {
|
||||||
|
return null; // Or a loading spinner
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue