2020-04-13 21:16:07 +02:00
|
|
|
// @flow
|
|
|
|
import * as PAGES from 'constants/pages';
|
2021-10-17 10:36:14 +02:00
|
|
|
import * as SETTINGS from 'constants/settings';
|
2020-04-13 21:16:07 +02:00
|
|
|
import React from 'react';
|
2020-08-26 22:28:33 +02:00
|
|
|
import classnames from 'classnames';
|
2020-09-04 22:11:28 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2020-04-13 21:16:07 +02:00
|
|
|
import UserEmailNew from 'component/userEmailNew';
|
|
|
|
import UserEmailVerify from 'component/userEmailVerify';
|
|
|
|
import UserFirstChannel from 'component/userFirstChannel';
|
|
|
|
import UserChannelFollowIntro from 'component/userChannelFollowIntro';
|
|
|
|
import UserTagFollowIntro from 'component/userTagFollowIntro';
|
2020-09-04 22:11:28 +02:00
|
|
|
import YoutubeSync from 'page/youtubeSync';
|
2020-04-13 21:16:07 +02:00
|
|
|
import { DEFAULT_BID_FOR_FIRST_CHANNEL } from 'component/userFirstChannel/view';
|
2020-06-15 22:33:03 +02:00
|
|
|
import { YOUTUBE_STATUSES } from 'lbryinc';
|
|
|
|
import REWARDS from 'rewards';
|
2020-04-13 21:16:07 +02:00
|
|
|
import UserVerify from 'component/userVerify';
|
|
|
|
import Spinner from 'component/spinner';
|
|
|
|
import YoutubeTransferStatus from 'component/youtubeTransferStatus';
|
|
|
|
import useFetched from 'effects/use-fetched';
|
|
|
|
import Confetti from 'react-confetti';
|
2021-01-13 17:53:35 +01:00
|
|
|
import usePrevious from 'effects/use-previous';
|
2021-07-20 04:38:55 +02:00
|
|
|
import { SHOW_TAGS_INTRO } from 'config';
|
2020-04-13 21:16:07 +02:00
|
|
|
|
2020-09-04 22:11:28 +02:00
|
|
|
const REDIRECT_PARAM = 'redirect';
|
|
|
|
const REDIRECT_IMMEDIATELY_PARAM = 'immediate';
|
|
|
|
const STEP_PARAM = 'step';
|
|
|
|
|
2020-04-13 21:16:07 +02:00
|
|
|
type Props = {
|
|
|
|
user: ?User,
|
|
|
|
emailToVerify: ?string,
|
|
|
|
channels: ?Array<string>,
|
|
|
|
balance: ?number,
|
|
|
|
fetchingChannels: boolean,
|
|
|
|
claimingReward: boolean,
|
2020-08-27 19:56:18 +02:00
|
|
|
claimConfirmEmailReward: () => void,
|
|
|
|
claimNewUserReward: () => void,
|
2020-04-13 21:16:07 +02:00
|
|
|
claimedRewards: Array<Reward>,
|
|
|
|
youtubeChannels: Array<any>,
|
|
|
|
syncEnabled: boolean,
|
|
|
|
hasSynced: boolean,
|
|
|
|
syncingWallet: boolean,
|
|
|
|
creatingChannel: boolean,
|
2020-09-15 15:54:05 +02:00
|
|
|
setClientSetting: (string, boolean, ?boolean) => void,
|
2020-08-24 06:00:10 +02:00
|
|
|
followingAcknowledged: boolean,
|
|
|
|
tagsAcknowledged: boolean,
|
|
|
|
rewardsAcknowledged: boolean,
|
2020-09-04 22:11:28 +02:00
|
|
|
interestedInYoutubeSync: boolean,
|
|
|
|
doToggleInterestedInYoutubeSync: () => void,
|
2021-02-17 19:25:52 +01:00
|
|
|
prefsReady: boolean,
|
2020-04-13 21:16:07 +02:00
|
|
|
};
|
|
|
|
|
2020-08-27 19:56:18 +02:00
|
|
|
function UserSignUp(props: Props) {
|
2020-04-13 21:16:07 +02:00
|
|
|
const {
|
|
|
|
emailToVerify,
|
|
|
|
user,
|
|
|
|
claimingReward,
|
|
|
|
claimedRewards,
|
|
|
|
channels,
|
2020-08-27 19:56:18 +02:00
|
|
|
claimConfirmEmailReward,
|
|
|
|
claimNewUserReward,
|
2020-04-13 21:16:07 +02:00
|
|
|
balance,
|
|
|
|
youtubeChannels,
|
|
|
|
syncEnabled,
|
|
|
|
syncingWallet,
|
|
|
|
hasSynced,
|
|
|
|
fetchingChannels,
|
|
|
|
creatingChannel,
|
2020-08-24 06:00:10 +02:00
|
|
|
followingAcknowledged,
|
|
|
|
tagsAcknowledged,
|
|
|
|
rewardsAcknowledged,
|
|
|
|
setClientSetting,
|
2020-09-04 22:11:28 +02:00
|
|
|
interestedInYoutubeSync,
|
|
|
|
doToggleInterestedInYoutubeSync,
|
2021-02-17 19:25:52 +01:00
|
|
|
prefsReady,
|
2020-04-13 21:16:07 +02:00
|
|
|
} = props;
|
2020-09-04 22:11:28 +02:00
|
|
|
const {
|
|
|
|
location: { search, pathname },
|
|
|
|
replace,
|
|
|
|
} = useHistory();
|
2020-04-13 21:16:07 +02:00
|
|
|
const urlParams = new URLSearchParams(search);
|
2020-09-04 22:11:28 +02:00
|
|
|
const redirect = urlParams.get(REDIRECT_PARAM);
|
|
|
|
const step = urlParams.get(STEP_PARAM);
|
|
|
|
const shouldRedirectImmediately = urlParams.get(REDIRECT_IMMEDIATELY_PARAM);
|
2020-04-13 21:16:07 +02:00
|
|
|
const [initialSignInStep, setInitialSignInStep] = React.useState();
|
|
|
|
const hasVerifiedEmail = user && user.has_verified_email;
|
|
|
|
const rewardsApproved = user && user.is_reward_approved;
|
|
|
|
const isIdentityVerified = user && user.is_identity_verified;
|
2020-04-20 22:53:40 +02:00
|
|
|
const passwordSet = user && user.password_set;
|
2020-04-13 21:16:07 +02:00
|
|
|
const hasFetchedReward = useFetched(claimingReward);
|
2021-01-13 17:53:35 +01:00
|
|
|
const previousHasVerifiedEmail = usePrevious(hasVerifiedEmail);
|
2020-04-13 21:16:07 +02:00
|
|
|
const channelCount = channels ? channels.length : 0;
|
2021-02-17 19:25:52 +01:00
|
|
|
const hasClaimedEmailAward = claimedRewards.some((reward) => reward.reward_type === REWARDS.TYPE_CONFIRM_EMAIL);
|
2020-04-13 21:16:07 +02:00
|
|
|
const hasYoutubeChannels = youtubeChannels && Boolean(youtubeChannels.length);
|
|
|
|
const isYoutubeTransferComplete =
|
|
|
|
hasYoutubeChannels &&
|
2020-09-09 23:13:25 +02:00
|
|
|
youtubeChannels.every(
|
2021-02-17 19:25:52 +01:00
|
|
|
(channel) =>
|
2022-03-26 03:33:32 +01:00
|
|
|
channel.transfer_state === YOUTUBE_STATUSES.YOUTUBE_SYNC_COMPLETED_TRANSFER ||
|
2020-09-09 23:13:25 +02:00
|
|
|
channel.sync_status === YOUTUBE_STATUSES.YOUTUBE_SYNC_ABANDONDED
|
|
|
|
);
|
2020-04-13 21:16:07 +02:00
|
|
|
// Complexity warning
|
|
|
|
// We can't just check if we are currently fetching something
|
|
|
|
// We may want to keep a component rendered while something is being fetched, instead of replacing it with the large spinner
|
|
|
|
// The verbose variable names are an attempt to alleviate _some_ of the confusion from handling all edge cases that come from
|
|
|
|
// reward claiming, channel creation, account syncing, and youtube transfer
|
|
|
|
// The possible screens for the sign in flow
|
|
|
|
const showEmail = !hasVerifiedEmail;
|
2020-04-20 22:53:40 +02:00
|
|
|
const showEmailVerification = (emailToVerify && !hasVerifiedEmail) || (!hasVerifiedEmail && passwordSet);
|
2020-08-24 06:00:10 +02:00
|
|
|
const showUserVerification = hasVerifiedEmail && !rewardsApproved && !isIdentityVerified && !rewardsAcknowledged;
|
2020-04-13 21:16:07 +02:00
|
|
|
const showChannelCreation =
|
|
|
|
hasVerifiedEmail &&
|
2020-09-04 22:11:28 +02:00
|
|
|
((balance !== undefined &&
|
|
|
|
balance !== null &&
|
|
|
|
balance > DEFAULT_BID_FOR_FIRST_CHANNEL &&
|
|
|
|
channelCount === 0 &&
|
|
|
|
!hasYoutubeChannels) ||
|
|
|
|
interestedInYoutubeSync);
|
2020-04-13 21:16:07 +02:00
|
|
|
const showYoutubeTransfer = hasVerifiedEmail && hasYoutubeChannels && !isYoutubeTransferComplete;
|
2020-08-24 06:00:10 +02:00
|
|
|
const showFollowIntro = step === 'channels' || (hasVerifiedEmail && !followingAcknowledged);
|
2021-07-20 04:38:55 +02:00
|
|
|
const showTagsIntro = SHOW_TAGS_INTRO && (step === 'tags' || (hasVerifiedEmail && !tagsAcknowledged));
|
2020-09-15 18:34:45 +02:00
|
|
|
const canHijackSignInFlowWithSpinner = hasVerifiedEmail && !showFollowIntro && !showTagsIntro && !rewardsAcknowledged;
|
2022-03-04 14:12:03 +01:00
|
|
|
const showSpinnerForSync = syncingWallet && !hasSynced && balance === undefined;
|
|
|
|
const isCurrentlyFetchingSomething = fetchingChannels || claimingReward || showSpinnerForSync || creatingChannel;
|
2020-04-13 21:16:07 +02:00
|
|
|
const isWaitingForSomethingToFinish =
|
|
|
|
// If the user has claimed the email award, we need to wait until the balance updates sometime in the future
|
|
|
|
(!hasFetchedReward && !hasClaimedEmailAward) || (syncEnabled && !hasSynced);
|
|
|
|
const showLoadingSpinner =
|
|
|
|
canHijackSignInFlowWithSpinner && (isCurrentlyFetchingSomething || isWaitingForSomethingToFinish);
|
|
|
|
|
2020-08-24 06:00:10 +02:00
|
|
|
function setSettingAndSync(setting, value) {
|
2020-09-15 15:54:05 +02:00
|
|
|
setClientSetting(setting, value, true);
|
2020-08-24 06:00:10 +02:00
|
|
|
}
|
|
|
|
|
2020-08-27 19:56:18 +02:00
|
|
|
React.useEffect(() => {
|
2021-02-17 19:25:52 +01:00
|
|
|
if (previousHasVerifiedEmail === false && hasVerifiedEmail && prefsReady) {
|
2020-08-27 19:56:18 +02:00
|
|
|
setSettingAndSync(SETTINGS.FIRST_RUN_STARTED, true);
|
|
|
|
}
|
2021-02-17 19:25:52 +01:00
|
|
|
}, [hasVerifiedEmail, previousHasVerifiedEmail, prefsReady]);
|
2020-08-27 19:56:18 +02:00
|
|
|
|
2020-04-13 21:16:07 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
// Don't claim the reward if sync is enabled until after a sync has been completed successfully
|
|
|
|
// If we do it before, we could end up trying to sync a wallet with a non-zero balance which will fail to sync
|
|
|
|
const delayForSync = syncEnabled && !hasSynced;
|
|
|
|
|
|
|
|
if (hasVerifiedEmail && !hasClaimedEmailAward && !hasFetchedReward && !delayForSync) {
|
2020-08-27 19:56:18 +02:00
|
|
|
claimConfirmEmailReward();
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
2020-08-27 19:56:18 +02:00
|
|
|
}, [
|
|
|
|
hasVerifiedEmail,
|
|
|
|
claimConfirmEmailReward,
|
|
|
|
hasClaimedEmailAward,
|
|
|
|
hasFetchedReward,
|
|
|
|
syncEnabled,
|
|
|
|
hasSynced,
|
|
|
|
balance,
|
|
|
|
]);
|
2020-04-13 21:16:07 +02:00
|
|
|
|
|
|
|
// Loop through this list from the end, until it finds a matching component
|
|
|
|
// If it never finds one, assume the user has completed every step and redirect them
|
|
|
|
const SIGN_IN_FLOW = [
|
2020-09-04 22:11:28 +02:00
|
|
|
showEmail && (
|
|
|
|
<UserEmailNew
|
|
|
|
interestedInYoutubSync={interestedInYoutubeSync}
|
|
|
|
doToggleInterestedInYoutubeSync={doToggleInterestedInYoutubeSync}
|
|
|
|
/>
|
|
|
|
),
|
2020-04-13 21:16:07 +02:00
|
|
|
showEmailVerification && <UserEmailVerify />,
|
2020-08-24 06:00:10 +02:00
|
|
|
showUserVerification && (
|
|
|
|
<UserVerify
|
|
|
|
onSkip={() => {
|
|
|
|
setSettingAndSync(SETTINGS.REWARDS_ACKNOWLEDGED, true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
2020-09-04 22:11:28 +02:00
|
|
|
showChannelCreation &&
|
|
|
|
(interestedInYoutubeSync ? (
|
2020-09-15 16:23:00 +02:00
|
|
|
<YoutubeSync inSignUpFlow doToggleInterestedInYoutubeSync={doToggleInterestedInYoutubeSync} />
|
2020-09-04 22:11:28 +02:00
|
|
|
) : (
|
|
|
|
<UserFirstChannel doToggleInterestedInYoutubeSync={doToggleInterestedInYoutubeSync} />
|
|
|
|
)),
|
2020-04-13 21:16:07 +02:00
|
|
|
showFollowIntro && (
|
|
|
|
<UserChannelFollowIntro
|
|
|
|
onContinue={() => {
|
2020-09-04 22:11:28 +02:00
|
|
|
if (urlParams.get('reset_scroll')) {
|
|
|
|
urlParams.delete('reset_scroll');
|
|
|
|
urlParams.append('reset_scroll', '2');
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
|
|
|
|
2020-09-04 22:11:28 +02:00
|
|
|
urlParams.delete(STEP_PARAM);
|
|
|
|
|
2020-08-24 06:00:10 +02:00
|
|
|
setSettingAndSync(SETTINGS.FOLLOWING_ACKNOWLEDGED, true);
|
2020-09-04 22:11:28 +02:00
|
|
|
replace(`${pathname}?${urlParams.toString()}`);
|
2020-04-13 21:16:07 +02:00
|
|
|
}}
|
|
|
|
onBack={() => {
|
2020-09-04 22:11:28 +02:00
|
|
|
if (urlParams.get('reset_scroll')) {
|
|
|
|
urlParams.delete('reset_scroll');
|
|
|
|
urlParams.append('reset_scroll', '3');
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
|
|
|
|
2020-08-24 06:00:10 +02:00
|
|
|
setSettingAndSync(SETTINGS.FOLLOWING_ACKNOWLEDGED, false);
|
2020-09-04 22:11:28 +02:00
|
|
|
replace(`${pathname}?${urlParams.toString()}`);
|
2020-04-13 21:16:07 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
showTagsIntro && (
|
|
|
|
<UserTagFollowIntro
|
|
|
|
onContinue={() => {
|
2020-09-04 22:11:28 +02:00
|
|
|
let url = `/$/${PAGES.AUTH}?reset_scroll=1&${STEP_PARAM}=channels`;
|
2020-04-13 21:16:07 +02:00
|
|
|
if (redirect) {
|
2020-09-04 22:11:28 +02:00
|
|
|
url += `&${REDIRECT_PARAM}=${redirect}`;
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
|
|
|
if (shouldRedirectImmediately) {
|
2020-09-04 22:11:28 +02:00
|
|
|
url += `&${REDIRECT_IMMEDIATELY_PARAM}=true`;
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
|
|
|
|
2020-09-04 22:11:28 +02:00
|
|
|
replace(url);
|
2020-08-24 06:00:10 +02:00
|
|
|
setSettingAndSync(SETTINGS.TAGS_ACKNOWLEDGED, true);
|
2020-04-13 21:16:07 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
showYoutubeTransfer && (
|
|
|
|
<div>
|
|
|
|
<YoutubeTransferStatus /> <Confetti recycle={false} style={{ position: 'fixed' }} />
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
showLoadingSpinner && (
|
|
|
|
<div className="main--empty">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2020-08-26 22:28:33 +02:00
|
|
|
// $FlowFixMe
|
2020-04-13 21:16:07 +02:00
|
|
|
function getSignInStep() {
|
|
|
|
for (var i = SIGN_IN_FLOW.length - 1; i > -1; i--) {
|
|
|
|
const Component = SIGN_IN_FLOW[i];
|
|
|
|
if (Component) {
|
|
|
|
// If we want to redirect immediately,
|
|
|
|
// remember the first step so we can redirect once a new step has been reached
|
|
|
|
// Ignore the loading step
|
|
|
|
if (redirect && shouldRedirectImmediately) {
|
|
|
|
if (!initialSignInStep) {
|
|
|
|
setInitialSignInStep(i);
|
|
|
|
} else if (i !== initialSignInStep && i !== SIGN_IN_FLOW.length - 1) {
|
2020-09-04 22:11:28 +02:00
|
|
|
replace(redirect);
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-26 22:28:33 +02:00
|
|
|
const scrollableSteps = [2, 4, 5];
|
|
|
|
const isScrollable = scrollableSteps.includes(i);
|
|
|
|
return [Component, isScrollable];
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-26 22:49:05 +02:00
|
|
|
|
|
|
|
return [undefined, false];
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
|
|
|
|
2020-08-26 22:28:33 +02:00
|
|
|
const [componentToRender, isScrollable] = getSignInStep();
|
2020-04-13 21:16:07 +02:00
|
|
|
|
2020-08-27 19:56:18 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (!componentToRender) {
|
|
|
|
claimNewUserReward();
|
|
|
|
}
|
|
|
|
}, [componentToRender, claimNewUserReward]);
|
|
|
|
|
2020-04-13 21:16:07 +02:00
|
|
|
if (!componentToRender) {
|
2020-09-04 22:11:28 +02:00
|
|
|
replace(redirect || '/');
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
|
|
|
|
2020-08-26 22:28:33 +02:00
|
|
|
return (
|
|
|
|
<section className={classnames('main--contained', { 'main--hoisted': isScrollable })}>{componentToRender}</section>
|
|
|
|
);
|
2020-04-13 21:16:07 +02:00
|
|
|
}
|
|
|
|
|
2020-09-04 22:11:28 +02:00
|
|
|
export default UserSignUp;
|