update product component sorted base static data
This commit is contained in:
@@ -91,7 +91,7 @@ export default function InnerProductcard({ data }: { data: any }) {
|
|||||||
{/* Nomi va tavsif */}
|
{/* Nomi va tavsif */}
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<h3
|
<h3
|
||||||
className="text-xl font-bold text-[#0c1239] mb-2 line-clamp-2
|
className="text-lg font-bold text-[#0c1239] mb-2 line-clamp-2
|
||||||
group-hover:text-[#f2a01c] transition-colors duration-300"
|
group-hover:text-[#f2a01c] transition-colors duration-300"
|
||||||
>
|
>
|
||||||
<Text txt={data.name} />
|
<Text txt={data.name} />
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ export default function CarRentalModal({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const token =
|
const token = "8277200651:AAHYi2iE7bW0PEfEahTFyqFQhUcR9bGZnnY";
|
||||||
process.env.NEXT_PUBLIC_TELEGRAM_TOKEN ||
|
// "7940057045:AAHRFPvgUCo_7pqpXD6uq4li7-_DYx2J96g"
|
||||||
"7940057045:AAHRFPvgUCo_7pqpXD6uq4li7-_DYx2J96g";
|
const chatId = "6735606461"
|
||||||
const chatId = process.env.NEXT_PUBLIC_TELEGRAM_CHAT_ID || "6134458285";
|
// "6134458285";
|
||||||
|
|
||||||
const message = `
|
const message = `
|
||||||
🚗 *Yangi buyurtma!*
|
🚗 *Yangi buyurtma!*
|
||||||
|
|||||||
@@ -10,6 +10,22 @@ import { EmptyState } from "@/components/emptyState";
|
|||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
import { baseUrl } from "@/data/url";
|
import { baseUrl } from "@/data/url";
|
||||||
|
|
||||||
|
// Kerakli tartib (id lar bo'yicha)
|
||||||
|
const CATEGORY_ORDER: number[] = [1, 2, 3, 4, 6, 5, 8, 9, 23, 11, 12, 10, 14, 26, 17, 13, 20, 19, 21, 28];
|
||||||
|
|
||||||
|
function sortByCustomOrder(data: ProductTypes[]): ProductTypes[] {
|
||||||
|
return [...data].sort((a, b) => {
|
||||||
|
const indexA = CATEGORY_ORDER.indexOf(a.id);
|
||||||
|
const indexB = CATEGORY_ORDER.indexOf(b.id);
|
||||||
|
|
||||||
|
// Agar id topilmasa - oxiriga surish
|
||||||
|
if (indexA === -1) return 1;
|
||||||
|
if (indexB === -1) return -1;
|
||||||
|
|
||||||
|
return indexA - indexB;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default function Products() {
|
export default function Products() {
|
||||||
const [cars, setCars] = useState<ProductTypes[]>([]);
|
const [cars, setCars] = useState<ProductTypes[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -34,15 +50,15 @@ export default function Products() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log("backend Data: ", data?.data);
|
|
||||||
|
|
||||||
if (data?.data && data.data.length > 0) {
|
if (data?.data && data.data.length > 0) {
|
||||||
setCars(data.data);
|
// ✅ Qayta tartiblash
|
||||||
|
const sorted = sortByCustomOrder(data.data);
|
||||||
|
setCars(sorted);
|
||||||
} else {
|
} else {
|
||||||
setCars([]);
|
setCars([]);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Xatolik: ", error);
|
|
||||||
setError(error instanceof Error ? error.message : "Noma'lum xatolik");
|
setError(error instanceof Error ? error.message : "Noma'lum xatolik");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -54,7 +70,6 @@ export default function Products() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div dir="ltr" className="max-w-[1200px] w-full mx-auto">
|
<div dir="ltr" className="max-w-[1200px] w-full mx-auto">
|
||||||
{/* title part */}
|
|
||||||
<div className="flex flex-col mb-10">
|
<div className="flex flex-col mb-10">
|
||||||
<div className="flex items-center justify-center w-full">
|
<div className="flex items-center justify-center w-full">
|
||||||
<div className="text-[#f2a01c] px-2 text-[18px] font-semibold">
|
<div className="text-[#f2a01c] px-2 text-[18px] font-semibold">
|
||||||
@@ -64,7 +79,6 @@ export default function Products() {
|
|||||||
<Title text="pricing-h2" />
|
<Title text="pricing-h2" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Error message */}
|
|
||||||
{error && (
|
{error && (
|
||||||
<div className="mb-4 p-4 bg-red-50 border border-red-200 rounded-lg">
|
<div className="mb-4 p-4 bg-red-50 border border-red-200 rounded-lg">
|
||||||
<p className="text-red-600 text-center">
|
<p className="text-red-600 text-center">
|
||||||
@@ -73,7 +87,6 @@ export default function Products() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* products */}
|
|
||||||
<div className="px-4 grid gap-5 grid-cols-1 place-content-center min-[500px]:grid-cols-2 min-lg:grid-cols-4 min-[1210px]:grid-cols-4">
|
<div className="px-4 grid gap-5 grid-cols-1 place-content-center min-[500px]:grid-cols-2 min-lg:grid-cols-4 min-[1210px]:grid-cols-4">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<LoadingSkeleton />
|
<LoadingSkeleton />
|
||||||
|
|||||||
Reference in New Issue
Block a user