import React, { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { LaunchDiscountPlanCard } from '../components/launch-discount/plan-card'; import { LAUNCH_PLANS, LaunchPlan } from '../components/launch-discount/plans'; import { GRADIENT, MONO, SANS } from '../components/signup-mirror/theme'; import { Spinner } from '../components/ui/Spinner'; import { useAppStateContext } from '../context/user.data.context'; import { recomaze_ai_personalization_env } from '../env'; import { createSignupCheckout, skipLaunchDiscount, } from '../service/payment/payment.service'; import { getBaseUrl } from '../utils/domain'; import { PlanType } from '../utils/plan'; const PageLoading = (): JSX.Element => (
); const LaunchDiscount = (): JSX.Element => { const navigate = useNavigate(); const { token, clientId, user } = useAppStateContext(); const [lockingKey, setLockingKey] = useState(null); const [skipping, setSkipping] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (!user) return; // Only a confirmed non-mirror account is bounced; a stale /me that omits // the flag must not eject a merchant who just arrived from the Mirror. if (user.signup_mirror === false) { navigate('/dashboard', { replace: true }); return; } if (user.signup_mirror_completed_at) { navigate('/dashboard', { replace: true }); } }, [user, navigate]); const adminBase = (): string => { const url = getBaseUrl(recomaze_ai_personalization_env?.wp_api_url); return `${url}/wp-admin/admin.php?page=recomaze`; }; const lock = async (plan: LaunchPlan): Promise => { if (!token || lockingKey || skipping) return; setError(null); setLockingKey(plan.key); try { const base = adminBase(); const response = await createSignupCheckout({ price_id: plan.priceId, success_url: `${base}#/dashboard`, cancel_url: `${base}#/launch-discount`, }); if (response?.success && response.session?.url) { window.location.replace(response.session.url); return; } throw new Error(response?.message || 'Failed to start checkout'); } catch (checkoutError) { console.error(checkoutError); setError('Something went wrong opening checkout. Please try again.'); setLockingKey(null); } }; const skip = async (): Promise => { if (!token || lockingKey || skipping) return; setSkipping(true); try { await skipLaunchDiscount(); } catch (skipError) { console.error(skipError); } finally { navigate('/onboarding-chain'); } }; if (!token || !clientId) return ; return (
Launch offer

50% off {' '} your first month

Your Company ID is saved. Pick a plan and Recomaze goes to work. Free for 7 days, then 50% off your first month.

{error && (
{error}
)}
{LAUNCH_PLANS.map(plan => ( ))}
Full access starts today - you won't be charged now. Your 7-day free trial runs first; cancel anytime before it ends and you pay nothing. When the trial ends, we bill your first month at 50% off, then the full plan price every month after.
); }; export default LaunchDiscount;