- {/* Title */}
+ {/* Image Container */}
+
+
+ );
+}
diff --git a/components/pages/subCategory/index.ts b/components/pages/subCategory/index.ts
new file mode 100644
index 0000000..a94f692
--- /dev/null
+++ b/components/pages/subCategory/index.ts
@@ -0,0 +1 @@
+export { MainSubCategory } from "./body";
diff --git a/lib/types.ts b/lib/types.ts
index 5b1de65..5c72c1f 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -3,6 +3,7 @@ export interface CategoryType {
name: string;
image: string;
description: string;
+ have_sub_category: boolean;
}
export interface SubCategoryType {
diff --git a/store/useCategory.ts b/store/useCategory.ts
index af27552..eb15eb5 100644
--- a/store/useCategory.ts
+++ b/store/useCategory.ts
@@ -4,6 +4,7 @@ import { create } from "zustand";
interface CategoryZustandType {
category: CategoryType;
setCategory: (category: CategoryType) => void;
+ clearCatalog: () => void;
}
const demoCategory: CategoryType = {
@@ -11,9 +12,11 @@ const demoCategory: CategoryType = {
name: "",
description: "",
image: "",
+ have_sub_category: false,
};
export const useCategory = create((set) => ({
category: demoCategory,
setCategory: (data) => set({ category: data }),
+ clearCatalog: () => set({ category: demoCategory }),
}));
diff --git a/store/useSubCategory.ts b/store/useSubCategory.ts
index 5e34adc..bc16f72 100644
--- a/store/useSubCategory.ts
+++ b/store/useSubCategory.ts
@@ -4,6 +4,7 @@ import { create } from "zustand";
interface SubCategoryZustandType {
subCategory: SubCategoryType;
setSubCategory: (subCategory: SubCategoryType) => void;
+ clearSubCategory: () => void;
}
const demoSubCategory = {
@@ -15,4 +16,5 @@ const demoSubCategory = {
export const useSubCategory = create((set) => ({
subCategory: demoSubCategory,
setSubCategory: (data) => set({ subCategory: data }),
+ clearSubCategory: () => set({ subCategory: demoSubCategory }),
}));
{title}
diff --git a/components/pages/products/product/products.tsx b/components/pages/products/product/products.tsx new file mode 100644 index 0000000..13781d7 --- /dev/null +++ b/components/pages/products/product/products.tsx @@ -0,0 +1,21 @@ +import Filter from "../filter/filter"; +import FilterInfo from "../filter/filterInfo"; +import MainProduct from "./mianProduct"; + +export function Products() { + return ( +
+
+ );
+}
diff --git a/components/pages/products/products.tsx b/components/pages/products/products.tsx
deleted file mode 100644
index 1145797..0000000
--- a/components/pages/products/products.tsx
+++ /dev/null
@@ -1,47 +0,0 @@
-import { ca, lede, slt } from "@/lib/demoData";
-import Filter from "./filter";
-import FilterInfo from "./filterInfo";
-import ProductCard from "./productCard";
-
-// slt , ca , lede
-
-export function Products({ categoryName }: { categoryName: string | null }) {
- console.log("category name: ",categoryName)
- const getProducts = () => {
- switch (categoryName) {
- case "slt":
- return slt;
- case "ca":
- return ca;
- case "lede":
- return lede;
- default:
- return [...slt, ...ca, ...lede];
- }
- };
-
- const products = getProducts();
- return (
-
+
+
+ {/* filter part */}
+
+
+ {/* main products */}
+
+
+
+
+
-
- );
-}
diff --git a/components/pages/subCategory/body.tsx b/components/pages/subCategory/body.tsx
new file mode 100644
index 0000000..1db426e
--- /dev/null
+++ b/components/pages/subCategory/body.tsx
@@ -0,0 +1,56 @@
+"use client";
+
+import httpClient from "@/request/api";
+import { endPoints } from "@/request/links";
+import { useQuery } from "@tanstack/react-query";
+import { useCategory } from "@/store/useCategory";
+import Card from "./card";
+
+export function MainSubCategory() {
+ const category = useCategory((state) => state.category);
+ const { data, isLoading, error } = useQuery({
+ queryKey: ["subCategory"],
+ queryFn: () => httpClient(endPoints.subCategory.byId(category.id)),
+ select: (data) => data?.data?.results,
+ });
+
+ if (isLoading) {
+ return (
+
-
-
- {/* filter part */}
-
-
- {/* main products */}
-
-
-
- {products.map((item, index) => (
-
- ))}
-
-
+ {[1, 2, 3].map((i) => (
+
+ ))}
+
+ );
+ }
+
+ if (error) {
+ return (
+
+ Ma'lumotlarni yuklashda xatolik yuz berdi
+
+ );
+ }
+
+ if (!data || data.length === 0) {
+ return (
+
+ Mahsulotlar topilmadi
+
+ );
+ }
+ return (
+
+ {data.map((item: any) => (
+
+ ))}
+
+ );
+}
diff --git a/components/pages/subCategory/card.tsx b/components/pages/subCategory/card.tsx
new file mode 100644
index 0000000..fa59743
--- /dev/null
+++ b/components/pages/subCategory/card.tsx
@@ -0,0 +1,60 @@
+import { useSubCategory } from "@/store/useSubCategory";
+import { useLocale } from "next-intl";
+import Image from "next/image";
+import Link from "next/link";
+import { useRouter } from "next/navigation";
+
+interface ProductCardProps {
+ id: number;
+ category: number;
+ title: string;
+ image: string;
+ slug: string;
+}
+
+export default function Card({
+ title,
+ image,
+ slug,
+ id,
+ category,
+}: ProductCardProps) {
+ const locale = useLocale();
+ const router = useRouter();
+ const setSubCategory = useSubCategory((state) => state.setSubCategory);
+
+ const handleClick = (e: React.MouseEvent) => {
+ e.preventDefault();
+
+ setSubCategory({
+ id,
+ name: title,
+ image,
+ category,
+ });
+ router.push(`/${locale}/products/${slug}`);
+ };
+ return (
+
+
+
+
+
+ {/* Content Container */}
+
+
+