From 3e9143f32c82a86b52e83123ccc7c7663f0a3eb1 Mon Sep 17 00:00:00 2001 From: zahravaziri Date: Mon, 9 Jun 2025 17:14:44 +0330 Subject: [PATCH] submit form contactus and start api projects --- contactMessages.json | 18 +++ messages/en.d.json.ts | 11 ++ messages/en.json | 11 ++ messages/fa.json | 24 +++- src/app/[locale]/contact-us/page.tsx | 2 +- src/app/[locale]/page.tsx | 2 + .../contact/contactMessages.json | 0 .../{product_categories => }/contact/route.ts | 7 +- src/app/api/project_categories/data.ts | 118 +++++++++++++++ src/app/api/project_categories/route.ts | 51 +++++++ .../pages/contact/ContactMeForm.tsx | 134 ++++++++++++++++-- src/components/pages/contact/TouchUs.tsx | 24 ++-- src/components/pages/home/Projects.tsx | 66 +++++++++ src/components/pages/project/ProjectGrid.tsx | 17 +-- src/components/pages/project/project.d.ts | 5 + src/components/uikit/inputs/index.tsx | 2 +- src/services/contact.ts | 18 +++ src/services/projects.ts | 40 ++++++ 18 files changed, 515 insertions(+), 35 deletions(-) create mode 100644 contactMessages.json rename src/app/api/{product_categories => }/contact/contactMessages.json (100%) rename src/app/api/{product_categories => }/contact/route.ts (91%) create mode 100644 src/app/api/project_categories/data.ts create mode 100644 src/app/api/project_categories/route.ts create mode 100644 src/components/pages/home/Projects.tsx create mode 100644 src/components/pages/project/project.d.ts create mode 100644 src/services/contact.ts create mode 100644 src/services/projects.ts diff --git a/contactMessages.json b/contactMessages.json new file mode 100644 index 0000000..ff17dd5 --- /dev/null +++ b/contactMessages.json @@ -0,0 +1,18 @@ +[ + { + "first_name": "asd", + "last_name": "asd", + "phone": "123213123213", + "email": "asd@asd.asd", + "message": "asdad", + "createdAt": "2025-06-09T12:36:14.614Z" + }, + { + "first_name": "fvgvbfc", + "last_name": "fcfvgf", + "phone": "09876535434234", + "email": "Zsddftgf@fgh.ir", + "message": "ggbghdghfrgb", + "createdAt": "2025-06-09T13:32:58.185Z" + } +] \ No newline at end of file diff --git a/messages/en.d.json.ts b/messages/en.d.json.ts index 76653b6..8a7fe58 100644 --- a/messages/en.d.json.ts +++ b/messages/en.d.json.ts @@ -78,6 +78,17 @@ declare const messages: { "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" diff --git a/messages/en.json b/messages/en.json index 840ef85..3842d17 100644 --- a/messages/en.json +++ b/messages/en.json @@ -75,6 +75,17 @@ "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" diff --git a/messages/fa.json b/messages/fa.json index 0c37b13..4cdb196 100644 --- a/messages/fa.json +++ b/messages/fa.json @@ -56,7 +56,29 @@ "pages_products_content_description": "آجرها به عنوان یکی از قدیمی‌ترین و پرکاربردترین مصالح ساختمانی بشر، در طول تاریخ دچار تحول زیادی شده‌اند. امروزه این مصالح در طیف بسیار متنوعی تولید و عرضه می‌شوند و به مهندسان و معماران این امکان را می‌دهند تا مناسب‌ترین آجر را برای هر پروژه و نیازی، از سازه‌های سنتی و تاریخی تا ساختمان‌های مدرن و پیشرفته، انتخاب کنند. برای درک بهتر این تنوع، می‌توان آجرها را بر اساس چند معیار کلیدی طبقه‌بندی کرد که هر یک ویژگی‌ها و کاربردهای خاص خود را دارند.\n۱. طبقه‌بندی بر اساس روش تولید: از سنت تا صنعت پیشرفته\nروش تولید آجرها مستقیماً بر ظاهر، بافت و ویژگی‌های آن‌ها تأثیر می‌گذارد.\nآجرهای دستی/قالبی: این آجرها با فشار دادن دستی خاک رس در قالب تولید می‌شوند. نتیجه، آجری با بافت نسبتاً زبر، لبه‌های نامنظم و ظاهری سنتی‌تر است که هر قطعه حس منحصر به فردی دارد. این نوع آجر اغلب برای پروژه‌های مرمت یا ساخت ساختمان‌هایی با سبک روستایی یا قدیمی استفاده می‌شود.\nآجرهای ماشینی: این آجرها با استفاده از ماشین‌آلات صنعتی تولید می‌شوند که دقت ابعادی و یکنواختی ظاهری بسیار بالاتری دارند. آجرهای ماشینی خود به دو دسته اصلی تقسیم می‌شوند:\nآجرهای سوراخ‌دار/توخالی: این آجرها دارای سوراخ‌هایی هستند که چندین مزیت دارند: کاهش وزن ساختمان، بهبود عایق حرارتی و صوتی و افزایش چسبندگی ملات.\nآجرهای توپر: این آجرها بدون سوراخ بوده و مقاومت فشاری بسیار بالایی دارند. آن‌ها برای سازه‌های باربر و دیوارهایی که به حداکثر استحکام نیاز دارند، ایده‌آل هستند.\n۲. طبقه‌بندی بر اساس نوع و ترکیب مواد اولیه: از خاک رس تا بتن\nجنس آجر تعیین‌کننده ویژگی‌های فیزیکی و شیمیایی آن است.", "com_products_products_category_title": "محصولات دسته {title}", - +"com_contact_touch_title": "با ما تماس بگیرید", +"com_contact_touch_title_bold": "", +"com_contact_touch_description": "برای هرگونه سوال، پشتیبانی یا بحث در مورد چگونگی رفع نیازهای صنعتی خود با ما تماس بگیرید.", +"com_contact_touch_option_1":"تماس بگیرید", +"com_contact_touch_option_2":"ایمیل", +"com_contact_touch_option_3":"آدرس ما", +"com_contact_touch_option_3_description":"خیابان سن خوان، پلاک ۷، گراف، فلوریسترات ۲۲A، کد پستی ۳۰۲۱", +"com_contact_title": "با ما تماس بگیرید", +"com_contact_title_bold": "", +"com_contact_first_name": "نام خود را وارد کنید", +"com_contact_last_name": "نام خانوادگی خود را وارد کنید", +"com_contact_email": "ایمیل خود را وارد کنید.", +"com_contact_phone": "شماره تلفن خود را وارد کنید.", +"com_contact_textarea": "پیام خود را وارد کنید", +"com_contact_first_name_required": "نام الزامی است", +"com_contact_last_name_required": "نام خانوادگی الزامی است", +"com_contact_email_required": "ایمیل الزامی است", +"com_contact_phone_required": "شماره تلفن الزامی است", +"com_contact_textarea_required": "پیام الزامی است", +"com_contact_email_error": "ایمیل معتبر نیست", +"com_contact_phone_error": "شماره تماس معتبر نیست (مثلاً: 09123456789)", +"com_contact_textarea_error": "پیام باید حداقل ۱۰ کاراکتر باشد", +"com_contact_button_submit": "ارسال پیام", "pages_notFound_title": "صفحه ۴۰۴ پیدا نشد", "pages_notFound_description": "صفحه‌ای که به دنبال آن هستید وجود ندارد یا منتقل شده است. لطفاً آدرس را بررسی کنید یا به صفحه اصلی بازگردید.", "pages_notFound_button": "بازگشت به صفحه اصلی" diff --git a/src/app/[locale]/contact-us/page.tsx b/src/app/[locale]/contact-us/page.tsx index 1edcafa..935a50f 100644 --- a/src/app/[locale]/contact-us/page.tsx +++ b/src/app/[locale]/contact-us/page.tsx @@ -20,7 +20,7 @@ export default async function Contact({ params }: { params: IPageParams }) { />
-
+
footer-bg + ); diff --git a/src/app/api/product_categories/contact/contactMessages.json b/src/app/api/contact/contactMessages.json similarity index 100% rename from src/app/api/product_categories/contact/contactMessages.json rename to src/app/api/contact/contactMessages.json diff --git a/src/app/api/product_categories/contact/route.ts b/src/app/api/contact/route.ts similarity index 91% rename from src/app/api/product_categories/contact/route.ts rename to src/app/api/contact/route.ts index 1f42807..d30de19 100644 --- a/src/app/api/product_categories/contact/route.ts +++ b/src/app/api/contact/route.ts @@ -7,6 +7,7 @@ const filePath = path.resolve(process.cwd(), 'contactMessages.json'); export async function POST(request: NextRequest) { try { const body = await request.json(); + console.log(body) const { first_name, last_name, phone, email, message } = body; if (!first_name || !last_name || !phone || !email || !message) { @@ -25,7 +26,9 @@ export async function POST(request: NextRequest) { } const newMessage = { - name, + first_name, + last_name, + phone, email, message, createdAt: new Date().toISOString(), @@ -41,6 +44,8 @@ export async function POST(request: NextRequest) { message: 'Your message has been received.', }); } catch (error) { + console.log(error) + console.log(error) return NextResponse.json( { error, message: 'مشکلی پیش آمده.' }, { status: 400 }, diff --git a/src/app/api/project_categories/data.ts b/src/app/api/project_categories/data.ts new file mode 100644 index 0000000..bc7c753 --- /dev/null +++ b/src/app/api/project_categories/data.ts @@ -0,0 +1,118 @@ +export const productCategories = [ + { + id: '1', + title: 'Ghazaghi', + fa_title: 'قزاقی', + icon: 'categoryGhazaghi', + typesCount: 22, + priceTypeTitle: 'Economy', + fa_priceTypeTitle: 'اقتصادی', + bestForTitle: 'Best For Interior Part', + fa_bestForTitle: 'Best For Interior Part', + fa_description: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`, + description: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`, + }, + { + id: '2', + title: 'Ghermez', + fa_title: 'قرمز', + icon: 'categoryGhermez', + typesCount: 12, + priceTypeTitle: 'Luxury', + fa_priceTypeTitle: 'لاکچری', + bestForTitle: 'Best For Exterior Part', + fa_bestForTitle: 'Best For Exterior Part', + fa_description: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`, + description: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`, + }, + { + id: '3', + title: 'oryZard', + fa_title: 'زرد', + icon: 'categoryZard', + typesCount: 11, + priceTypeTitle: 'Economy', + fa_priceTypeTitle: 'اقتصادی', + bestForTitle: 'Best For Facing', + fa_bestForTitle: 'Best For Facing', + fa_description: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`, + description: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`, + }, + { + id: '40', + title: 'Semirom', + fa_title: 'سمیرم', + icon: 'categorySemirom', + typesCount: 40, + priceTypeTitle: 'Economy', + fa_priceTypeTitle: 'اقتصادی', + bestForTitle: 'Best For Building', + fa_bestForTitle: 'Best For Building', + fa_description: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`, + description: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`, + }, +] as APIProductCategoryEntity[]; + +interface APIProductCategoryEntity { + id: string; + title: string; + fa_title?: string; + icon: string; + typesCount: number; + priceTypeTitle: string; + fa_priceTypeTitle?: string; + bestForTitle: string; + fa_bestForTitle?: string; + fa_description?: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`; + description?: `Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. +Facing Bricks: Characteristics and Features +Facing bricks, also known as face bricks or veneer bricks, are specially designed for visible areas of a building, primarily the exterior facades, but also for interior walls where aesthetics are important. Unlike common bricks which are often covered by plaster or other materials, facing bricks are chosen for their visual appeal and ability to withstand environmental conditions. + +Facing Bricks: Characteristics and Features`; +} diff --git a/src/app/api/project_categories/route.ts b/src/app/api/project_categories/route.ts new file mode 100644 index 0000000..4cb1e56 --- /dev/null +++ b/src/app/api/project_categories/route.ts @@ -0,0 +1,51 @@ +import { NextResponse } from 'next/server'; +import { cookies } from 'next/headers'; +import { productCategories } from './data'; + +export async function GET(request: Request) { + let data = productCategories; + + const cookieStore = await cookies(); + const lang = (await cookieStore).get('lang')?.value || 'fa'; + + if (lang === 'fa') { + data = productCategories.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, + }; + }, + ); + } + + return NextResponse.json({ data: productCategories }); +} diff --git a/src/components/pages/contact/ContactMeForm.tsx b/src/components/pages/contact/ContactMeForm.tsx index 28232de..000d5b4 100644 --- a/src/components/pages/contact/ContactMeForm.tsx +++ b/src/components/pages/contact/ContactMeForm.tsx @@ -1,32 +1,148 @@ 'use client'; +import { useState } from 'react'; import Button from '@/components/uikit/button'; import FormField from '@/components/uikit/inputs'; import { useTranslations } from 'next-intl'; +import api from '@/lib/axios'; +import { setContact } from '@/services/contact'; const ContactForm = () => { const t = useTranslations(); + const [formData, setFormData] = useState({ + first_name: '', + last_name: '', + email: '', + phone: '', + message: '', + }); + + const [errors, setErrors] = useState>({}); + const [loading, setLoading] = useState(false); + + const validate = () => { + const newErrors: Record = {}; + + if (!formData.first_name.trim()) + newErrors.first_name = t('com_contact_first_name_required'); + if (!formData.last_name.trim()) + newErrors.last_name = t('com_contact_last_name_required'); + + if (!formData.email) { + newErrors.email = t('com_contact_email_required'); + } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) { + newErrors.email = t('com_contact_email_error'); + } + + if (!formData.phone) { + newErrors.phone = t('com_contact_phone_required'); + } else if (!/^09\d{9}$/.test(formData.phone)) { + newErrors.phone = t('com_contact_phone_error'); + } + + if (!formData.message.trim()) { + newErrors.message = t('com_contact_textarea_required'); + } else if (formData.message.trim().length < 10) { + newErrors.message = t('com_contact_textarea_error'); + } + + setErrors(newErrors); + return Object.keys(newErrors).length === 0; + }; + + const handleChange = (field: string, value: string) => { + setFormData({ ...formData, [field]: value }); + setErrors({ ...errors, [field]: '' }); + }; + + const handleSubmit = (e: React.FormEvent) => { + console.log(e); + e.preventDefault(); + setLoading(true); + setContact(formData).finally(() => { + setLoading(false); + }); + }; + return ( -
+

{t('com_contact_title')}{' '} {t('com_contact_title_bold')}

+
- - -
- - - +
+ handleChange('first_name', e.target.value)} + /> + {errors.first_name && ( +

{errors.first_name}

+ )} +
- +
+ handleChange('last_name', e.target.value)} + /> + {errors.last_name && ( +

{errors.last_name}

+ )} +
+
+ +
+ handleChange('email', e.target.value)} + /> + {errors.email && ( +

{errors.email}

+ )} +
+ +
+ handleChange('phone', e.target.value)} + /> + {errors.phone && ( +

{errors.phone}

+ )} +
+ +
+ handleChange('message', e.target.value)} + /> + {errors.message && ( +

{errors.message}

+ )} +
+ +
-
+ ); }; diff --git a/src/components/pages/contact/TouchUs.tsx b/src/components/pages/contact/TouchUs.tsx index 2a4cdc7..635ed7a 100644 --- a/src/components/pages/contact/TouchUs.tsx +++ b/src/components/pages/contact/TouchUs.tsx @@ -1,5 +1,6 @@ 'use client'; +import SectionTitle from '@/components/layout/sectionTitle'; import { Icon } from '@/components/uikit/icons'; import { useTranslations } from 'next-intl'; @@ -8,23 +9,18 @@ const TouchUs = () => { return (
-
- -

{t('pages_contact_title')}

-
-

- {t('com_contact_touch_title')}{' '} - - {t('com_contact_touch_title_bold')} - -

-

+ +

{t('com_contact_touch_description')}

-
+
@@ -36,7 +32,7 @@ const TouchUs = () => {
-
+
@@ -48,7 +44,7 @@ const TouchUs = () => {
-
+
diff --git a/src/components/pages/home/Projects.tsx b/src/components/pages/home/Projects.tsx new file mode 100644 index 0000000..5183947 --- /dev/null +++ b/src/components/pages/home/Projects.tsx @@ -0,0 +1,66 @@ +import images from '@/assets/images/images'; +import SectionTitle from '@/components/layout/sectionTitle'; +import { getProductCategories } from '@/services/products'; +import Link from 'next/link'; +import routeFactory from '@/assets/constants/routeFactory'; +import { getTranslations } from 'next-intl/server'; +import { TLocales } from '@/models/layout'; +import { getProjectCategories } from '@/services/projects'; +import { IProjectCardProps } from '../project/project'; + +interface Props { + locale: TLocales; +} + +export default async function HomePageProjects({ locale }: Props) { + const t = await getTranslations({ locale }); + + // const projectCategories: IProjectCardProps[] = await getProjectCategories(); + const routes = routeFactory(t, locale); + + return ( +
+
+
+
+ +

+ {t('com_home_products_description')} +

+
+
+ +
+ {/*
+ {projectCategories.map((category, index) => ( + +
+

+ {category.title} +

+ {/*

+ {t('com_products_category_types_count', { + count: category.typesCount, + })} +

+
+ + ))} +
*/} +
+
+ ); +} diff --git a/src/components/pages/project/ProjectGrid.tsx b/src/components/pages/project/ProjectGrid.tsx index 8149bf6..ab5ca9b 100644 --- a/src/components/pages/project/ProjectGrid.tsx +++ b/src/components/pages/project/ProjectGrid.tsx @@ -1,39 +1,40 @@ import images from '@/assets/images/images'; import Image from 'next/image'; import Link from 'next/link'; +import { IProjectCardProps } from './project'; const projects = [ { title: 'Sustainable Practices Reducing Waste in Industrial Production', - image: images.projectImg_1.src, + imageSrc: images.projectImg_1.src, link: '#', }, { title: 'Advanced Robotics Revolutionizing Industrial Workflows', - image: images.projectImg_1.src, + imageSrc: images.projectImg_1.src, link: '#', }, { title: 'Top Benefits of the Robotics in Manufacturing', - image: images.projectImg_1.src, + imageSrc: images.projectImg_1.src, link: '#', }, { title: 'Leveraging Data Analytics for Smarter Production', - image: images.projectImg_1.src, + imageSrc: images.projectImg_1.src, link: '#', }, { title: 'Reducing Operational Costs Through Automation', - image: '/images/post5.jpg', + imageSrc: '/images/post5.jpg', link: '#', }, { title: 'The Advantages of Customized Manufacturing Solutions', - image: '/images/post6.jpg', + imageSrc: '/images/post6.jpg', link: '#', }, -]; +] as IProjectCardProps[]; export default function ProjectsGrid() { return ( @@ -46,7 +47,7 @@ export default function ProjectsGrid() { >
{project.title} = ({ name, }) => { const commonClass = - 'w-full rounded-lg border border-gray-300 p-3 focus:ring-2 focus:ring-red-500 focus:outline-none'; + 'w-full rounded-lg border border-gray-100 p-3 focus:outline-none'; if (type === 'textarea') { return ( diff --git a/src/services/contact.ts b/src/services/contact.ts new file mode 100644 index 0000000..aa3981a --- /dev/null +++ b/src/services/contact.ts @@ -0,0 +1,18 @@ +import api from "@/lib/axios"; + + interface payload { + first_name: string, + last_name: string, + email: string, + phone: string, + message: string, +} + +export async function setContact(payload:payload) { + return api + .post('/contact', payload) + .then(({ data }) => { + return Promise.resolve(); + }) + .catch((error) => Promise.reject(error)); +} diff --git a/src/services/projects.ts b/src/services/projects.ts new file mode 100644 index 0000000..9bb20e9 --- /dev/null +++ b/src/services/projects.ts @@ -0,0 +1,40 @@ +'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 getProjectCategories() { + const cookiesStore = await cookies(); + return api + .get('/project_categories', { + headers: { + Cookie: cookiesStore.toString(), + }, + }) + .then(({ data }) => { + return Promise.resolve(data.data); + }) + .catch((error) => Promise.reject(error)); +} + + + +export async function getProjects( + categoryId: string, + page = 1, +): Promise> { + const cookiesStore = await cookies(); + return api + .get(`/project_categories/${categoryId}/projects`, { + headers: { + Cookie: cookiesStore.toString(), + }, + params: { page }, + }) + .then(({ data }) => { + return Promise.resolve(data); + }) + .catch((error) => Promise.reject(error)); +}