refactor: clean up message files and improve product category handling
This commit is contained in:
@@ -47,7 +47,7 @@ export default async function ProductPage({
|
||||
productCategory={productCategory}
|
||||
className="mt-6"
|
||||
/>
|
||||
<div className="mt-20">
|
||||
<div id="productList" className="mt-20">
|
||||
<h2 className="mb-6 text-3xl font-semibold text-gray-500">
|
||||
{productCategory.title} Products
|
||||
</h2>
|
||||
|
||||
@@ -4,49 +4,33 @@ import { APIProductCategoryEntity } from '@/models/api';
|
||||
import { productCategoriesData } from './data';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
let data = productCategoriesData as APIProductCategoryEntity[];
|
||||
try {
|
||||
let data = productCategoriesData as APIProductCategoryEntity[];
|
||||
|
||||
const cookieStore = await cookies();
|
||||
const lang = (await cookieStore).get('lang')?.value || 'fa';
|
||||
const cookieStore = await cookies();
|
||||
const lang = (await cookieStore).get('locale')?.value || 'en';
|
||||
console.log('!!!!!!!!!!!!!!!!!!!!');
|
||||
console.log(lang);
|
||||
|
||||
if (lang === 'fa') {
|
||||
data = productCategoriesData.map(
|
||||
({
|
||||
id,
|
||||
title,
|
||||
fa_title,
|
||||
icon,
|
||||
typesCount,
|
||||
priceTypeTitle,
|
||||
fa_priceTypeTitle,
|
||||
bestForTitle,
|
||||
fa_bestForTitle,
|
||||
description,
|
||||
fa_description,
|
||||
}) => {
|
||||
if (lang === 'fa') {
|
||||
return {
|
||||
id,
|
||||
icon,
|
||||
typesCount,
|
||||
title: fa_title || title,
|
||||
priceTypeTitle: fa_priceTypeTitle || priceTypeTitle,
|
||||
bestForTitle: fa_bestForTitle || bestForTitle,
|
||||
description: fa_description || description,
|
||||
};
|
||||
}
|
||||
return {
|
||||
id,
|
||||
icon,
|
||||
typesCount,
|
||||
title,
|
||||
priceTypeTitle,
|
||||
bestForTitle,
|
||||
description,
|
||||
};
|
||||
},
|
||||
if (lang === 'fa') {
|
||||
data = productCategoriesData.map((productCategory) => ({
|
||||
...productCategory,
|
||||
title: (lang && productCategory.fa_title) || productCategory.title,
|
||||
priceTypeTitle:
|
||||
productCategory.fa_priceTypeTitle || productCategory.priceTypeTitle,
|
||||
bestForTitle:
|
||||
productCategory.fa_bestForTitle || productCategory.bestForTitle,
|
||||
description:
|
||||
productCategory.fa_description || productCategory.description,
|
||||
}));
|
||||
}
|
||||
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
console.error('Error fetching product categories:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch product categories' },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ data });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user