make invite redirect to channel if appropriate

This commit is contained in:
jessop 2020-01-31 17:04:44 -05:00 committed by Jeremy Kauffman
parent e290cec7b8
commit d44e3e2783

View file

@ -4,8 +4,9 @@ import React, { useEffect } from 'react';
import Button from 'component/button'; import Button from 'component/button';
import ClaimPreview from 'component/claimPreview'; import ClaimPreview from 'component/claimPreview';
import Card from 'component/common/card'; import Card from 'component/common/card';
import { parseURI } from 'lbry-redux'; import { buildURI, parseURI } from 'lbry-redux';
import { rewards as REWARDS, ERRORS } from 'lbryinc'; import { rewards as REWARDS, ERRORS } from 'lbryinc';
import { formatLbryUrlForWeb } from 'util/url';
type Props = { type Props = {
user: any, user: any,
@ -37,10 +38,18 @@ function Invited(props: Props) {
} = props; } = props;
const refUri = referrer && 'lbry://' + referrer.replace(':', '#'); const refUri = referrer && 'lbry://' + referrer.replace(':', '#');
const { isChannel: referrerIsChannel, claimName: referrerChannelName } = parseURI(refUri); const {
isChannel: referrerIsChannel,
claimName: referrerChannelName,
channelClaimId: referrerChannelClaimId,
} = parseURI(refUri);
const channelUri =
referrerIsChannel &&
formatLbryUrlForWeb(buildURI({ channelName: referrerChannelName, channelClaimId: referrerChannelClaimId }));
const rewardsApproved = user && user.is_reward_approved; const rewardsApproved = user && user.is_reward_approved;
const hasVerifiedEmail = user && user.has_verified_email; const hasVerifiedEmail = user && user.has_verified_email;
const referredRewardAvailable = rewards && rewards.some(reward => reward.reward_type === REWARDS.TYPE_REFEREE); const referredRewardAvailable = rewards && rewards.some(reward => reward.reward_type === REWARDS.TYPE_REFEREE);
const redirect = channelUri || `/$/${PAGES.HOME}`;
// always follow if it's a channel // always follow if it's a channel
useEffect(() => { useEffect(() => {
@ -65,7 +74,7 @@ function Invited(props: Props) {
}, [referrer]); }, [referrer]);
function handleDone() { function handleDone() {
history.push(`/$/${PAGES.DISCOVER}`); history.push(redirect);
} }
if (referrerSetError === ERRORS.ALREADY_CLAIMED) { if (referrerSetError === ERRORS.ALREADY_CLAIMED) {