add new endpoint for tariffs
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
</div>
|
||||
<div className="subscription-grid">
|
||||
|
||||
{userData.tariffs?.map(((item: {
|
||||
{userData?.map(((item: {
|
||||
id: number,
|
||||
name: string,
|
||||
price: number,
|
||||
|
||||
Reference in New Issue
Block a user