LLC/src/view/Landing/components/Products.jsx

101 lines
2.7 KiB
React
Raw Normal View History

2025-02-22 19:14:53 +03:30
import { getLocale, getMessages } from "next-intl/server";
2025-02-17 02:11:47 +03:30
import Link from "next/link";
2025-02-16 09:06:54 +03:30
import React from "react";
2025-02-22 19:14:53 +03:30
import CardNormal from "src/components/Cards/CardNormal";
2025-02-19 16:11:53 +03:30
import ProductCarousel from "src/components/Carousel/ProductCarousel";
2025-02-22 19:14:53 +03:30
import graphql from "src/utils/graphql";
2025-02-16 09:06:54 +03:30
2025-02-22 19:14:53 +03:30
const gql = `
query Products_connection($locale: I18NLocaleCode, $page: Int, $pageSize: Int,$category:String,$brand:String) {
products_connection(
pagination: { page: $page, pageSize: $pageSize }
locale: $locale
sort: ["createdAt:desc"]
filters: {
or:[
{brand: { slug: { eqi: $brand } }}
{category:{ slug: { eqi: $category } }}
]
}
) {
nodes {
title
documentId
images {
alternativeText
documentId
url
}
category {
documentId
title
slug
}
brand {
title
documentId
slug
image {
url
alternativeText
documentId
}
}
slug
}
}
}
`
const getProducts = async (brand = "", category = "") => {
const locale = await getLocale()
const products = await graphql(gql, {
page: 1,
pageSize: 20,
locale: "en",
brand: brand,
category: category
})
2025-02-16 09:06:54 +03:30
2025-02-22 19:14:53 +03:30
return products.products_connection.nodes;
2025-02-19 16:11:53 +03:30
2025-02-22 19:14:53 +03:30
}
const Products = async () => {
const products1 = await getProducts("active")
const products2 = await getProducts("", "construction")
2025-02-16 09:06:54 +03:30
2025-02-22 19:14:53 +03:30
const t = await getMessages()
return (
2025-02-27 16:41:18 +03:30
<div className="my-20 max-w-screen-xl mx-auto px-4">
2025-02-19 16:11:53 +03:30
2025-02-22 19:14:53 +03:30
<div>
<ProductCarousel products={products1} subtitle={""} title={t.HomePage.products.title[0]} showMoreLink={"/products/active"} />
</div>
2025-02-19 16:11:53 +03:30
2025-03-12 04:12:14 +03:30
{/* <div>
2025-03-02 16:53:24 +03:30
<ProductCarousel products={products2} subtitle={""} title={t.HomePage.products.title[1]} showMoreLink={"/products/construction"} />
2025-03-12 04:12:14 +03:30
</div> */}
2025-02-22 19:14:53 +03:30
{/* <div className="grid grid-cols-1 lg:grid-cols-3 gap-5">
2025-02-19 16:11:53 +03:30
{products?.map((product, index) => (
2025-02-16 09:06:54 +03:30
<div key={index} className="relative">
2025-02-19 16:11:53 +03:30
<CardNormal product={product} priority />
2025-02-16 09:06:54 +03:30
</div>
))}
2025-02-19 16:11:53 +03:30
</div> */}
2025-02-17 02:11:47 +03:30
2025-02-22 19:14:53 +03:30
{/* <div className="flex justify-center">
2025-02-17 02:11:47 +03:30
<Link href={"categories/Product-20Listing-Page"}>
<button className="btn btn-primary px-10 text-sm ">
{" "}
See All Products
</button>
</Link>
2025-02-19 15:04:53 +03:30
</div> */}
2025-02-16 09:06:54 +03:30
</div>
2025-02-22 19:14:53 +03:30
2025-02-16 09:06:54 +03:30
);
};
export default Products;