<commit_before>import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Button, Title, useLoading, TextLoader, VpnLogo, Href, FullLoader, SupportDropdown } from 'react-components';
import AccountStep from './AccountStep/AccountStep';
import PlanStep from './PlanStep/PlanStep';
import useSignup from './useSignup';
import { c } from 'ttag';
import VerificationStep from './VerificationStep/VerificationStep';
import PaymentStep from './PaymentStep/PaymentStep';
import { PLAN, VPN_PLANS, BEST_DEAL_PLANS, PLAN_BUNDLES } from './plans';
import { CYCLE } from 'proton-shared/lib/constants';
import PlanDetails from './SelectedPlan/PlanDetails';
import PlanUpsell from './SelectedPlan/PlanUpsell';
import useVerification from './VerificationStep/useVerification';
import { checkCookie } from 'proton-shared/lib/helpers/cookies';
import MobileRedirectionStep from './MobileRedirectionStep/MobileRedirectionStep';
import PublicPage from '../../components/page/PublicPage';

const SignupState = {
    Plan: 'plan',
    Account: 'account',
    Verification: 'verification',
    Payment: 'payment',
    MobileRedirection: 'mobile-redirection'
};

const BRAVE_COOKIE = '1397';
const BESTDEAL_COOKIE = 'bestdeal';

// TODO: Flexible urls and plans for reuse between project
const SignupContainer = ({ match, history, onLogin }) => {
    const searchParams = new URLSearchParams(history.location.search);
    const from = searchParams.get('from');
    const couponCode = searchParams.get('coupon');
    const currency = searchParams.get('currency');
    const billingCycle = Number(searchParams.get('billing'));

    const historyState = history.location.state || {};
    const preSelectedPlan = searchParams.get('plan') || historyState.preSelectedPlan;
    const invite = historyState.invite;
    const coupon =
        historyState.coupon ||
        (couponCode && {
            code: couponCode,
            plan: preSelectedPlan,
            cycle: billingCycle
        });

    const redirectToMobile = (from || historyState.from) === 'mobile';
    const hasCookieOffer = checkCookie('offer', BESTDEAL_COOKIE) || checkCookie('offer', BRAVE_COOKIE);
    const availablePlans =
        hasCookieOffer && !redirectToMobile ? BEST_DEAL_PLANS : PLAN_BUNDLES[preSelectedPlan] || VPN_PLANS;

    useEffect(() => {
        // Always start at plans, or account if plan is preselected
        if (preSelectedPlan && from === 'pricing') {
            history.replace(`/signup/${SignupState.Account}`, {
                coupon,
                invite,
                preSelectedPlan
            });
        } else {
            history.replace('/signup', {
                coupon,
                invite,
                from,
                preSelectedPlan
            });
        }
    }, []);

    const signupState = match.params.step;
    const [upsellDone, setUpsellDone] = useState(false);
    const [creatingAccount, withCreateLoading] = useLoading(false);

    const goToStep = (step) =>
        history.push(`/signup/${step}`, {
            coupon,
            invite,
            preSelectedPlan
        });

    const handleLogin = (data) => {
        if (redirectToMobile) {
            return goToStep(SignupState.MobileRedirection);
        }
        return onLogin({ ...data, pathname: '/downloads' });
    };

    const {
        model,
        setModel,
        signup,
        selectedPlan,
        makePayment,
        signupAvailability,
        getPlanByName,
        isLoading,
        appliedCoupon,
        appliedInvite
    } = useSignup(
        handleLogin,
        { coupon, invite, availablePlans },
        {
            planName: preSelectedPlan,
            cycle: billingCycle,
            currency
        }
    );
    const { verify, requestCode } = useVerification();<commit_msg>[VPNFE-83] Redirect to Android at the end of signup flow<commit_after>import React, { useState, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { Button, Title, useLoading, TextLoader, VpnLogo, Href, FullLoader, SupportDropdown } from 'react-components';
import AccountStep from './AccountStep/AccountStep';
import PlanStep from './PlanStep/PlanStep';
import useSignup from './useSignup';
import { c } from 'ttag';
import VerificationStep from './VerificationStep/VerificationStep';
import PaymentStep from './PaymentStep/PaymentStep';
import { PLAN, VPN_PLANS, BEST_DEAL_PLANS, PLAN_BUNDLES } from './plans';
import { CYCLE } from 'proton-shared/lib/constants';
import PlanDetails from './SelectedPlan/PlanDetails';
import PlanUpsell from './SelectedPlan/PlanUpsell';
import useVerification from './VerificationStep/useVerification';
import { checkCookie } from 'proton-shared/lib/helpers/cookies';
import MobileRedirectionStep from './MobileRedirectionStep/MobileRedirectionStep';
import PublicPage from '../../components/page/PublicPage';

const SignupState = {
    Plan: 'plan',
    Account: 'account',
    Verification: 'verification',
    Payment: 'payment',
    MobileRedirection: 'mobile-redirection'
};

const BRAVE_COOKIE = '1397';
const BESTDEAL_COOKIE = 'bestdeal';

// TODO: Flexible urls and plans for reuse between project
const SignupContainer = ({ match, history, onLogin }) => {
    const searchParams = new URLSearchParams(history.location.search);
    const from = searchParams.get('from');
    const couponCode = searchParams.get('coupon');
    const currency = searchParams.get('currency');
    const billingCycle = Number(searchParams.get('billing'));

    const historyState = history.location.state || {};
    const preSelectedPlan = searchParams.get('plan') || historyState.preSelectedPlan;
    const invite = historyState.invite;
    const redirectToMobileRef = useRef((from || historyState.from) === 'mobile');
    const coupon =
        historyState.coupon ||
        (couponCode && {
            code: couponCode,
            plan: preSelectedPlan,
            cycle: billingCycle
        });

    const hasCookieOffer = checkCookie('offer', BESTDEAL_COOKIE) || checkCookie('offer', BRAVE_COOKIE);
    const availablePlans =
        hasCookieOffer && !redirectToMobileRef.current ? BEST_DEAL_PLANS : PLAN_BUNDLES[preSelectedPlan] || VPN_PLANS;

    useEffect(() => {
        // Always start at plans, or account if plan is preselected
        if (preSelectedPlan && from === 'pricing') {
            history.replace(`/signup/${SignupState.Account}`, {
                coupon,
                invite,
                preSelectedPlan
            });
        } else {
            history.replace('/signup', {
                coupon,
                invite,
                from,
                preSelectedPlan
            });
        }
    }, []);

    const signupState = match.params.step;
    const [upsellDone, setUpsellDone] = useState(false);
    const [creatingAccount, withCreateLoading] = useLoading(false);

    const goToStep = (step) =>
        history.push(`/signup/${step}`, {
            coupon,
            invite,
            preSelectedPlan
        });

    const handleLogin = (data) => {
        if (redirectToMobileRef.current) {
            return goToStep(SignupState.MobileRedirection);
        }
        return onLogin({ ...data, pathname: '/downloads' });
    };

    const {
        model,
        setModel,
        signup,
        selectedPlan,
        makePayment,
        signupAvailability,
        getPlanByName,
        isLoading,
        appliedCoupon,
        appliedInvite
    } = useSignup(
        handleLogin,
        { coupon, invite, availablePlans },
        {
            planName: preSelectedPlan,
            cycle: billingCycle,
            currency
        }
    );
    const { verify, requestCode } = useVerification();
{'fraction_non_alphanumeric': 0.11385883565172591, 'fraction_numerical': 0.001287995878413189, 'mean_word_length': 2.726007677543186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '142658', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2160, 'n_words': 501}