'use client' import { fetchTariffs } from '@/app/actions/action'; import { useQuery } from '@tanstack/react-query'; import { convertBytes } from '@/app/lib/convertBytes'; import { useTranslations } from 'next-intl'; import { yooKasaCreatePayment } from '@/app/actions/yooKassa'; import { useState, ReactNode } from 'react'; import ModalWindow from '@/app/components/ModalWindow'; export default function PaymentTabTariffs() { const t = useTranslations('Global'); const { data: userData, isLoading, isError, error } = useQuery({ queryKey: ['tariffData'], queryFn: () => { return fetchTariffs(); } }); const [openWindow, setOpenWindow] = useState(false); const [selectedTariff, setSelectedTariff] = useState<{ value: number; tariff: string; tokens: number; } | null>(null); const [isProcessing, setIsProcessing] = useState(false); async function createPayment(value: number, tariff: string) { if (isProcessing) return; setIsProcessing(true); try { const response = await yooKasaCreatePayment(value, tariff); console.log(response); if (response) { window.open(response, '_blank', 'noopener,noreferrer'); } } catch (error) { console.error('Payment error:', error); } finally { setIsProcessing(false); } } function openPaymentWindow(value: number, tariff: string, tokens: number) { setSelectedTariff({ value, tariff, tokens }); setIsProcessing(false); setOpenWindow(true); } function closeModal() { setOpenWindow(false); setSelectedTariff(null); setIsProcessing(false); } function PaymentConfirmationModal() { if (!selectedTariff) return null; const handleConfirm = () => { createPayment(selectedTariff.value, selectedTariff.tariff); }; const handleCancel = () => { closeModal(); }; return (

Подтверждение оплаты

Подписка: {selectedTariff.tariff}

Месячная подписка будет автоматически продлеваться
Включено {selectedTariff.tokens} токенов!
{selectedTariff.value}₽
в месяц
); } return ( <>
{userData?.map((item: { id: number; name: string; price: number; tokens: number; maxFilesCount: number; diskSize: number; }) => (
🚀

{t.has(item.name) ? t(item.name) : item.name}

{item.price}
в месяц
{item.tokens} токенов включено
  • {item.maxFilesCount} файлов в месяц
  • {item.diskSize ? convertBytes(item.diskSize) : 0} хранилища
  • Базовые модули защиты
  • Поддержка 24/7
  • API доступ
))}
); }