add new endpoint for tariffs

This commit is contained in:
smanylov
2026-02-09 17:28:03 +07:00
parent 1b57d589fb
commit 7d6882a006
2 changed files with 39 additions and 4 deletions
+34
View File
@@ -65,4 +65,38 @@ export async function getUserFilesInfo() {
} catch (error) { } catch (error) {
console.error(`error: ${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');
}
} }
+5 -4
View File
@@ -1,6 +1,6 @@
'use client' 'use client'
import { getUserData } from '@/app/actions/action'; import { fetchTariffs } from '@/app/actions/action';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { convertBytes } from '@/app/lib/convertBytes'; import { convertBytes } from '@/app/lib/convertBytes';
import { useTranslations } from 'next-intl'; import { useTranslations } from 'next-intl';
@@ -12,12 +12,13 @@ export default function PaymentTabTariffs() {
isError, isError,
error error
} = useQuery({ } = useQuery({
queryKey: ['userData'], queryKey: ['tariffData'],
queryFn: () => { queryFn: () => {
return getUserData(); return fetchTariffs();
} }
}); });
const t = useTranslations('Global'); const t = useTranslations('Global');
return ( return (
@@ -33,7 +34,7 @@ export default function PaymentTabTariffs() {
</div> </div>
<div className="subscription-grid"> <div className="subscription-grid">
{userData.tariffs?.map(((item: { {userData?.map(((item: {
id: number, id: number,
name: string, name: string,
price: number, price: number,