diff --git a/src/app/actions/action.ts b/src/app/actions/action.ts index c83b761..75f6f3a 100644 --- a/src/app/actions/action.ts +++ b/src/app/actions/action.ts @@ -70,7 +70,7 @@ export async function getUserFilesInfo() { } } -export async function fetchTariffs() { +export async function fetchTariffs(tariffTerm: 'MONTHLY' | 'YEAR') { const token = await getSessionData('token'); try { @@ -81,7 +81,8 @@ export async function fetchTariffs() { msg_id: 30001, message_body: { action: 'get', - user_token: token + user_token: token, + tariff_term: tariffTerm } }), headers: { diff --git a/src/app/ui/payment/payment-tab-buy-tokens.tsx b/src/app/ui/payment/payment-tab-buy-tokens.tsx index bebef6c..7eac54d 100644 --- a/src/app/ui/payment/payment-tab-buy-tokens.tsx +++ b/src/app/ui/payment/payment-tab-buy-tokens.tsx @@ -1,6 +1,6 @@ 'use client' -import { fetchTariffs, fetchTokensBundle } from '@/app/actions/action'; +import { fetchTokensBundle } from '@/app/actions/action'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { convertBytes } from '@/app/lib/convertBytes'; import { useTranslations } from 'next-intl'; diff --git a/src/app/ui/payment/payment-tab-tariffs.tsx b/src/app/ui/payment/payment-tab-tariffs.tsx index 5bf0f46..1e35931 100644 --- a/src/app/ui/payment/payment-tab-tariffs.tsx +++ b/src/app/ui/payment/payment-tab-tariffs.tsx @@ -23,15 +23,16 @@ interface Tariff { export default function PaymentTabTariffs() { const t = useTranslations('Global'); + const [billingPer, setBillingPer] = useState<'MONTHLY' | 'YEAR'>('MONTHLY'); const { data: tariffData, isLoading, isError, error } = useQuery({ - queryKey: ['tariffData'], - queryFn: () => { - return fetchTariffs(); + queryKey: ['tariffData', billingPer], + queryFn: () => {; + return fetchTariffs(billingPer); }, select: (data: Tariff[] | null): Tariff[] => { if (data) { @@ -53,7 +54,6 @@ export default function PaymentTabTariffs() { const [isProcessing, setIsProcessing] = useState(false); const [showWidget, setShowWidget] = useState(false); const [yooMoneyConfig, setYooMoneyConfig] = useState(null); - const [billingPer, setBillingPer] = useState<'per-month' | 'per-year'>('per-month'); const queryClient = useQueryClient(); async function createPayment(value: number, tariff: number) { @@ -184,7 +184,7 @@ export default function PaymentTabTariffs() { setShowWidget(false); } - function changeBilling(type: 'per-month' | 'per-year') { + function changeBilling(type: 'MONTHLY' | 'YEAR') { setBillingPer(type) } @@ -198,17 +198,17 @@ export default function PaymentTabTariffs() {
- {billingPer === 'per-month' && ( + {billingPer === 'MONTHLY' && ( +
+ {tariffData?.map((item: { + id: number; + name: string; + price: number; + tokens: number; + maxFilesCount: number; + diskSize: number; + }) => { + return ( +
+
+

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

+
{item.price ?? 0} ₽
+
{t('per-month')}
+
{item.tokens ?? 0} токенов включено
+
+
    +
  • + + {item.maxFilesCount} файлов в месяц +
  • +
  • + + {item.diskSize ? convertBytes(item.diskSize) : 0} хранилища +
  • +
  • + + Базовые модули защиты +
  • +
  • + + Поддержка 24/7 +
  • +
  • + + API доступ +
  • +
+
+ +
+
+ ) + } + )} +
+ )} + + {billingPer === 'YEAR' && (
{tariffData?.map((item: { id: number; diff --git a/src/i18n/messages/en.json b/src/i18n/messages/en.json index 51c3816..a79f8b5 100644 --- a/src/i18n/messages/en.json +++ b/src/i18n/messages/en.json @@ -345,6 +345,7 @@ "distribution-analytics": "Distribution analytics", "annual": "Annual", "per-month": "Per month", + "per-year": "Per year", "violation-count": "Violation count", "your-files": "Your files", "files-under-protection": "Files under protection", diff --git a/src/i18n/messages/ru.json b/src/i18n/messages/ru.json index 020dc36..f01b566 100644 --- a/src/i18n/messages/ru.json +++ b/src/i18n/messages/ru.json @@ -345,6 +345,7 @@ "distribution-analytics": "Аналитика распространения", "annual": "Годовая", "per-month": "Помесячно", + "per-year": "В год", "violation-count": "Количество нарушений", "your-files": "Ваши файлы", "files-under-protection": "Файлов под защитой",