This commit is contained in:
Samandar Turgunboyev
2026-02-26 13:10:48 +05:00
parent 6642f5cfe1
commit 5e60ac8dd4
2 changed files with 54 additions and 68 deletions

View File

@@ -0,0 +1,38 @@
'use client';
import { partner_api } from '@/features/about/lib/api';
import { useQuery } from '@tanstack/react-query';
import { useParams } from 'next/navigation';
import { useEffect } from 'react';
export default function AboutSEO() {
const { locale } = useParams();
const { data } = useQuery({
queryKey: ['aboutData'],
queryFn: async () => (await partner_api.getAbout()).data,
});
useEffect(() => {
if (!data) return;
const banner = data.banner;
const title =
locale === 'uz'
? banner.title_uz
: locale === 'ru'
? banner.title_ru
: banner.title_en;
const description =
locale === 'uz'
? banner.description_uz
: locale === 'ru'
? banner.description_ru
: banner.description_en;
document.title = title || 'Gastro Market';
const descMeta = document.querySelector('meta[name="description"]');
if (descMeta) descMeta.setAttribute('content', description || '');
}, [data, locale]);
return null;
}

View File

@@ -1,32 +1,23 @@
// app/[locale]/about/page.tsx
'use client';
import { partner_api } from '@/features/about/lib/api';
import { AboutContent } from '@/features/about/ui/AboutContent';
import { AboutHero } from '@/features/about/ui/AboutHero';
import { PartnershipForm } from '@/features/about/ui/AboutPage';
import { BASE_URL } from '@/shared/config/api/URLs';
import { useQuery } from '@tanstack/react-query';
import { Metadata } from 'next';
import { useParams } from 'next/navigation';
import { useEffect } from 'react';
import AboutSEO from './AboutSEO';
interface Props {
params: { locale: 'uz' | 'ru' | 'en' };
}
// Har requestda server-side yangilanishi
export const revalidate = 0;
// Helper: full image url
function getImageUrl(image?: string | null): string {
if (!image || image.length === 0) return '/placeholder.svg';
if (!image) return '/placeholder.svg';
return image.includes(BASE_URL) ? image : BASE_URL + image;
}
// ====================
// Server-side Metadata
// ====================
interface Props {
params: { locale: 'uz' | 'ru' };
}
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { locale } = params;
@@ -48,33 +39,31 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
? banner.description_ru
: banner.description_en;
const imageUrl = getImageUrl(banner?.image);
return {
title: title || 'Gastro Market',
description: description || 'Gastro Market mahsulotlarini kashf eting',
openGraph: {
title: title || 'Gastro Market',
description: description || 'Gastro Market mahsulotlarini kashf eting',
title,
description,
type: 'website',
images: [
{
url: imageUrl,
url: getImageUrl(banner.image),
width: 1200,
height: 630,
alt: title || 'Gastro Market',
alt: title,
},
],
},
twitter: {
card: 'summary_large_image',
title: title || 'Gastro Market',
description: description || 'Gastro Market mahsulotlarini kashf eting',
images: [imageUrl],
title,
description,
images: [getImageUrl(banner.image)],
},
};
} catch (error) {
console.error('About metadata error:', error);
} catch (err) {
console.error('About metadata error:', err);
return {
title: 'Gastro Market',
description: 'Gastro Market mahsulotlarini kashf eting',
@@ -82,51 +71,10 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
}
}
// ====================
// Client-side SEO Update
// ====================
function AboutSEO() {
const { locale } = useParams();
const { data } = useQuery({
queryKey: ['aboutData'],
queryFn: async () => (await partner_api.getAbout()).data,
});
useEffect(() => {
if (!data) return;
const banner = data.banner;
const title =
locale === 'uz'
? banner.title_uz
: locale === 'ru'
? banner.title_ru
: banner.title_en;
const description =
locale === 'uz'
? banner.description_uz
: locale === 'ru'
? banner.description_ru
: banner.description_en;
document.title = title || 'Gastro Market';
const descMeta = document.querySelector('meta[name="description"]');
if (descMeta) descMeta.setAttribute('content', description || '');
}, [data, locale]);
return null;
}
// ====================
// Page Component
// ====================
const AboutPage = async () => {
return (
<div className="custom-container">
{/* Client-side SEO yangilash */}
<AboutSEO />
{/* Hero + Content + Form */}
<AboutSEO /> {/* Client-side SEO */}
<AboutHero />
<AboutContent />
<PartnershipForm />