diff --git a/src/app/actions/action.ts b/src/app/actions/action.ts index c5223d6..e84aa1d 100644 --- a/src/app/actions/action.ts +++ b/src/app/actions/action.ts @@ -2,7 +2,6 @@ import { getSessionData, deleteSession } from '@/app/actions/session'; import { testUserData, API_BASE_URL } from '@/app/actions/definitions'; -import { redirect } from 'next/navigation'; export async function getUserData() { const userEmail = await getSessionData('email'); @@ -99,4 +98,23 @@ export async function fetchTariffs() { } catch (error) { console.error('error'); } -} \ No newline at end of file +} + +export async function getBuildData() { + + try { + const response = await fetch(`${API_BASE_URL}/check/api/build`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + } + }); + + if (response.ok) { + return await response.json(); + } + } catch (error) { + console.error('error'); + } +} diff --git a/src/app/lib/prefetch-queries.ts b/src/app/lib/prefetch-queries.ts index c384463..b597432 100644 --- a/src/app/lib/prefetch-queries.ts +++ b/src/app/lib/prefetch-queries.ts @@ -1,5 +1,5 @@ import { QueryClient } from '@tanstack/react-query'; -import { getUserData, getUserFilesInfo } from '@/app/actions/action'; +import { getUserData, getUserFilesInfo, getBuildData } from '@/app/actions/action'; import { getUserFilesData } from '@/app/actions/fileEntity'; import { fetchReferralUserStats } from '@/app/actions/referralsActions'; @@ -24,5 +24,19 @@ export async function prefetchLayoutQueries(queryClient: QueryClient) { queryKey: ['referralUserStats'], queryFn: () => fetchReferralUserStats() }), + queryClient.prefetchQuery({ + queryKey: ['backendBuildDate'], + queryFn: async () => { + try { + const response = await getBuildData(); + if (response.buildTimeBack) { + return response.buildTimeBack; + } + return null; + } catch (error) { + return null; + } + } + }), ]); } \ No newline at end of file diff --git a/src/app/ui/navigation/nav-links.tsx b/src/app/ui/navigation/nav-links.tsx index 6c555d5..a253fbd 100644 --- a/src/app/ui/navigation/nav-links.tsx +++ b/src/app/ui/navigation/nav-links.tsx @@ -14,6 +14,7 @@ import { useClickOutside } from '@/app/hooks/useClickOutside'; import { fetchReferralUserStats } from '@/app/actions/referralsActions'; import { useQuery } from '@tanstack/react-query'; import { env } from 'process'; +import { getBuildData } from '@/app/actions/action'; export default function NavLinks() { const { @@ -56,7 +57,21 @@ export default function NavLinks() { } return null; }, - retry: false // Не повторять запрос при ошибке + retry: false + }); + + const { + data: backendBuildDate, + } = useQuery({ + queryKey: ['backendBuildDate'], + queryFn: () => getBuildData(), + select: (data) => { + if (data) { + return data; + } + return null; + }, + retry: false }); const pathname = usePathname().replace('/en/', '/').replace('/ru/', '/'); @@ -160,14 +175,16 @@ export default function NavLinks() {
- {!frontendBuildDate && ( + {frontendBuildDate && (
front: {frontendBuildDate}
)} - {/*
- back: -
*/} + {backendBuildDate && ( +
+ back: {backendBuildDate} +
+ )}
);