From 9d5c40ff5bf131fbee536b4fb9352da0d0fcbcd5 Mon Sep 17 00:00:00 2001 From: ahasani194 Date: Sat, 14 Jun 2025 15:37:20 +0330 Subject: [PATCH] refactor: clean up message files and improve product category handling --- messages/en.d.json.ts | 60 ++++++++--------- messages/en.json | 60 ++++++++--------- .../[product_category_id]/page.tsx | 2 +- src/app/api/product_categories/route.ts | 66 +++++++------------ src/assets/constants/routeFactory/index.ts | 2 +- src/components/layout/header/index.tsx | 9 ++- .../pages/products/productList/index.tsx | 4 ++ src/services/projects.ts | 3 - 8 files changed, 93 insertions(+), 113 deletions(-) diff --git a/messages/en.d.json.ts b/messages/en.d.json.ts index 0fc822e..f49a419 100644 --- a/messages/en.d.json.ts +++ b/messages/en.d.json.ts @@ -36,7 +36,6 @@ declare const messages: { "com_home_projects_title_bold": "initiatives", "com_home_projects_description": "Our successful project initiatives showcase our commitment to excellence and innovation across various industries.", - "footer_title": "Industrial Solutions for a Modern World", "footer_description": "We are committed to providing personalized industrial solutions that meet the unique needs of our clients. Our team of experts is dedicated to delivering high-quality products and services that drive success in today’s competitive market.", "footer_slogan": "We are committed to providing personalized industrial solutions.", @@ -58,45 +57,40 @@ declare const messages: { "com_products_category_Ghermez_title": "Ghermez", "com_products_category_Semirom_title": "Semirom", "com_products_category_Zard_title": "Zard", - "com_products_category_types_count": "count Types", + "com_products_category_types_count": "{count} types", "com_products_category_show_all_CTA": "Show Products", "pages_products_content_title": "Brick Classification: Understanding the Variety and Applications", "pages_products_content_description": "Bricks, as one of humanity's oldest and most widely used building materials, have evolved significantly throughout history. Today, they are produced and supplied in an incredibly diverse range, allowing engineers and architects to choose the most suitable brick for any project and need, from traditional and historic structures to modern and advanced buildings. To better understand this diversity, we can classify bricks based on several key criteria, each with its own specific characteristics and applications. \n 1. Classification by Manufacturing Method: From Tradition to Advanced IndustryThe method by which bricks are produced directly impacts their appearance, texture, and properties. Hand-moulded/Stock Bricks: These bricks are produced by manually pressing clay into molds. The result is a brick with a relatively rough texture, uneven edges, and a more traditional appearance, where each piece feels unique. This type of brick is often used for restoration projects or for constructing buildings with a rustic or antique style. Machine-made Bricks: These bricks are produced using industrial machinery, resulting in much higher precision in dimensions and uniformity in appearance. Machine-made bricks themselves are divided into two main categories: Perforated/Hollow Bricks: These bricks have holes, offering several advantages: they reduce building weight, improve thermal and acoustic insulation, and enhance mortar adhesion. Solid Bricks: These bricks are without holes and possess very high compressive strength. They are ideal for load-bearing structures and walls requiring maximum strength. 2. Classification by Raw Material Type and Composition: From Clay to Concrete The material from which a brick is made determines its physical and chemical properties.", "com_products_products_category_title": "Products of {title} Category", + "com_contact_touch_title": "Get in touch", + "com_contact_touch_title_bold": "with us", + "com_contact_touch_description": "Reach out for any inquiries, support, or to discuss how we can meet your industrial needs.", + "com_contact_touch_option_1": "Contact", + "com_contact_touch_option_2": "e-mail", + "com_contact_touch_option_3": "Our Address", + "com_contact_touch_option_3_description": "7 San Juan Lane Graaf Florisstraat 22A,3021 CH", + "com_contact_title": "Contact ", + "com_contact_title_bold": "me", + "com_contact_first_name": "Enter first name", + "com_contact_last_name": "Enter last name", + "com_contact_email": "Enter your e-mail", + "com_contact_phone": "Enter your phone no.", + "com_contact_textarea": "Write Message", + "com_contact_first_name_required": "Name is required", + "com_contact_last_name_required": "Last name is required", + "com_contact_email_required": "Email is required", + "com_contact_phone_required": "Phone is required", + "com_contact_textarea_required": "Message is required", - -"com_contact_touch_title": "Get in touch", -"com_contact_touch_title_bold": "with us", -"com_contact_touch_description": "Reach out for any inquiries, support, or to discuss how we can meet your industrial needs.", -"com_contact_touch_option_1":"Contact", -"com_contact_touch_option_2":"e-mail", -"com_contact_touch_option_3":"Our Address", -"com_contact_touch_option_3_description":"7 San Juan Lane Graaf Florisstraat 22A,3021 CH", -"com_contact_title": "Contact ", -"com_contact_title_bold": "me", -"com_contact_first_name": "Enter first name", -"com_contact_last_name": "Enter last name", -"com_contact_email": "Enter your e-mail", -"com_contact_phone": "Enter your phone no.", -"com_contact_textarea": "Write Message", - -"com_contact_first_name_required": "Name is required", -"com_contact_last_name_required": "Last name is required", -"com_contact_email_required": "Email is required", -"com_contact_phone_required": "Phone is required", -"com_contact_textarea_required": "Message is required", - - -"com_contact_email_error": "Email is not valid", -"com_contact_phone_error": "The contact number is not valid (for example: 09123456789)", -"com_contact_textarea_error": "Message must be at least 10 characters long.", -"com_contact_button_submit": "Submit Message", -"pages_notFound_title": "404 Not Found Page", -"pages_notFound_description": "You can either head back to the Homepage or try a search.", -"pages_notFound_button":"Go To Home" - + "com_contact_email_error": "Email is not valid", + "com_contact_phone_error": "The contact number is not valid (for example: 09123456789)", + "com_contact_textarea_error": "Message must be at least 10 characters long.", + "com_contact_button_submit": "Submit Message", + "pages_notFound_title": "404 Not Found Page", + "pages_notFound_description": "You can either head back to the Homepage or try a search.", + "pages_notFound_button": "Go To Home" }; export default messages; \ No newline at end of file diff --git a/messages/en.json b/messages/en.json index f819236..fab6c62 100644 --- a/messages/en.json +++ b/messages/en.json @@ -33,7 +33,6 @@ "com_home_projects_title_bold": "initiatives", "com_home_projects_description": "Our successful project initiatives showcase our commitment to excellence and innovation across various industries.", - "footer_title": "Industrial Solutions for a Modern World", "footer_description": "We are committed to providing personalized industrial solutions that meet the unique needs of our clients. Our team of experts is dedicated to delivering high-quality products and services that drive success in today’s competitive market.", "footer_slogan": "We are committed to providing personalized industrial solutions.", @@ -55,44 +54,39 @@ "com_products_category_Ghermez_title": "Ghermez", "com_products_category_Semirom_title": "Semirom", "com_products_category_Zard_title": "Zard", - "com_products_category_types_count": "count Types", + "com_products_category_types_count": "{count} types", "com_products_category_show_all_CTA": "Show Products", "pages_products_content_title": "Brick Classification: Understanding the Variety and Applications", "pages_products_content_description": "Bricks, as one of humanity's oldest and most widely used building materials, have evolved significantly throughout history. Today, they are produced and supplied in an incredibly diverse range, allowing engineers and architects to choose the most suitable brick for any project and need, from traditional and historic structures to modern and advanced buildings. To better understand this diversity, we can classify bricks based on several key criteria, each with its own specific characteristics and applications. \n 1. Classification by Manufacturing Method: From Tradition to Advanced IndustryThe method by which bricks are produced directly impacts their appearance, texture, and properties. Hand-moulded/Stock Bricks: These bricks are produced by manually pressing clay into molds. The result is a brick with a relatively rough texture, uneven edges, and a more traditional appearance, where each piece feels unique. This type of brick is often used for restoration projects or for constructing buildings with a rustic or antique style. Machine-made Bricks: These bricks are produced using industrial machinery, resulting in much higher precision in dimensions and uniformity in appearance. Machine-made bricks themselves are divided into two main categories: Perforated/Hollow Bricks: These bricks have holes, offering several advantages: they reduce building weight, improve thermal and acoustic insulation, and enhance mortar adhesion. Solid Bricks: These bricks are without holes and possess very high compressive strength. They are ideal for load-bearing structures and walls requiring maximum strength. 2. Classification by Raw Material Type and Composition: From Clay to Concrete The material from which a brick is made determines its physical and chemical properties.", "com_products_products_category_title": "Products of {title} Category", + "com_contact_touch_title": "Get in touch", + "com_contact_touch_title_bold": "with us", + "com_contact_touch_description": "Reach out for any inquiries, support, or to discuss how we can meet your industrial needs.", + "com_contact_touch_option_1": "Contact", + "com_contact_touch_option_2": "e-mail", + "com_contact_touch_option_3": "Our Address", + "com_contact_touch_option_3_description": "7 San Juan Lane Graaf Florisstraat 22A,3021 CH", + "com_contact_title": "Contact ", + "com_contact_title_bold": "me", + "com_contact_first_name": "Enter first name", + "com_contact_last_name": "Enter last name", + "com_contact_email": "Enter your e-mail", + "com_contact_phone": "Enter your phone no.", + "com_contact_textarea": "Write Message", + "com_contact_first_name_required": "Name is required", + "com_contact_last_name_required": "Last name is required", + "com_contact_email_required": "Email is required", + "com_contact_phone_required": "Phone is required", + "com_contact_textarea_required": "Message is required", - -"com_contact_touch_title": "Get in touch", -"com_contact_touch_title_bold": "with us", -"com_contact_touch_description": "Reach out for any inquiries, support, or to discuss how we can meet your industrial needs.", -"com_contact_touch_option_1":"Contact", -"com_contact_touch_option_2":"e-mail", -"com_contact_touch_option_3":"Our Address", -"com_contact_touch_option_3_description":"7 San Juan Lane Graaf Florisstraat 22A,3021 CH", -"com_contact_title": "Contact ", -"com_contact_title_bold": "me", -"com_contact_first_name": "Enter first name", -"com_contact_last_name": "Enter last name", -"com_contact_email": "Enter your e-mail", -"com_contact_phone": "Enter your phone no.", -"com_contact_textarea": "Write Message", - -"com_contact_first_name_required": "Name is required", -"com_contact_last_name_required": "Last name is required", -"com_contact_email_required": "Email is required", -"com_contact_phone_required": "Phone is required", -"com_contact_textarea_required": "Message is required", - - -"com_contact_email_error": "Email is not valid", -"com_contact_phone_error": "The contact number is not valid (for example: 09123456789)", -"com_contact_textarea_error": "Message must be at least 10 characters long.", -"com_contact_button_submit": "Submit Message", -"pages_notFound_title": "404 Not Found Page", -"pages_notFound_description": "You can either head back to the Homepage or try a search.", -"pages_notFound_button":"Go To Home" - + "com_contact_email_error": "Email is not valid", + "com_contact_phone_error": "The contact number is not valid (for example: 09123456789)", + "com_contact_textarea_error": "Message must be at least 10 characters long.", + "com_contact_button_submit": "Submit Message", + "pages_notFound_title": "404 Not Found Page", + "pages_notFound_description": "You can either head back to the Homepage or try a search.", + "pages_notFound_button": "Go To Home" } diff --git a/src/app/[locale]/product-categories/[product_category_id]/page.tsx b/src/app/[locale]/product-categories/[product_category_id]/page.tsx index d7d6768..fd0889a 100644 --- a/src/app/[locale]/product-categories/[product_category_id]/page.tsx +++ b/src/app/[locale]/product-categories/[product_category_id]/page.tsx @@ -47,7 +47,7 @@ export default async function ProductPage({ productCategory={productCategory} className="mt-6" /> -
+

{productCategory.title} Products

diff --git a/src/app/api/product_categories/route.ts b/src/app/api/product_categories/route.ts index 166f826..3a39120 100644 --- a/src/app/api/product_categories/route.ts +++ b/src/app/api/product_categories/route.ts @@ -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 }); } diff --git a/src/assets/constants/routeFactory/index.ts b/src/assets/constants/routeFactory/index.ts index 8db0ada..4dd2e59 100644 --- a/src/assets/constants/routeFactory/index.ts +++ b/src/assets/constants/routeFactory/index.ts @@ -34,7 +34,7 @@ const routeFactory: RouteFactory = (t, locale) => ({ }, blog: { title: t('pages_blog_title'), - route: () => `/${locale}/blog-us`, + route: () => `/${locale}/blog`, }, contact: { title: t('pages_contact_title'), diff --git a/src/components/layout/header/index.tsx b/src/components/layout/header/index.tsx index 2917b3d..e6a74c8 100644 --- a/src/components/layout/header/index.tsx +++ b/src/components/layout/header/index.tsx @@ -5,15 +5,20 @@ import Navbar from '../navbar'; import Button, { IconButton } from '@/components/uikit/button'; import { Icon } from '@/components/uikit/icons'; import { useTranslations } from 'next-intl'; +import routeFactory from '@/assets/constants/routeFactory'; +import { useParams } from 'next/navigation'; export default function Header() { const t = useTranslations(); + const params = useParams(); + const locale = params.locale as string; const bannerFooter = [ t('com_home_Banner_link1'), t('com_home_Banner_link2'), t('com_home_Banner_link3'), ]; + const routes = routeFactory(t, locale); return (
- +
diff --git a/src/components/pages/products/productList/index.tsx b/src/components/pages/products/productList/index.tsx index c0741af..36dd034 100644 --- a/src/components/pages/products/productList/index.tsx +++ b/src/components/pages/products/productList/index.tsx @@ -19,6 +19,10 @@ export default function ProductList({ .then((res) => { setProducts(res.data); setPagination(res.pagination); + + document + .getElementById('productList') + ?.scrollIntoView({ behavior: 'smooth', block: 'start' }); }) .catch((error) => { console.error('Failed to fetch products:', error); diff --git a/src/services/projects.ts b/src/services/projects.ts index c7594c8..3c33c7a 100644 --- a/src/services/projects.ts +++ b/src/services/projects.ts @@ -1,8 +1,6 @@ 'use server'; -import { IProjectCardProps } from '@/components/pages/project/project'; import api from '@/lib/axios'; -import { IResponse } from '@/models/response'; import { cookies } from 'next/headers'; export async function getProjects() { @@ -12,7 +10,6 @@ export async function getProjects() { headers: { Cookie: cookiesStore.toString(), }, - }) .then(({ data }) => Promise.resolve(data.data)) .catch((error) => Promise.reject(error));