mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
feat: guest purchase cabinet credentials UI
- CabinetCredentialsState with copyable email/password fields - Auto-login via JWT token with checkAdminStatus - /auto-login route with ErrorBoundary and no-referrer meta - Narrowed contact_type to 'email' | 'telegram' | null - Disabled button styling for PendingActivation go-to-cabinet - i18n: added landing.copy key to all 4 locales
This commit is contained in:
11
src/App.tsx
11
src/App.tsx
@@ -40,6 +40,7 @@ const Connection = lazy(() => import('./pages/Connection'));
|
|||||||
const ConnectionQR = lazy(() => import('./pages/ConnectionQR'));
|
const ConnectionQR = lazy(() => import('./pages/ConnectionQR'));
|
||||||
const QuickPurchase = lazy(() => import('./pages/QuickPurchase'));
|
const QuickPurchase = lazy(() => import('./pages/QuickPurchase'));
|
||||||
const PurchaseSuccess = lazy(() => import('./pages/PurchaseSuccess'));
|
const PurchaseSuccess = lazy(() => import('./pages/PurchaseSuccess'));
|
||||||
|
const AutoLogin = lazy(() => import('./pages/AutoLogin'));
|
||||||
const TopUpMethodSelect = lazy(() => import('./pages/TopUpMethodSelect'));
|
const TopUpMethodSelect = lazy(() => import('./pages/TopUpMethodSelect'));
|
||||||
const TopUpAmount = lazy(() => import('./pages/TopUpAmount'));
|
const TopUpAmount = lazy(() => import('./pages/TopUpAmount'));
|
||||||
const ConnectedAccounts = lazy(() => import('./pages/ConnectedAccounts'));
|
const ConnectedAccounts = lazy(() => import('./pages/ConnectedAccounts'));
|
||||||
@@ -219,6 +220,16 @@ function App() {
|
|||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path="/auto-login"
|
||||||
|
element={
|
||||||
|
<ErrorBoundary level="app">
|
||||||
|
<LazyPage>
|
||||||
|
<AutoLogin />
|
||||||
|
</LazyPage>
|
||||||
|
</ErrorBoundary>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Protected routes */}
|
{/* Protected routes */}
|
||||||
<Route
|
<Route
|
||||||
|
|||||||
@@ -280,6 +280,12 @@ export const authApi = {
|
|||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Auto-login from guest purchase success page
|
||||||
|
autoLogin: async (token: string): Promise<AuthResponse> => {
|
||||||
|
const response = await apiClient.post<AuthResponse>('/cabinet/auth/login/auto', { token });
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
|
||||||
// Account merge (no JWT required)
|
// Account merge (no JWT required)
|
||||||
getMergePreview: async (mergeToken: string): Promise<MergePreviewResponse> => {
|
getMergePreview: async (mergeToken: string): Promise<MergePreviewResponse> => {
|
||||||
const response = await apiClient.get<MergePreviewResponse>(
|
const response = await apiClient.get<MergePreviewResponse>(
|
||||||
|
|||||||
@@ -90,6 +90,10 @@ export interface PurchaseStatus {
|
|||||||
period_days: number | null;
|
period_days: number | null;
|
||||||
tariff_name: string | null;
|
tariff_name: string | null;
|
||||||
gift_message: string | null;
|
gift_message: string | null;
|
||||||
|
contact_type: 'email' | 'telegram' | null;
|
||||||
|
cabinet_email: string | null;
|
||||||
|
cabinet_password: string | null;
|
||||||
|
auto_login_token: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|||||||
@@ -3960,6 +3960,7 @@
|
|||||||
"total": "Total",
|
"total": "Total",
|
||||||
"pay": "Pay",
|
"pay": "Pay",
|
||||||
"choosePeriod": "Choose period",
|
"choosePeriod": "Choose period",
|
||||||
|
"copy": "Copy",
|
||||||
"copied": "Copied!",
|
"copied": "Copied!",
|
||||||
"copyLink": "Copy link",
|
"copyLink": "Copy link",
|
||||||
"giftToggleLabel": "Purchase type",
|
"giftToggleLabel": "Purchase type",
|
||||||
@@ -3970,6 +3971,16 @@
|
|||||||
"activateNow": "Activate now",
|
"activateNow": "Activate now",
|
||||||
"activating": "Activating...",
|
"activating": "Activating...",
|
||||||
"activationFailed": "Activation failed",
|
"activationFailed": "Activation failed",
|
||||||
"giftMessage": "Message"
|
"giftMessage": "Message",
|
||||||
|
"cabinetReady": "Your account is ready",
|
||||||
|
"cabinetEmail": "Email",
|
||||||
|
"cabinetPassword": "Password",
|
||||||
|
"goToCabinet": "Go to Cabinet",
|
||||||
|
"saveCredentials": "Save these login credentials",
|
||||||
|
"credentialsSentToEmail": "Login credentials sent to your email",
|
||||||
|
"giftSentSuccess": "Gift sent!",
|
||||||
|
"giftSentDesc": "Recipient will be notified by email",
|
||||||
|
"autoLoginFailed": "Auto-login failed",
|
||||||
|
"autoLoginProcessing": "Signing in..."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3511,6 +3511,7 @@
|
|||||||
"total": "مجموع",
|
"total": "مجموع",
|
||||||
"pay": "پرداخت",
|
"pay": "پرداخت",
|
||||||
"choosePeriod": "انتخاب دوره",
|
"choosePeriod": "انتخاب دوره",
|
||||||
|
"copy": "کپی",
|
||||||
"copied": "کپی شد!",
|
"copied": "کپی شد!",
|
||||||
"copyLink": "کپی لینک",
|
"copyLink": "کپی لینک",
|
||||||
"giftToggleLabel": "\u0646\u0648\u0639 \u062e\u0631\u06cc\u062f",
|
"giftToggleLabel": "\u0646\u0648\u0639 \u062e\u0631\u06cc\u062f",
|
||||||
@@ -3521,6 +3522,16 @@
|
|||||||
"activateNow": "فعالسازی",
|
"activateNow": "فعالسازی",
|
||||||
"activating": "در حال فعالسازی...",
|
"activating": "در حال فعالسازی...",
|
||||||
"activationFailed": "خطا در فعالسازی",
|
"activationFailed": "خطا در فعالسازی",
|
||||||
"giftMessage": "پیام"
|
"giftMessage": "پیام",
|
||||||
|
"cabinetReady": "حساب شما آماده است",
|
||||||
|
"cabinetEmail": "ایمیل",
|
||||||
|
"cabinetPassword": "رمز عبور",
|
||||||
|
"goToCabinet": "رفتن به پنل کاربری",
|
||||||
|
"saveCredentials": "این اطلاعات ورود را ذخیره کنید",
|
||||||
|
"credentialsSentToEmail": "اطلاعات ورود به ایمیل شما ارسال شد",
|
||||||
|
"giftSentSuccess": "هدیه ارسال شد!",
|
||||||
|
"giftSentDesc": "گیرنده از طریق ایمیل مطلع خواهد شد",
|
||||||
|
"autoLoginFailed": "ورود خودکار ناموفق بود",
|
||||||
|
"autoLoginProcessing": "در حال ورود..."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4523,6 +4523,7 @@
|
|||||||
"total": "Итого",
|
"total": "Итого",
|
||||||
"pay": "Оплатить",
|
"pay": "Оплатить",
|
||||||
"choosePeriod": "Выберите период",
|
"choosePeriod": "Выберите период",
|
||||||
|
"copy": "Скопировать",
|
||||||
"copied": "Скопировано!",
|
"copied": "Скопировано!",
|
||||||
"copyLink": "Скопировать ссылку",
|
"copyLink": "Скопировать ссылку",
|
||||||
"giftToggleLabel": "Тип покупки",
|
"giftToggleLabel": "Тип покупки",
|
||||||
@@ -4533,6 +4534,16 @@
|
|||||||
"activateNow": "Активировать",
|
"activateNow": "Активировать",
|
||||||
"activating": "Активация...",
|
"activating": "Активация...",
|
||||||
"activationFailed": "Ошибка активации",
|
"activationFailed": "Ошибка активации",
|
||||||
"giftMessage": "Сообщение"
|
"giftMessage": "Сообщение",
|
||||||
|
"cabinetReady": "Ваш аккаунт готов",
|
||||||
|
"cabinetEmail": "Email",
|
||||||
|
"cabinetPassword": "Пароль",
|
||||||
|
"goToCabinet": "Перейти в кабинет",
|
||||||
|
"saveCredentials": "Сохраните эти данные для входа",
|
||||||
|
"credentialsSentToEmail": "Данные для входа отправлены на email",
|
||||||
|
"giftSentSuccess": "Подарок отправлен!",
|
||||||
|
"giftSentDesc": "Получатель получит уведомление на email",
|
||||||
|
"autoLoginFailed": "Не удалось выполнить автоматический вход",
|
||||||
|
"autoLoginProcessing": "Выполняется вход..."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3510,6 +3510,7 @@
|
|||||||
"total": "总计",
|
"total": "总计",
|
||||||
"pay": "支付",
|
"pay": "支付",
|
||||||
"choosePeriod": "选择时长",
|
"choosePeriod": "选择时长",
|
||||||
|
"copy": "复制",
|
||||||
"copied": "已复制!",
|
"copied": "已复制!",
|
||||||
"copyLink": "复制链接",
|
"copyLink": "复制链接",
|
||||||
"giftToggleLabel": "\u8d2d\u4e70\u7c7b\u578b",
|
"giftToggleLabel": "\u8d2d\u4e70\u7c7b\u578b",
|
||||||
@@ -3520,6 +3521,16 @@
|
|||||||
"activateNow": "立即激活",
|
"activateNow": "立即激活",
|
||||||
"activating": "激活中...",
|
"activating": "激活中...",
|
||||||
"activationFailed": "激活失败",
|
"activationFailed": "激活失败",
|
||||||
"giftMessage": "留言"
|
"giftMessage": "留言",
|
||||||
|
"cabinetReady": "您的账户已准备就绪",
|
||||||
|
"cabinetEmail": "邮箱",
|
||||||
|
"cabinetPassword": "密码",
|
||||||
|
"goToCabinet": "前往个人中心",
|
||||||
|
"saveCredentials": "请保存这些登录信息",
|
||||||
|
"credentialsSentToEmail": "登录信息已发送到您的邮箱",
|
||||||
|
"giftSentSuccess": "礼物已发送!",
|
||||||
|
"giftSentDesc": "收件人将通过邮件收到通知",
|
||||||
|
"autoLoginFailed": "自动登录失败",
|
||||||
|
"autoLoginProcessing": "正在登录..."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
82
src/pages/AutoLogin.tsx
Normal file
82
src/pages/AutoLogin.tsx
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
import { useEffect, useState, useRef } from 'react';
|
||||||
|
import { useSearchParams, useNavigate } from 'react-router';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { authApi } from '../api/auth';
|
||||||
|
import { useAuthStore } from '../store/auth';
|
||||||
|
|
||||||
|
export default function AutoLogin() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { setTokens, setUser, checkAdminStatus } = useAuthStore();
|
||||||
|
const [error, setError] = useState(false);
|
||||||
|
const attemptedRef = useRef(false);
|
||||||
|
|
||||||
|
const token = searchParams.get('token');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Prevent referrer leaking the token
|
||||||
|
const meta = document.createElement('meta');
|
||||||
|
meta.name = 'referrer';
|
||||||
|
meta.content = 'no-referrer';
|
||||||
|
document.head.appendChild(meta);
|
||||||
|
return () => {
|
||||||
|
document.head.removeChild(meta);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!token || attemptedRef.current) {
|
||||||
|
if (!token) setError(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
attemptedRef.current = true;
|
||||||
|
|
||||||
|
authApi
|
||||||
|
.autoLogin(token)
|
||||||
|
.then(async (response) => {
|
||||||
|
setTokens(response.access_token, response.refresh_token);
|
||||||
|
setUser(response.user);
|
||||||
|
await checkAdminStatus();
|
||||||
|
navigate('/', { replace: true });
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setError(true);
|
||||||
|
});
|
||||||
|
}, [token, navigate, setTokens, setUser, checkAdminStatus]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-dvh items-center justify-center bg-dark-950 px-4">
|
||||||
|
<div className="w-full max-w-sm rounded-2xl border border-dark-800/50 bg-dark-900/50 p-8 text-center">
|
||||||
|
{error ? (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-error-500/10">
|
||||||
|
<svg
|
||||||
|
className="h-8 w-8 text-error-400"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth={2}
|
||||||
|
>
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-dark-300">{t('landing.autoLoginFailed')}</p>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => navigate('/login', { replace: true })}
|
||||||
|
className="rounded-xl bg-accent-500 px-6 py-2.5 text-sm font-medium text-white transition-colors hover:bg-accent-400"
|
||||||
|
>
|
||||||
|
{t('auth.login', 'Login')}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="mx-auto h-10 w-10 animate-spin rounded-full border-2 border-dark-600 border-t-accent-500" />
|
||||||
|
<p className="text-sm text-dark-300">{t('landing.autoLoginProcessing')}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import { useState, useCallback, useRef, useEffect } from 'react';
|
import { useState, useCallback, useRef, useEffect } from 'react';
|
||||||
import { useParams } from 'react-router';
|
import { useParams, useNavigate } from 'react-router';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { QRCodeSVG } from 'qrcode.react';
|
import { QRCodeSVG } from 'qrcode.react';
|
||||||
import { landingApi } from '../api/landings';
|
import { landingApi } from '../api/landings';
|
||||||
|
import { authApi } from '../api/auth';
|
||||||
|
import { useAuthStore } from '../store/auth';
|
||||||
import { copyToClipboard } from '../utils/clipboard';
|
import { copyToClipboard } from '../utils/clipboard';
|
||||||
import { cn } from '../lib/utils';
|
import { cn } from '../lib/utils';
|
||||||
|
|
||||||
@@ -45,6 +47,168 @@ function PendingState() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CopyableField({ label, value }: { label: string; value: string }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
const timeoutRef = useRef<ReturnType<typeof setTimeout>>(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleCopy = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
await copyToClipboard(value);
|
||||||
|
setCopied(true);
|
||||||
|
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
||||||
|
timeoutRef.current = setTimeout(() => setCopied(false), 2000);
|
||||||
|
} catch {
|
||||||
|
// Clipboard write failed silently
|
||||||
|
}
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 rounded-xl bg-dark-800/50 px-4 py-3">
|
||||||
|
<div className="flex-1 text-left">
|
||||||
|
<p className="text-xs text-dark-400">{label}</p>
|
||||||
|
<p className="mt-0.5 font-mono text-sm text-dark-100">{value}</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleCopy}
|
||||||
|
className={cn(
|
||||||
|
'shrink-0 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors',
|
||||||
|
copied
|
||||||
|
? 'bg-success-500/10 text-success-500'
|
||||||
|
: 'bg-dark-700/50 text-dark-300 hover:bg-dark-600/50',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{copied ? t('landing.copied', 'Copied!') : t('landing.copy', 'Copy')}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CabinetCredentialsState({
|
||||||
|
cabinetEmail,
|
||||||
|
cabinetPassword,
|
||||||
|
autoLoginToken,
|
||||||
|
tariffName,
|
||||||
|
periodDays,
|
||||||
|
}: {
|
||||||
|
cabinetEmail: string;
|
||||||
|
cabinetPassword: string | null;
|
||||||
|
autoLoginToken: string | null;
|
||||||
|
tariffName: string | null;
|
||||||
|
periodDays: number | null;
|
||||||
|
}) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { setTokens, setUser, checkAdminStatus } = useAuthStore();
|
||||||
|
const [isLoggingIn, setIsLoggingIn] = useState(false);
|
||||||
|
const [loginError, setLoginError] = useState(false);
|
||||||
|
|
||||||
|
const handleGoToCabinet = useCallback(async () => {
|
||||||
|
if (!autoLoginToken) {
|
||||||
|
navigate('/login');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setIsLoggingIn(true);
|
||||||
|
setLoginError(false);
|
||||||
|
try {
|
||||||
|
const response = await authApi.autoLogin(autoLoginToken);
|
||||||
|
setTokens(response.access_token, response.refresh_token);
|
||||||
|
setUser(response.user);
|
||||||
|
await checkAdminStatus();
|
||||||
|
navigate('/');
|
||||||
|
} catch {
|
||||||
|
setLoginError(true);
|
||||||
|
setIsLoggingIn(false);
|
||||||
|
}
|
||||||
|
}, [autoLoginToken, navigate, setTokens, setUser, checkAdminStatus]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, scale: 0.9 }}
|
||||||
|
animate={{ opacity: 1, scale: 1 }}
|
||||||
|
className="flex flex-col items-center gap-6 text-center"
|
||||||
|
>
|
||||||
|
{/* Animated checkmark */}
|
||||||
|
<motion.div
|
||||||
|
initial={{ scale: 0 }}
|
||||||
|
animate={{ scale: 1 }}
|
||||||
|
transition={{ type: 'spring', stiffness: 200, damping: 15, delay: 0.1 }}
|
||||||
|
className="flex h-20 w-20 items-center justify-center rounded-full bg-success-500/10"
|
||||||
|
>
|
||||||
|
<motion.svg
|
||||||
|
initial={{ pathLength: 0, opacity: 0 }}
|
||||||
|
animate={{ pathLength: 1, opacity: 1 }}
|
||||||
|
transition={{ duration: 0.4, delay: 0.3 }}
|
||||||
|
className="h-10 w-10 text-success-500"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth={2.5}
|
||||||
|
>
|
||||||
|
<motion.path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
d="M5 13l4 4L19 7"
|
||||||
|
initial={{ pathLength: 0 }}
|
||||||
|
animate={{ pathLength: 1 }}
|
||||||
|
transition={{ duration: 0.4, delay: 0.3 }}
|
||||||
|
/>
|
||||||
|
</motion.svg>
|
||||||
|
</motion.div>
|
||||||
|
|
||||||
|
{/* Title */}
|
||||||
|
<div>
|
||||||
|
<h1 className="text-xl font-bold text-dark-50">{t('landing.cabinetReady')}</h1>
|
||||||
|
{tariffName && periodDays !== null && (
|
||||||
|
<p className="mt-1 text-sm text-dark-300">
|
||||||
|
{tariffName} — {periodDays} {t('landing.daysAccess')}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Credentials */}
|
||||||
|
<div className="w-full space-y-3">
|
||||||
|
<CopyableField label={t('landing.cabinetEmail')} value={cabinetEmail} />
|
||||||
|
{cabinetPassword && (
|
||||||
|
<CopyableField label={t('landing.cabinetPassword')} value={cabinetPassword} />
|
||||||
|
)}
|
||||||
|
{cabinetPassword && <p className="text-xs text-dark-400">{t('landing.saveCredentials')}</p>}
|
||||||
|
{!cabinetPassword && (
|
||||||
|
<p className="text-xs text-dark-400">{t('landing.credentialsSentToEmail')}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Go to Cabinet button */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleGoToCabinet}
|
||||||
|
disabled={isLoggingIn}
|
||||||
|
className={cn(
|
||||||
|
'flex w-full items-center justify-center gap-2 rounded-xl px-6 py-3 text-sm font-medium text-white transition-colors',
|
||||||
|
isLoggingIn ? 'cursor-not-allowed bg-accent-500/50' : 'bg-accent-500 hover:bg-accent-400',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isLoggingIn ? (
|
||||||
|
<>
|
||||||
|
<Spinner className="h-4 w-4" />
|
||||||
|
{t('landing.autoLoginProcessing')}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
t('landing.goToCabinet')
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
{loginError && <p className="text-xs text-error-400">{t('landing.autoLoginFailed')}</p>}
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function SuccessState({
|
function SuccessState({
|
||||||
subscriptionUrl,
|
subscriptionUrl,
|
||||||
cryptoLink,
|
cryptoLink,
|
||||||
@@ -127,8 +291,10 @@ function SuccessState({
|
|||||||
|
|
||||||
{/* Title */}
|
{/* Title */}
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-xl font-bold text-dark-50">{t('landing.purchaseSuccess')}</h1>
|
<h1 className="text-xl font-bold text-dark-50">
|
||||||
{tariffName && periodDays && (
|
{isGift ? t('landing.giftSentSuccess') : t('landing.purchaseSuccess')}
|
||||||
|
</h1>
|
||||||
|
{tariffName && periodDays !== null && (
|
||||||
<p className="mt-1 text-sm text-dark-300">
|
<p className="mt-1 text-sm text-dark-300">
|
||||||
{tariffName} — {periodDays} {t('landing.daysAccess')}
|
{tariffName} — {periodDays} {t('landing.daysAccess')}
|
||||||
</p>
|
</p>
|
||||||
@@ -216,6 +382,7 @@ function PendingActivationState({
|
|||||||
isGift,
|
isGift,
|
||||||
isActivating,
|
isActivating,
|
||||||
onActivate,
|
onActivate,
|
||||||
|
autoLoginToken,
|
||||||
}: {
|
}: {
|
||||||
tariffName: string | null;
|
tariffName: string | null;
|
||||||
periodDays: number | null;
|
periodDays: number | null;
|
||||||
@@ -223,8 +390,30 @@ function PendingActivationState({
|
|||||||
isGift: boolean;
|
isGift: boolean;
|
||||||
isActivating: boolean;
|
isActivating: boolean;
|
||||||
onActivate: () => void;
|
onActivate: () => void;
|
||||||
|
autoLoginToken: string | null;
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { setTokens, setUser, checkAdminStatus } = useAuthStore();
|
||||||
|
const [isLoggingIn, setIsLoggingIn] = useState(false);
|
||||||
|
|
||||||
|
const handleGoToCabinet = useCallback(async () => {
|
||||||
|
if (!autoLoginToken) {
|
||||||
|
navigate('/login');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setIsLoggingIn(true);
|
||||||
|
try {
|
||||||
|
const response = await authApi.autoLogin(autoLoginToken);
|
||||||
|
setTokens(response.access_token, response.refresh_token);
|
||||||
|
setUser(response.user);
|
||||||
|
await checkAdminStatus();
|
||||||
|
navigate('/');
|
||||||
|
} catch {
|
||||||
|
setIsLoggingIn(false);
|
||||||
|
navigate('/login');
|
||||||
|
}
|
||||||
|
}, [autoLoginToken, navigate, setTokens, setUser, checkAdminStatus]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
@@ -251,7 +440,7 @@ function PendingActivationState({
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-xl font-bold text-dark-50">{t('landing.pendingActivation')}</h1>
|
<h1 className="text-xl font-bold text-dark-50">{t('landing.pendingActivation')}</h1>
|
||||||
{tariffName && periodDays && (
|
{tariffName && periodDays !== null && (
|
||||||
<p className="mt-1 text-sm text-dark-300">
|
<p className="mt-1 text-sm text-dark-300">
|
||||||
{tariffName} — {periodDays} {t('landing.daysAccess')}
|
{tariffName} — {periodDays} {t('landing.daysAccess')}
|
||||||
</p>
|
</p>
|
||||||
@@ -264,26 +453,51 @@ function PendingActivationState({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<div className="flex w-full flex-col gap-3">
|
||||||
type="button"
|
<button
|
||||||
onClick={onActivate}
|
type="button"
|
||||||
disabled={isActivating}
|
onClick={onActivate}
|
||||||
className={cn(
|
disabled={isActivating}
|
||||||
'flex items-center justify-center gap-2 rounded-xl px-6 py-3 text-sm font-medium text-white transition-colors',
|
className={cn(
|
||||||
isActivating
|
'flex items-center justify-center gap-2 rounded-xl px-6 py-3 text-sm font-medium text-white transition-colors',
|
||||||
? 'cursor-not-allowed bg-accent-500/50'
|
isActivating
|
||||||
: 'bg-accent-500 hover:bg-accent-400',
|
? 'cursor-not-allowed bg-accent-500/50'
|
||||||
|
: 'bg-accent-500 hover:bg-accent-400',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isActivating ? (
|
||||||
|
<>
|
||||||
|
<Spinner className="h-4 w-4" />
|
||||||
|
{t('landing.activating')}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
t('landing.activateNow')
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{autoLoginToken && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleGoToCabinet}
|
||||||
|
disabled={isLoggingIn}
|
||||||
|
className={cn(
|
||||||
|
'flex items-center justify-center gap-2 rounded-xl px-6 py-3 text-sm font-medium transition-colors',
|
||||||
|
isLoggingIn
|
||||||
|
? 'cursor-not-allowed bg-dark-800/30 text-dark-400'
|
||||||
|
: 'bg-dark-800/50 text-dark-200 hover:bg-dark-700/50',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isLoggingIn ? (
|
||||||
|
<>
|
||||||
|
<Spinner className="h-4 w-4" />
|
||||||
|
{t('landing.autoLoginProcessing')}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
t('landing.goToCabinet')
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
)}
|
)}
|
||||||
>
|
</div>
|
||||||
{isActivating ? (
|
|
||||||
<>
|
|
||||||
<Spinner className="h-4 w-4" />
|
|
||||||
{t('landing.activating')}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
t('landing.activateNow')
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</motion.div>
|
</motion.div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -386,6 +600,8 @@ export default function PurchaseSuccess() {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: purchaseStatus,
|
data: purchaseStatus,
|
||||||
isError,
|
isError,
|
||||||
@@ -420,25 +636,40 @@ export default function PurchaseSuccess() {
|
|||||||
setIsActivating(true);
|
setIsActivating(true);
|
||||||
setActivationError(false);
|
setActivationError(false);
|
||||||
try {
|
try {
|
||||||
await landingApi.activatePurchase(token);
|
const result = await landingApi.activatePurchase(token);
|
||||||
await refetch();
|
queryClient.setQueryData(['purchase-status', token], result);
|
||||||
} catch {
|
} catch {
|
||||||
setActivationError(true);
|
setActivationError(true);
|
||||||
} finally {
|
} finally {
|
||||||
activatingRef.current = false;
|
activatingRef.current = false;
|
||||||
setIsActivating(false);
|
setIsActivating(false);
|
||||||
}
|
}
|
||||||
}, [token, refetch]);
|
}, [token, queryClient]);
|
||||||
|
|
||||||
const isSuccess = purchaseStatus?.status === 'delivered';
|
const isSuccess = purchaseStatus?.status === 'delivered';
|
||||||
const isPendingActivation = purchaseStatus?.status === 'pending_activation';
|
const isPendingActivation = purchaseStatus?.status === 'pending_activation';
|
||||||
const isFailed = purchaseStatus?.status === 'failed' || purchaseStatus?.status === 'expired';
|
const isFailed = purchaseStatus?.status === 'failed' || purchaseStatus?.status === 'expired';
|
||||||
|
|
||||||
|
// Email self-purchase delivered → show cabinet credentials
|
||||||
|
const isEmailSelfPurchase =
|
||||||
|
isSuccess &&
|
||||||
|
purchaseStatus.contact_type === 'email' &&
|
||||||
|
!purchaseStatus.is_gift &&
|
||||||
|
purchaseStatus.cabinet_email;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-dvh items-center justify-center bg-dark-950 px-4">
|
<div className="flex min-h-dvh items-center justify-center bg-dark-950 px-4">
|
||||||
<div className="w-full max-w-md rounded-2xl border border-dark-800/50 bg-dark-900/50 p-8">
|
<div className="w-full max-w-md rounded-2xl border border-dark-800/50 bg-dark-900/50 p-8">
|
||||||
{isError ? (
|
{isError ? (
|
||||||
<FailedState />
|
<FailedState />
|
||||||
|
) : isEmailSelfPurchase ? (
|
||||||
|
<CabinetCredentialsState
|
||||||
|
cabinetEmail={purchaseStatus.cabinet_email!}
|
||||||
|
cabinetPassword={purchaseStatus.cabinet_password}
|
||||||
|
autoLoginToken={purchaseStatus.auto_login_token}
|
||||||
|
tariffName={purchaseStatus.tariff_name}
|
||||||
|
periodDays={purchaseStatus.period_days}
|
||||||
|
/>
|
||||||
) : isSuccess ? (
|
) : isSuccess ? (
|
||||||
<SuccessState
|
<SuccessState
|
||||||
subscriptionUrl={purchaseStatus.subscription_url}
|
subscriptionUrl={purchaseStatus.subscription_url}
|
||||||
@@ -459,6 +690,7 @@ export default function PurchaseSuccess() {
|
|||||||
isGift={purchaseStatus.is_gift}
|
isGift={purchaseStatus.is_gift}
|
||||||
isActivating={isActivating}
|
isActivating={isActivating}
|
||||||
onActivate={handleActivate}
|
onActivate={handleActivate}
|
||||||
|
autoLoginToken={purchaseStatus.auto_login_token}
|
||||||
/>
|
/>
|
||||||
{activationError && (
|
{activationError && (
|
||||||
<p className="text-center text-sm text-error-400">{t('landing.activationFailed')}</p>
|
<p className="text-center text-sm text-error-400">{t('landing.activationFailed')}</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user