2020-01-14 21:44:07 +01:00
|
|
|
// @flow
|
2020-08-26 22:28:33 +02:00
|
|
|
import { SITE_NAME } from 'config';
|
2020-01-14 21:44:07 +01:00
|
|
|
import * as PAGES from 'constants/pages';
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import ClaimPreview from 'component/claimPreview';
|
|
|
|
import Card from 'component/common/card';
|
2020-01-31 23:04:44 +01:00
|
|
|
import { buildURI, parseURI } from 'lbry-redux';
|
2020-06-15 22:33:03 +02:00
|
|
|
import { ERRORS } from 'lbryinc';
|
|
|
|
import REWARDS from 'rewards';
|
2020-01-31 23:04:44 +01:00
|
|
|
import { formatLbryUrlForWeb } from 'util/url';
|
2020-04-22 14:07:09 +02:00
|
|
|
import ChannelContent from 'component/channelContent';
|
2020-04-22 21:43:43 +02:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2020-01-14 21:44:07 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
user: any,
|
|
|
|
claimReward: () => void,
|
|
|
|
setReferrer: string => void,
|
|
|
|
referrerSetPending: boolean,
|
|
|
|
referrerSetError: string,
|
|
|
|
channelSubscribe: (sub: Subscription) => void,
|
|
|
|
history: { push: string => void },
|
|
|
|
rewards: Array<Reward>,
|
|
|
|
referrer: string,
|
|
|
|
fullUri: string,
|
|
|
|
isSubscribed: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
function Invited(props: Props) {
|
|
|
|
const {
|
|
|
|
user,
|
|
|
|
claimReward,
|
|
|
|
setReferrer,
|
|
|
|
referrerSetPending,
|
|
|
|
referrerSetError,
|
|
|
|
channelSubscribe,
|
|
|
|
history,
|
|
|
|
rewards,
|
|
|
|
fullUri,
|
|
|
|
referrer,
|
|
|
|
isSubscribed,
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const refUri = referrer && 'lbry://' + referrer.replace(':', '#');
|
2020-01-31 23:04:44 +01:00
|
|
|
const {
|
|
|
|
isChannel: referrerIsChannel,
|
|
|
|
claimName: referrerChannelName,
|
|
|
|
channelClaimId: referrerChannelClaimId,
|
|
|
|
} = parseURI(refUri);
|
|
|
|
const channelUri =
|
|
|
|
referrerIsChannel &&
|
|
|
|
formatLbryUrlForWeb(buildURI({ channelName: referrerChannelName, channelClaimId: referrerChannelClaimId }));
|
2020-01-14 21:44:07 +01:00
|
|
|
const rewardsApproved = user && user.is_reward_approved;
|
|
|
|
const hasVerifiedEmail = user && user.has_verified_email;
|
|
|
|
const referredRewardAvailable = rewards && rewards.some(reward => reward.reward_type === REWARDS.TYPE_REFEREE);
|
2020-04-02 17:38:09 +02:00
|
|
|
const redirect = channelUri || `/`;
|
2020-01-14 21:44:07 +01:00
|
|
|
|
|
|
|
// always follow if it's a channel
|
|
|
|
useEffect(() => {
|
|
|
|
if (fullUri && !isSubscribed) {
|
|
|
|
channelSubscribe({
|
|
|
|
channelName: parseURI(fullUri).claimName,
|
|
|
|
uri: fullUri,
|
|
|
|
});
|
|
|
|
}
|
2020-12-01 18:56:59 +01:00
|
|
|
}, [fullUri, isSubscribed, channelSubscribe]);
|
2020-01-14 21:44:07 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!referrerSetPending && hasVerifiedEmail) {
|
|
|
|
claimReward();
|
|
|
|
}
|
2020-12-01 18:56:59 +01:00
|
|
|
}, [referrerSetPending, hasVerifiedEmail, claimReward]);
|
2020-01-14 21:44:07 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (referrer) {
|
|
|
|
setReferrer(referrer.replace(':', '#'));
|
|
|
|
}
|
2020-12-01 18:56:59 +01:00
|
|
|
}, [referrer, setReferrer]);
|
2020-01-14 21:44:07 +01:00
|
|
|
|
|
|
|
function handleDone() {
|
2020-01-31 23:04:44 +01:00
|
|
|
history.push(redirect);
|
2020-01-14 21:44:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (referrerSetError === ERRORS.ALREADY_CLAIMED) {
|
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
title={__(`Whoa`)}
|
|
|
|
subtitle={
|
|
|
|
referrerIsChannel
|
|
|
|
? __(`You've already claimed your referrer, but we've followed this channel for you.`)
|
|
|
|
: __(`You've already claimed your referrer.`)
|
|
|
|
}
|
|
|
|
body={
|
|
|
|
referrerIsChannel && (
|
|
|
|
<div className="claim-preview--channel">
|
|
|
|
<ClaimPreview key={refUri} uri={refUri} actions={''} type={'small'} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
actions={
|
|
|
|
<div className="card__actions">
|
|
|
|
<Button button="primary" label={__('Done!')} onClick={handleDone} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (referrerSetError && referredRewardAvailable) {
|
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
title={__(`Welcome!`)}
|
|
|
|
subtitle={__(
|
|
|
|
`Something went wrong with your invite link. You can set and claim your invite reward after signing in.`
|
|
|
|
)}
|
|
|
|
actions={
|
|
|
|
<>
|
2020-04-13 21:16:07 +02:00
|
|
|
<p className="error__text">{__('Not a valid invite')}</p>
|
2020-01-14 21:44:07 +01:00
|
|
|
<div className="card__actions">
|
|
|
|
<Button
|
|
|
|
button="primary"
|
|
|
|
label={hasVerifiedEmail ? __('Verify') : __('Create Account')}
|
|
|
|
navigate={`/$/${PAGES.AUTH}?redirect=/$/${PAGES.REWARDS}`}
|
|
|
|
/>
|
|
|
|
<Button button="link" label={__('Explore')} onClick={handleDone} />
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rewardsApproved) {
|
2020-04-22 21:43:43 +02:00
|
|
|
const signUpButton = (
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={hasVerifiedEmail ? __(`Finish verification `) : __(`Create an account `)}
|
|
|
|
navigate={`/$/${PAGES.AUTH}?redirect=/$/${PAGES.INVITE}/${referrer}`}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-01-14 21:44:07 +01:00
|
|
|
return (
|
|
|
|
<Card
|
2020-08-26 22:28:33 +02:00
|
|
|
title={
|
|
|
|
referrerIsChannel
|
|
|
|
? __('%channel_name% invites you to the party!', { channel_name: referrerChannelName })
|
|
|
|
: __(`You're invited!`)
|
|
|
|
}
|
2020-01-14 21:44:07 +01:00
|
|
|
subtitle={
|
2020-04-22 21:43:43 +02:00
|
|
|
<p>
|
|
|
|
{referrerIsChannel ? (
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
channel_name: referrerChannelName,
|
|
|
|
signup_link: signUpButton,
|
2020-08-26 22:28:33 +02:00
|
|
|
SITE_NAME,
|
2020-04-22 21:43:43 +02:00
|
|
|
}}
|
|
|
|
>
|
2020-08-26 22:28:33 +02:00
|
|
|
%channel_name% is waiting for you on %SITE_NAME%. Create your account now.
|
2020-04-22 21:43:43 +02:00
|
|
|
</I18nMessage>
|
|
|
|
) : (
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
signup_link: signUpButton,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Content freedom and a present are waiting for you. %signup_link% to claim it.
|
|
|
|
</I18nMessage>
|
|
|
|
)}
|
|
|
|
</p>
|
2020-01-14 21:44:07 +01:00
|
|
|
}
|
|
|
|
body={
|
|
|
|
referrerIsChannel && (
|
|
|
|
<div className="claim-preview--channel">
|
2020-04-22 21:43:43 +02:00
|
|
|
<div className="section">
|
|
|
|
<ClaimPreview key={refUri} uri={refUri} actions={''} type={'small'} />
|
|
|
|
</div>
|
|
|
|
<div className="section">
|
|
|
|
<ChannelContent uri={fullUri} defaultPageSize={3} defaultInfiniteScroll={false} />
|
|
|
|
</div>
|
2020-01-14 21:44:07 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
actions={
|
2020-04-22 21:43:43 +02:00
|
|
|
<div className="section__actions">
|
2020-04-22 19:12:54 +02:00
|
|
|
<Button
|
2020-04-22 21:43:43 +02:00
|
|
|
button="primary"
|
2020-04-22 19:12:54 +02:00
|
|
|
label={hasVerifiedEmail ? __('Finish Account') : __('Create Account')}
|
2020-04-22 21:43:43 +02:00
|
|
|
navigate={`/$/${PAGES.AUTH}?redirect=/$/${PAGES.INVITE}/${referrer}`}
|
2020-04-22 19:12:54 +02:00
|
|
|
/>
|
2020-01-14 21:44:07 +01:00
|
|
|
<Button button="link" label={__('Skip')} onClick={handleDone} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
title={__(`Welcome!`)}
|
|
|
|
subtitle={referrerIsChannel ? __(`We've followed your invitee for you. Check them out!`) : __(`Congrats!`)}
|
|
|
|
body={
|
|
|
|
referrerIsChannel && (
|
|
|
|
<div className="claim-preview--channel">
|
|
|
|
<ClaimPreview key={refUri} uri={refUri} actions={''} type={'small'} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
actions={
|
2020-04-22 21:43:43 +02:00
|
|
|
<div className="section__actions">
|
2020-01-14 21:44:07 +01:00
|
|
|
<Button button="primary" label={__('Done')} onClick={handleDone} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Invited;
|