From 7d6882a00649898b77b3befb46b37beaa2879d9f Mon Sep 17 00:00:00 2001 From: smanylov Date: Mon, 9 Feb 2026 17:28:03 +0700 Subject: [PATCH] add new endpoint for tariffs --- src/app/actions/action.ts | 34 ++++++++++++++++++++++ src/app/ui/payment/payment-tab-tariffs.tsx | 9 +++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/app/actions/action.ts b/src/app/actions/action.ts index 73898a3..c5223d6 100644 --- a/src/app/actions/action.ts +++ b/src/app/actions/action.ts @@ -65,4 +65,38 @@ export async function getUserFilesInfo() { } catch (error) { console.error(`error: ${error}`); } +} + +export async function fetchTariffs() { + const token = await getSessionData('token'); + + try { + const response = await fetch(`${API_BASE_URL}/api/v1/data`, { + method: 'POST', + body: JSON.stringify({ + version: 1, + msg_id: 30001, + message_body: { + action: 'get', + user_token: token + } + }), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }); + + if (response.ok) { + const parsed = await response.json() + if (parsed?.message_code === 0) { + return parsed.message_body?.tariffs; + } else { + return [] + } + + } + } catch (error) { + console.error('error'); + } } \ No newline at end of file diff --git a/src/app/ui/payment/payment-tab-tariffs.tsx b/src/app/ui/payment/payment-tab-tariffs.tsx index 1553d0a..94faf8b 100644 --- a/src/app/ui/payment/payment-tab-tariffs.tsx +++ b/src/app/ui/payment/payment-tab-tariffs.tsx @@ -1,6 +1,6 @@ 'use client' -import { getUserData } from '@/app/actions/action'; +import { fetchTariffs } from '@/app/actions/action'; import { useQuery } from '@tanstack/react-query'; import { convertBytes } from '@/app/lib/convertBytes'; import { useTranslations } from 'next-intl'; @@ -12,12 +12,13 @@ export default function PaymentTabTariffs() { isError, error } = useQuery({ - queryKey: ['userData'], + queryKey: ['tariffData'], queryFn: () => { - return getUserData(); + return fetchTariffs(); } }); + const t = useTranslations('Global'); return ( @@ -33,7 +34,7 @@ export default function PaymentTabTariffs() {
- {userData.tariffs?.map(((item: { + {userData?.map(((item: { id: number, name: string, price: number,