added collection page
This commit is contained in:
@@ -25,6 +25,7 @@ export default function CartPage() {
|
|||||||
const [note, setNote] = useState<string>("");
|
const [note, setNote] = useState<string>("");
|
||||||
const [phone, setPhone] = useState<string>("");
|
const [phone, setPhone] = useState<string>("");
|
||||||
const [name, setName] = useState<string>("");
|
const [name, setName] = useState<string>("");
|
||||||
|
const [lastName, setLastName] = useState<string>("");
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ export default function CartPage() {
|
|||||||
const orderData = userStore.getOrderData();
|
const orderData = userStore.getOrderData();
|
||||||
if (orderData) {
|
if (orderData) {
|
||||||
if (orderData.customer_name) setName(orderData.customer_name);
|
if (orderData.customer_name) setName(orderData.customer_name);
|
||||||
|
if (orderData.customer_last_name) setLastName(orderData.customer_last_name);
|
||||||
if (orderData.customer_phone) setPhone(orderData.customer_phone);
|
if (orderData.customer_phone) setPhone(orderData.customer_phone);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
@@ -227,8 +229,10 @@ export default function CartPage() {
|
|||||||
paymentTypes={paymentTypes}
|
paymentTypes={paymentTypes}
|
||||||
phone={phone}
|
phone={phone}
|
||||||
name={name}
|
name={name}
|
||||||
|
lastName={lastName}
|
||||||
onPhoneChange={setPhone}
|
onPhoneChange={setPhone}
|
||||||
onNameChange={setName}
|
onNameChange={setName}
|
||||||
|
onLastNameChange={setLastName}
|
||||||
onPaymentTypeChange={setPaymentType}
|
onPaymentTypeChange={setPaymentType}
|
||||||
onDeliveryTypeChange={handleDeliveryTypeChange}
|
onDeliveryTypeChange={handleDeliveryTypeChange}
|
||||||
onRegionChange={setSelectedRegion}
|
onRegionChange={setSelectedRegion}
|
||||||
|
|||||||
38
app/[locale]/collections/[slug]/page.tsx
Normal file
38
app/[locale]/collections/[slug]/page.tsx
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import type { Metadata } from "next"
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
params: Promise<{ locale: string; slug: string }>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const revalidate = 600 // ISR: Revalidate every 10 minutes
|
||||||
|
|
||||||
|
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||||
|
const { locale, slug } = await params
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `${slug.charAt(0).toUpperCase() + slug.slice(1)} | E-Commerce`,
|
||||||
|
description: `Browse ${slug} collection products in our store`,
|
||||||
|
openGraph: {
|
||||||
|
locale,
|
||||||
|
type: "website",
|
||||||
|
title: `${slug.charAt(0).toUpperCase() + slug.slice(1)} | E-Commerce`,
|
||||||
|
description: `Browse ${slug} collection products in our store`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function generateStaticParams() {
|
||||||
|
// Generate static params for popular collections
|
||||||
|
const collections = ["new-arrivals", "best-sellers", "featured"]
|
||||||
|
return collections.map((slug) => ({ slug }))
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function CollectionPage(props: Props) {
|
||||||
|
const params = await props.params
|
||||||
|
|
||||||
|
const CollectionPageClient = (
|
||||||
|
await import("../../../../features/collections/components/CollectionPageClient")
|
||||||
|
).default
|
||||||
|
|
||||||
|
return <CollectionPageClient params={params} />
|
||||||
|
}
|
||||||
@@ -13,23 +13,22 @@ const metadataContent = {
|
|||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
interface PageProps {
|
interface PageProps {
|
||||||
params: {
|
params: Promise<{
|
||||||
locale: string;
|
locale: string;
|
||||||
};
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateMetadata(
|
export async function generateMetadata(
|
||||||
{ params }: PageProps,
|
{ params }: PageProps,
|
||||||
parent: ResolvingMetadata
|
parent: ResolvingMetadata
|
||||||
): Promise<Metadata> {
|
): Promise<Metadata> {
|
||||||
const locale = params.locale as keyof typeof metadataContent;
|
const { locale } = await params;
|
||||||
|
const localeKey = locale as keyof typeof metadataContent;
|
||||||
const content = metadataContent[locale] || metadataContent.ru;
|
const content = metadataContent[localeKey] || metadataContent.ru;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: content.title,
|
title: content.title,
|
||||||
description: content.description,
|
description: content.description,
|
||||||
|
|
||||||
robots: {
|
robots: {
|
||||||
index: false,
|
index: false,
|
||||||
follow: false,
|
follow: false,
|
||||||
@@ -39,5 +38,6 @@ export async function generateMetadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function OrdersPage({ params }: PageProps) {
|
export default async function OrdersPage({ params }: PageProps) {
|
||||||
return <OrdersPageClient locale={params.locale} />;
|
const { locale } = await params;
|
||||||
}
|
return <OrdersPageClient locale={locale} />;
|
||||||
|
}
|
||||||
@@ -81,7 +81,7 @@ export default function Header({ locale = "ru" }: HeaderProps) {
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={toggleCategoryMenu}
|
onClick={toggleCategoryMenu}
|
||||||
className="hidden gap-2 rounded-xl font-bold sm:flex hover:bg-[#005bff] bg-[#005bff] text-white"
|
className="hidden gap-2 rounded-lg font-bold sm:flex hover:bg-[#005bff] bg-[#005bff] text-white"
|
||||||
size="lg"
|
size="lg"
|
||||||
>
|
>
|
||||||
{isCategoryOpen ? <X className="h-5 w-5" /> : <CategoryIcon />}
|
{isCategoryOpen ? <X className="h-5 w-5" /> : <CategoryIcon />}
|
||||||
@@ -131,19 +131,10 @@ export default function Header({ locale = "ru" }: HeaderProps) {
|
|||||||
<AuthDialog isOpen={isLoginOpen} onClose={() => setIsLoginOpen(false)} />
|
<AuthDialog isOpen={isLoginOpen} onClose={() => setIsLoginOpen(false)} />
|
||||||
|
|
||||||
<MobileBottomNav
|
<MobileBottomNav
|
||||||
locale={locale}
|
locale={locale}
|
||||||
isAuthenticated={isAuthenticated}
|
|
||||||
translations={{
|
onLoginClick={() => setIsLoginOpen(true)}
|
||||||
catalog: t("common.catalog"),
|
/>
|
||||||
favorites: t("common.favorites"),
|
|
||||||
orders: t("common.orders"),
|
|
||||||
cart: t("common.cart"),
|
|
||||||
login: t("common.login"),
|
|
||||||
profile: t("profile"),
|
|
||||||
}}
|
|
||||||
onLoginClick={() => setIsLoginOpen(true)}
|
|
||||||
onProfileClick={handleProfileClick}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,10 @@ import {
|
|||||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||||
import { useCategories, useCart, useFavorites, useOrders } from "@/lib/hooks";
|
import { useCategories, useCart, useFavorites, useOrders } from "@/lib/hooks";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useAuthStatus } from "@/lib/hooks/useAuth";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
interface MobileBottomNavProps {
|
interface MobileBottomNavProps {
|
||||||
locale?: string;
|
locale?: string;
|
||||||
isAuthenticated?: boolean;
|
|
||||||
translations?: {
|
translations?: {
|
||||||
catalog: string;
|
catalog: string;
|
||||||
favorites: string;
|
favorites: string;
|
||||||
@@ -26,48 +27,56 @@ interface MobileBottomNavProps {
|
|||||||
profile: string;
|
profile: string;
|
||||||
};
|
};
|
||||||
onLoginClick?: () => void;
|
onLoginClick?: () => void;
|
||||||
onProfileClick?: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function MobileBottomNav({
|
export default function MobileBottomNav({
|
||||||
locale = "ru",
|
locale = "ru",
|
||||||
isAuthenticated = false,
|
|
||||||
translations,
|
translations,
|
||||||
onLoginClick,
|
onLoginClick,
|
||||||
onProfileClick, // EKLENEN
|
|
||||||
}: MobileBottomNavProps) {
|
}: MobileBottomNavProps) {
|
||||||
const [isClient, setIsClient] = useState(false);
|
const [isClient, setIsClient] = useState(false);
|
||||||
const [isCategoryOpen, setIsCategoryOpen] = useState(false);
|
const [isCategoryOpen, setIsCategoryOpen] = useState(false);
|
||||||
|
const t = useTranslations();
|
||||||
|
// AUTH STATE DIRECTLY FROM HOOK - NOT FROM PROPS
|
||||||
|
const { isAuthenticated, isLoading: authLoading } = useAuthStatus();
|
||||||
|
|
||||||
const { data: categories = [] } = useCategories();
|
const { data: categories = [] } = useCategories();
|
||||||
const { data: cartData } = useCart();
|
const { data: cartData } = useCart();
|
||||||
const { data: favoritesData } = useFavorites();
|
const { data: favoritesData } = useFavorites();
|
||||||
const { data: ordersData } = useOrders();
|
const { data: ordersData } = useOrders();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const t = translations || {
|
|
||||||
catalog: "Каталог",
|
|
||||||
favorites: "Избранное",
|
|
||||||
orders: "Заказы",
|
|
||||||
cart: "Корзина",
|
|
||||||
login: "Войти",
|
|
||||||
profile: "Профиль",
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsClient(true);
|
setIsClient(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleAuthClick = () => {
|
|
||||||
if (isAuthenticated) {
|
|
||||||
if (onProfileClick) {
|
const handleProfileClick = (e: React.MouseEvent) => {
|
||||||
onProfileClick();
|
e.preventDefault();
|
||||||
} else {
|
e.stopPropagation();
|
||||||
router.push(`/${locale}/me`);
|
|
||||||
console.log("hello");
|
|
||||||
}
|
|
||||||
} else if (onLoginClick) {
|
if (authLoading) {
|
||||||
onLoginClick();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isAuthenticated) {
|
||||||
|
router.push(`/${locale}/me`);
|
||||||
|
} else {
|
||||||
|
if (onLoginClick) {
|
||||||
|
onLoginClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNavigation = (path: string) => (e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log("[MobileBottomNav] Navigating to:", path);
|
||||||
|
router.push(path);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isClient) return null;
|
if (!isClient) return null;
|
||||||
@@ -82,94 +91,85 @@ export default function MobileBottomNav({
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex-col gap-0.5 h-auto px-2 py-2"
|
className="flex-col gap-0.5 h-auto px-2 py-2"
|
||||||
onClick={() => setIsCategoryOpen(true)}
|
onClick={() => {
|
||||||
|
console.log("[MobileBottomNav] Catalog clicked");
|
||||||
|
setIsCategoryOpen(true);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Menu className="h-5 w-5 text-gray-600" />
|
<Menu className="h-5 w-5 text-gray-600" />
|
||||||
<span className="text-xs text-gray-700">{t.catalog}</span>
|
<span className="text-xs text-gray-700">{t("common.catalog")}</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{/* Favorites Button */}
|
{/* Favorites Button */}
|
||||||
<Link href="/favorites">
|
<Button
|
||||||
<Button
|
variant="ghost"
|
||||||
variant="ghost"
|
size="sm"
|
||||||
size="sm"
|
className="relative flex-col gap-0.5 h-auto px-2 py-2"
|
||||||
className="relative flex-col gap-0.5 h-auto px-2 py-2"
|
onClick={handleNavigation("/favorites")}
|
||||||
>
|
>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Heart className="h-5 w-5 text-gray-600" />
|
<Heart className="h-5 w-5 text-gray-600" />
|
||||||
<Badge
|
<Badge
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
||||||
>
|
>
|
||||||
{favoritesData?.length || 0}
|
{favoritesData?.length || 0}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-xs text-gray-700">{t.favorites}</span>
|
<span className="text-xs text-gray-700">{t("common.favorites")}</span>
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
|
||||||
|
|
||||||
{/* Orders Button */}
|
{/* Orders Button */}
|
||||||
<Link href="/orders">
|
<Button
|
||||||
<Button
|
variant="ghost"
|
||||||
variant="ghost"
|
size="sm"
|
||||||
size="sm"
|
className="relative flex-col gap-0.5 h-auto px-2 py-2"
|
||||||
className="relative flex-col gap-0.5 h-auto px-2 py-2"
|
onClick={handleNavigation("/orders")}
|
||||||
>
|
>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Truck className="h-5 w-5 text-gray-600" />
|
<Truck className="h-5 w-5 text-gray-600" />
|
||||||
<Badge
|
<Badge
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
||||||
>
|
>
|
||||||
{ordersData?.length || 0}
|
{ordersData?.length || 0}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-xs text-gray-700">{t.orders}</span>
|
<span className="text-xs text-gray-700">{t("common.orders")}</span>
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
|
||||||
|
|
||||||
{/* Cart Button */}
|
{/* Cart Button */}
|
||||||
<Link href="/cart">
|
<Button
|
||||||
<Button
|
variant="ghost"
|
||||||
variant="ghost"
|
size="sm"
|
||||||
size="sm"
|
className="relative flex-col gap-0.5 h-auto px-2 py-2"
|
||||||
className="relative flex-col gap-0.5 h-auto px-2 py-2"
|
onClick={handleNavigation("/cart")}
|
||||||
>
|
>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<ShoppingCart className="h-5 w-5 text-gray-600" />
|
<ShoppingCart className="h-5 w-5 text-gray-600" />
|
||||||
<Badge
|
<Badge
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
||||||
>
|
|
||||||
{cartData?.data?.length || 0}
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
<span className="text-xs text-gray-700">{t.cart}</span>
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
{isAuthenticated ? (
|
|
||||||
<Link href={`/${locale}/me`}>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
className="flex-col gap-0.5 h-auto px-2 py-2"
|
|
||||||
>
|
>
|
||||||
<User className="h-5 w-5 text-gray-600" />
|
{cartData?.data?.length || 0}
|
||||||
<span className="text-xs text-gray-700">{t.profile}</span>
|
</Badge>
|
||||||
</Button>
|
</div>
|
||||||
</Link>
|
<span className="text-xs text-gray-700">{t("common.cart")}</span>
|
||||||
) : (
|
</Button>
|
||||||
<Button
|
|
||||||
variant="ghost"
|
{/* Profile/Login Button */}
|
||||||
size="sm"
|
<Button
|
||||||
className="flex-col gap-0.5 h-auto px-2 py-2"
|
variant="ghost"
|
||||||
onClick={onLoginClick}
|
size="sm"
|
||||||
>
|
className="flex-col gap-0.5 h-auto px-2 py-2"
|
||||||
<User className="h-5 w-5 text-gray-600" />
|
onClick={handleProfileClick}
|
||||||
<span className="text-xs text-gray-700">{t.login}</span>
|
disabled={authLoading}
|
||||||
</Button>
|
>
|
||||||
)}
|
<User className="h-5 w-5 text-gray-600" />
|
||||||
|
<span className="text-xs text-gray-700">
|
||||||
|
{authLoading ? "..." : (isAuthenticated ? t("profile") : t("login"))}
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ export default function MobileBottomNav({
|
|||||||
<Sheet open={isCategoryOpen} onOpenChange={setIsCategoryOpen}>
|
<Sheet open={isCategoryOpen} onOpenChange={setIsCategoryOpen}>
|
||||||
<SheetContent side="left" className="w-[300px] p-0">
|
<SheetContent side="left" className="w-[300px] p-0">
|
||||||
<SheetHeader className="p-4 border-b">
|
<SheetHeader className="p-4 border-b">
|
||||||
<SheetTitle>{t.catalog}</SheetTitle>
|
<SheetTitle>{t("common.catalog")}</SheetTitle>
|
||||||
</SheetHeader>
|
</SheetHeader>
|
||||||
<ScrollArea className="h-[calc(100vh-80px)]">
|
<ScrollArea className="h-[calc(100vh-80px)]">
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
@@ -214,4 +214,4 @@ export default function MobileBottomNav({
|
|||||||
</Sheet>
|
</Sheet>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ export default function LanguageSelector() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Select value={locale} onValueChange={handleLanguageChange}>
|
<Select value={locale} onValueChange={handleLanguageChange}>
|
||||||
<SelectTrigger className="w-[70px] rounded-xl border-gray-300">
|
<SelectTrigger className="w-[70px] md:h-10! flex items-center justify-center rounded-lg border-gray-300">
|
||||||
<SelectValue>
|
<SelectValue>
|
||||||
<FlagIcon locale={locale} />
|
<FlagIcon locale={locale} />
|
||||||
</SelectValue>
|
</SelectValue>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function Tabs({
|
function Tabs({
|
||||||
className,
|
className,
|
||||||
@@ -15,7 +15,7 @@ function Tabs({
|
|||||||
className={cn("flex flex-col gap-2", className)}
|
className={cn("flex flex-col gap-2", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TabsList({
|
function TabsList({
|
||||||
@@ -31,7 +31,7 @@ function TabsList({
|
|||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TabsTrigger({
|
function TabsTrigger({
|
||||||
@@ -42,12 +42,12 @@ function TabsTrigger({
|
|||||||
<TabsPrimitive.Trigger
|
<TabsPrimitive.Trigger
|
||||||
data-slot="tabs-trigger"
|
data-slot="tabs-trigger"
|
||||||
className={cn(
|
className={cn(
|
||||||
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"cursor-pointer data-[state=active]:bg-white dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TabsContent({
|
function TabsContent({
|
||||||
@@ -60,7 +60,7 @@ function TabsContent({
|
|||||||
className={cn("flex-1 outline-none", className)}
|
className={cn("flex-1 outline-none", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
export { Tabs, TabsList, TabsTrigger, TabsContent };
|
||||||
|
|||||||
@@ -45,8 +45,10 @@ interface OrderSummaryProps {
|
|||||||
paymentTypes: PaymentType[];
|
paymentTypes: PaymentType[];
|
||||||
phone: string;
|
phone: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
lastName: string;
|
||||||
onPhoneChange: (phone: string) => void;
|
onPhoneChange: (phone: string) => void;
|
||||||
onNameChange: (name: string) => void;
|
onNameChange: (name: string) => void;
|
||||||
|
onLastNameChange: (lastName: string) => void;
|
||||||
onPaymentTypeChange: (type: PaymentType) => void;
|
onPaymentTypeChange: (type: PaymentType) => void;
|
||||||
onDeliveryTypeChange: (type: DeliveryType) => void;
|
onDeliveryTypeChange: (type: DeliveryType) => void;
|
||||||
onRegionChange: (regionCode: string) => void;
|
onRegionChange: (regionCode: string) => void;
|
||||||
@@ -68,8 +70,10 @@ export default function OrderSummary({
|
|||||||
paymentTypes,
|
paymentTypes,
|
||||||
phone,
|
phone,
|
||||||
name,
|
name,
|
||||||
|
lastName,
|
||||||
onPhoneChange,
|
onPhoneChange,
|
||||||
onNameChange,
|
onNameChange,
|
||||||
|
onLastNameChange,
|
||||||
onPaymentTypeChange,
|
onPaymentTypeChange,
|
||||||
onDeliveryTypeChange,
|
onDeliveryTypeChange,
|
||||||
onRegionChange,
|
onRegionChange,
|
||||||
@@ -93,7 +97,7 @@ export default function OrderSummary({
|
|||||||
<h3 className="text-lg font-semibold mb-3">
|
<h3 className="text-lg font-semibold mb-3">
|
||||||
{t("customer_information")}
|
{t("customer_information")}
|
||||||
</h3>
|
</h3>
|
||||||
<div className="space-y-4">
|
<div className="space-y-5">
|
||||||
<div>
|
<div>
|
||||||
<Label className="text-sm font-medium mb-2 block">
|
<Label className="text-sm font-medium mb-2 block">
|
||||||
{t("name")}
|
{t("name")}
|
||||||
@@ -106,6 +110,18 @@ export default function OrderSummary({
|
|||||||
className="rounded-xl"
|
className="rounded-xl"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<Label className="text-sm font-medium mb-2 block">
|
||||||
|
{t("last_name")}
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
value={lastName}
|
||||||
|
onChange={(e) => onLastNameChange(e.target.value)}
|
||||||
|
placeholder={t("last_name")}
|
||||||
|
className="rounded-xl"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label className="text-sm font-medium mb-2 block">
|
<Label className="text-sm font-medium mb-2 block">
|
||||||
{t("phone")}
|
{t("phone")}
|
||||||
|
|||||||
@@ -106,30 +106,61 @@ export default function CategoryPageClient({
|
|||||||
}
|
}
|
||||||
}, [selectedCategory?.id]);
|
}, [selectedCategory?.id]);
|
||||||
|
|
||||||
// Update products list
|
// Update products list - BU KISIM ÖNEMLİ!
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (productsData?.data) {
|
if (productsData?.data) {
|
||||||
setAllProducts((prev) => {
|
setAllProducts((prev) => {
|
||||||
|
// İlk sayfa ise direkt replace et
|
||||||
if (currentPage === 1) {
|
if (currentPage === 1) {
|
||||||
return productsData.data;
|
return productsData.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sonraki sayfalar için deduplicate et
|
||||||
const existingIds = new Set(prev.map((p) => p.id));
|
const existingIds = new Set(prev.map((p) => p.id));
|
||||||
const newProducts = productsData.data.filter(
|
const newProducts = productsData.data.filter(
|
||||||
(p: Product) => !existingIds.has(p.id)
|
(p: Product) => !existingIds.has(p.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Eğer yeni ürün yoksa, return prev (gereksiz re-render önlenir)
|
||||||
|
if (newProducts.length === 0) {
|
||||||
|
return prev;
|
||||||
|
}
|
||||||
|
|
||||||
return [...prev, ...newProducts];
|
return [...prev, ...newProducts];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [productsData, currentPage]);
|
}, [productsData?.data, currentPage]); // productsData yerine productsData.data
|
||||||
|
|
||||||
|
// hasMore hesaplama - BU KISIM DA ÖNEMLİ!
|
||||||
const hasMore = useMemo(() => {
|
const hasMore = useMemo(() => {
|
||||||
return !!productsData?.pagination?.next_page_url;
|
if (!productsData?.pagination) return false;
|
||||||
}, [productsData]);
|
|
||||||
|
// pagination.next_page_url varsa devam et
|
||||||
|
if (productsData.pagination.next_page_url) return true;
|
||||||
|
|
||||||
|
// Alternatif olarak: current_page < last_page kontrolü
|
||||||
|
if (
|
||||||
|
productsData.pagination.current_page &&
|
||||||
|
productsData.pagination.last_page
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
productsData.pagination.current_page < productsData.pagination.last_page
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alternatif 2: hasMorePages flag'i varsa
|
||||||
|
if (productsData.pagination.hasMorePages !== undefined) {
|
||||||
|
return productsData.pagination.hasMorePages;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}, [productsData?.pagination]);
|
||||||
|
|
||||||
const loadMoreData = useCallback(() => {
|
const loadMoreData = useCallback(() => {
|
||||||
if (!hasMore || isFetching) return;
|
if (!hasMore || isFetching) return;
|
||||||
|
console.log("Loading page:", currentPage + 1); // Debug için
|
||||||
setCurrentPage((prev) => prev + 1);
|
setCurrentPage((prev) => prev + 1);
|
||||||
}, [hasMore, isFetching]);
|
}, [hasMore, isFetching, currentPage]);
|
||||||
|
|
||||||
const sortedProducts = useMemo(() => {
|
const sortedProducts = useMemo(() => {
|
||||||
const products = [...allProducts];
|
const products = [...allProducts];
|
||||||
@@ -245,6 +276,7 @@ export default function CategoryPageClient({
|
|||||||
products={sortedProducts}
|
products={sortedProducts}
|
||||||
hasMore={hasMore}
|
hasMore={hasMore}
|
||||||
onLoadMore={loadMoreData}
|
onLoadMore={loadMoreData}
|
||||||
|
isFetching={isFetching}
|
||||||
translations={{
|
translations={{
|
||||||
loading: t("common.loading"),
|
loading: t("common.loading"),
|
||||||
no_results: t("no_results"),
|
no_results: t("no_results"),
|
||||||
@@ -276,4 +308,4 @@ export default function CategoryPageClient({
|
|||||||
</CategoryFiltersSheet>
|
</CategoryFiltersSheet>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ interface CategoryProductsGridProps {
|
|||||||
products: Product[];
|
products: Product[];
|
||||||
hasMore: boolean;
|
hasMore: boolean;
|
||||||
onLoadMore: () => void;
|
onLoadMore: () => void;
|
||||||
|
isFetching?: boolean; // Yeni prop - loading durumu için
|
||||||
translations: {
|
translations: {
|
||||||
loading: string;
|
loading: string;
|
||||||
no_results: string;
|
no_results: string;
|
||||||
@@ -16,9 +17,10 @@ export default function CategoryProductsGrid({
|
|||||||
products,
|
products,
|
||||||
hasMore,
|
hasMore,
|
||||||
onLoadMore,
|
onLoadMore,
|
||||||
|
isFetching = false,
|
||||||
translations,
|
translations,
|
||||||
}: CategoryProductsGridProps) {
|
}: CategoryProductsGridProps) {
|
||||||
if (products.length === 0) {
|
if (products.length === 0 && !isFetching) {
|
||||||
return (
|
return (
|
||||||
<div className="text-center py-8 text-gray-500">
|
<div className="text-center py-8 text-gray-500">
|
||||||
{translations.no_results}
|
{translations.no_results}
|
||||||
@@ -35,9 +37,19 @@ export default function CategoryProductsGrid({
|
|||||||
style={{ overflow: "visible" }}
|
style={{ overflow: "visible" }}
|
||||||
loader={
|
loader={
|
||||||
<div className="flex justify-center py-4">
|
<div className="flex justify-center py-4">
|
||||||
<div>{translations.loading}</div>
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-5 h-5 border-2 border-gray-300 border-t-blue-500 rounded-full animate-spin" />
|
||||||
|
<span>{translations.loading}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
endMessage={
|
||||||
|
products.length > 0 && !hasMore ? (
|
||||||
|
<div className="text-center py-4 text-gray-500 text-sm">
|
||||||
|
{/* Opsiyonel: "Tüm ürünler yüklendi" mesajı */}
|
||||||
|
</div>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<div className="bg-white rounded-lg grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3">
|
<div className="bg-white rounded-lg grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3">
|
||||||
{products.map((product) => (
|
{products.map((product) => (
|
||||||
@@ -55,6 +67,19 @@ export default function CategoryProductsGrid({
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* İlk yükleme için skeleton göster */}
|
||||||
|
{isFetching && products.length === 0 && (
|
||||||
|
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3 mt-3">
|
||||||
|
{Array.from({ length: 6 }).map((_, i) => (
|
||||||
|
<div key={i} className="animate-pulse">
|
||||||
|
<div className="bg-gray-200 h-48 rounded-lg mb-2" />
|
||||||
|
<div className="bg-gray-200 h-4 rounded w-3/4 mb-2" />
|
||||||
|
<div className="bg-gray-200 h-4 rounded w-1/2" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</InfiniteScroll>
|
</InfiniteScroll>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
233
features/collections/components/CollectionFilters.tsx
Normal file
233
features/collections/components/CollectionFilters.tsx
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Slider } from "@/components/ui/slider";
|
||||||
|
import type { FilterBrand, FilterCategory } from "@/lib/types/api";
|
||||||
|
|
||||||
|
interface FiltersData {
|
||||||
|
categories: FilterCategory[];
|
||||||
|
brands: FilterBrand[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CollectionFiltersProps {
|
||||||
|
filtersData: FiltersData | undefined;
|
||||||
|
selectedBrands: Set<number>;
|
||||||
|
selectedCategories: Set<number>;
|
||||||
|
priceSort: "none" | "lowToHigh" | "highToLow";
|
||||||
|
priceRange: [number, number];
|
||||||
|
onBrandToggle: (brandId: number) => void;
|
||||||
|
onCategoryToggle: (categoryId: number) => void;
|
||||||
|
onPriceSortChange: (sortType: "none" | "lowToHigh" | "highToLow") => void;
|
||||||
|
onPriceChange: (values: number[]) => void;
|
||||||
|
onReset: () => void;
|
||||||
|
translations: {
|
||||||
|
category: string;
|
||||||
|
brands: string;
|
||||||
|
sort: string;
|
||||||
|
default: string;
|
||||||
|
price_low_to_high: string;
|
||||||
|
price_high_to_low: string;
|
||||||
|
price: string;
|
||||||
|
price_from: string;
|
||||||
|
price_to: string;
|
||||||
|
reset: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CollectionFilters({
|
||||||
|
filtersData,
|
||||||
|
selectedBrands,
|
||||||
|
selectedCategories,
|
||||||
|
priceSort,
|
||||||
|
priceRange,
|
||||||
|
onBrandToggle,
|
||||||
|
onCategoryToggle,
|
||||||
|
onPriceSortChange,
|
||||||
|
onPriceChange,
|
||||||
|
onReset,
|
||||||
|
translations,
|
||||||
|
}: CollectionFiltersProps) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-6 mb-6">
|
||||||
|
{filtersData?.categories && filtersData.categories.length > 0 && (
|
||||||
|
<FilterSection title={translations.category}>
|
||||||
|
{filtersData.categories.map((category) => (
|
||||||
|
<CheckboxItem
|
||||||
|
key={category.id}
|
||||||
|
checked={selectedCategories.has(category.id)}
|
||||||
|
onCheckedChange={() => onCategoryToggle(category.id)}
|
||||||
|
label={category.name}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</FilterSection>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{filtersData?.brands && filtersData.brands.length > 0 && (
|
||||||
|
<FilterSection title={translations.brands}>
|
||||||
|
{filtersData.brands.map((brand) => (
|
||||||
|
<CheckboxItem
|
||||||
|
key={brand.id}
|
||||||
|
checked={selectedBrands.has(brand.id)}
|
||||||
|
onCheckedChange={() => onBrandToggle(brand.id)}
|
||||||
|
label={brand.name}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</FilterSection>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<FilterSection title={translations.sort}>
|
||||||
|
<RadioItem
|
||||||
|
name="sort"
|
||||||
|
checked={priceSort === "none"}
|
||||||
|
onChange={() => onPriceSortChange("none")}
|
||||||
|
label={translations.default}
|
||||||
|
/>
|
||||||
|
<RadioItem
|
||||||
|
name="sort"
|
||||||
|
checked={priceSort === "lowToHigh"}
|
||||||
|
onChange={() => onPriceSortChange("lowToHigh")}
|
||||||
|
label={translations.price_low_to_high}
|
||||||
|
/>
|
||||||
|
<RadioItem
|
||||||
|
name="sort"
|
||||||
|
checked={priceSort === "highToLow"}
|
||||||
|
onChange={() => onPriceSortChange("highToLow")}
|
||||||
|
label={translations.price_high_to_low}
|
||||||
|
/>
|
||||||
|
</FilterSection>
|
||||||
|
|
||||||
|
<PriceFilter
|
||||||
|
title={translations.price}
|
||||||
|
priceRange={priceRange}
|
||||||
|
onPriceChange={onPriceChange}
|
||||||
|
translations={{
|
||||||
|
from: translations.price_from,
|
||||||
|
to: translations.price_to,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button variant="outline" className="w-full rounded-xl" onClick={onReset}>
|
||||||
|
{translations.reset}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FilterSection({
|
||||||
|
title,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3 className="text-lg font-semibold mb-3">{title}</h3>
|
||||||
|
<div className="space-y-2">{children}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CheckboxItem({
|
||||||
|
checked,
|
||||||
|
onCheckedChange,
|
||||||
|
label,
|
||||||
|
}: {
|
||||||
|
checked: boolean;
|
||||||
|
onCheckedChange: () => void;
|
||||||
|
label: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<label className="flex items-center gap-2 cursor-pointer">
|
||||||
|
<Checkbox checked={checked} onCheckedChange={onCheckedChange} />
|
||||||
|
<span className="text-sm">{label}</span>
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function RadioItem({
|
||||||
|
name,
|
||||||
|
checked,
|
||||||
|
onChange,
|
||||||
|
label,
|
||||||
|
}: {
|
||||||
|
name: string;
|
||||||
|
checked: boolean;
|
||||||
|
onChange: () => void;
|
||||||
|
label: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<label className="flex items-center gap-2 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name={name}
|
||||||
|
checked={checked}
|
||||||
|
onChange={onChange}
|
||||||
|
className="w-4 h-4"
|
||||||
|
/>
|
||||||
|
<span>{label}</span>
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function PriceFilter({
|
||||||
|
title,
|
||||||
|
priceRange,
|
||||||
|
onPriceChange,
|
||||||
|
translations,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
priceRange: [number, number];
|
||||||
|
onPriceChange: (values: number[]) => void;
|
||||||
|
translations: { from: string; to: string };
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3 className="text-lg font-semibold mb-3">{title}</h3>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<div className="flex-1">
|
||||||
|
<Label htmlFor="price-from" className="text-xs mb-1">
|
||||||
|
{translations.from}
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="price-from"
|
||||||
|
type="number"
|
||||||
|
value={priceRange[0]}
|
||||||
|
onChange={(e) =>
|
||||||
|
onPriceChange([parseInt(e.target.value) || 0, priceRange[1]])
|
||||||
|
}
|
||||||
|
className="rounded-lg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Label htmlFor="price-to" className="text-xs mb-1">
|
||||||
|
{translations.to}
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="price-to"
|
||||||
|
type="number"
|
||||||
|
value={priceRange[1]}
|
||||||
|
onChange={(e) =>
|
||||||
|
onPriceChange([
|
||||||
|
priceRange[0],
|
||||||
|
parseInt(e.target.value) || 10000,
|
||||||
|
])
|
||||||
|
}
|
||||||
|
className="rounded-lg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Slider
|
||||||
|
min={0}
|
||||||
|
max={99999}
|
||||||
|
step={100}
|
||||||
|
value={priceRange}
|
||||||
|
onValueChange={onPriceChange}
|
||||||
|
className="mt-2"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
55
features/collections/components/CollectionFiltersSheet.tsx
Normal file
55
features/collections/components/CollectionFiltersSheet.tsx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { SlidersHorizontal, X } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Sheet,
|
||||||
|
SheetContent,
|
||||||
|
SheetHeader,
|
||||||
|
SheetTitle,
|
||||||
|
SheetTrigger,
|
||||||
|
} from "@/components/ui/sheet";
|
||||||
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||||
|
|
||||||
|
interface CollectionFiltersSheetProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
filterLabel: string;
|
||||||
|
closeLabel: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CollectionFiltersSheet({
|
||||||
|
isOpen,
|
||||||
|
onOpenChange,
|
||||||
|
filterLabel,
|
||||||
|
closeLabel,
|
||||||
|
children,
|
||||||
|
}: CollectionFiltersSheetProps) {
|
||||||
|
return (
|
||||||
|
<Sheet open={isOpen} onOpenChange={onOpenChange}>
|
||||||
|
<SheetTrigger asChild>
|
||||||
|
<Button
|
||||||
|
className="sm:hidden fixed bottom-20 right-4 rounded-xl font-bold gap-2 z-10 shadow-lg"
|
||||||
|
size="lg"
|
||||||
|
>
|
||||||
|
{filterLabel}
|
||||||
|
<SlidersHorizontal className="h-5 w-5" />
|
||||||
|
</Button>
|
||||||
|
</SheetTrigger>
|
||||||
|
<SheetContent side="left" className="w-[290px] p-0">
|
||||||
|
<SheetHeader className="p-4 border-b">
|
||||||
|
<SheetTitle>{filterLabel}</SheetTitle>
|
||||||
|
<button
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
className="absolute top-4 right-4 rounded-md ring-offset-background transition-opacity hover:opacity-100"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
<span className="sr-only">{closeLabel}</span>
|
||||||
|
</button>
|
||||||
|
</SheetHeader>
|
||||||
|
<ScrollArea className="h-[calc(100vh-80px)] p-4">
|
||||||
|
{children}
|
||||||
|
</ScrollArea>
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>
|
||||||
|
);
|
||||||
|
}
|
||||||
261
features/collections/components/CollectionPageClient.tsx
Normal file
261
features/collections/components/CollectionPageClient.tsx
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState, useMemo, useCallback } from "react";
|
||||||
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
import type { Product } from "@/lib/types/api";
|
||||||
|
import CollectionFilters from "./CollectionFilters";
|
||||||
|
import CollectionProductsGrid from "./CollectionProductsGrid";
|
||||||
|
import CollectionFiltersSheet from "./CollectionFiltersSheet";
|
||||||
|
import {
|
||||||
|
useCollections,
|
||||||
|
useCollectionFilters,
|
||||||
|
useFilteredCollectionProducts,
|
||||||
|
} from "@/features/collections/hooks/useCollections";
|
||||||
|
|
||||||
|
interface CollectionPageClientProps {
|
||||||
|
params: { locale: string; slug: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CollectionPageClient({
|
||||||
|
params,
|
||||||
|
}: CollectionPageClientProps) {
|
||||||
|
const { slug } = params;
|
||||||
|
const t = useTranslations();
|
||||||
|
const [isSheetOpen, setIsSheetOpen] = useState(false);
|
||||||
|
|
||||||
|
const { data: collectionsData, isLoading: collectionsLoading } =
|
||||||
|
useCollections();
|
||||||
|
|
||||||
|
const selectedCollection = useMemo(() => {
|
||||||
|
if (!collectionsData || !slug) return null;
|
||||||
|
return collectionsData.find((col) => col.slug === slug);
|
||||||
|
}, [collectionsData, slug]);
|
||||||
|
|
||||||
|
// State management
|
||||||
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
|
const [allProducts, setAllProducts] = useState<Product[]>([]);
|
||||||
|
const [priceSort, setPriceSort] = useState<"none" | "lowToHigh" | "highToLow">("none");
|
||||||
|
const [priceRange, setPriceRange] = useState<[number, number]>([0, 10000]);
|
||||||
|
const [selectedBrands, setSelectedBrands] = useState<Set<number>>(new Set());
|
||||||
|
const [selectedCategories, setSelectedCategories] = useState<Set<number>>(new Set());
|
||||||
|
|
||||||
|
// Fetch filters
|
||||||
|
const { data: filtersData } = useCollectionFilters(selectedCollection?.id, {
|
||||||
|
enabled: !!selectedCollection,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Build filter params
|
||||||
|
const filterParams = useMemo(() => {
|
||||||
|
const params: any = {
|
||||||
|
page: currentPage,
|
||||||
|
limit: 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (selectedBrands.size > 0) {
|
||||||
|
params.brands = Array.from(selectedBrands);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedCategories.size > 0) {
|
||||||
|
params.categories = Array.from(selectedCategories);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priceRange[0] > 0) {
|
||||||
|
params.min_price = priceRange[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priceRange[1] < 10000) {
|
||||||
|
params.max_price = priceRange[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}, [currentPage, selectedBrands, selectedCategories, priceRange]);
|
||||||
|
|
||||||
|
// Fetch filtered products
|
||||||
|
const { data: productsData, isFetching } = useFilteredCollectionProducts(
|
||||||
|
selectedCollection?.id?.toString() || "",
|
||||||
|
filterParams,
|
||||||
|
{ enabled: !!selectedCollection }
|
||||||
|
);
|
||||||
|
|
||||||
|
// Reset on collection change
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedCollection) {
|
||||||
|
setAllProducts([]);
|
||||||
|
setCurrentPage(1);
|
||||||
|
setSelectedBrands(new Set());
|
||||||
|
setSelectedCategories(new Set());
|
||||||
|
setPriceRange([0, 10000]);
|
||||||
|
setPriceSort("none");
|
||||||
|
}
|
||||||
|
}, [selectedCollection?.id]);
|
||||||
|
|
||||||
|
// Update products list
|
||||||
|
useEffect(() => {
|
||||||
|
if (productsData?.data) {
|
||||||
|
setAllProducts((prev) => {
|
||||||
|
if (currentPage === 1) {
|
||||||
|
return productsData.data;
|
||||||
|
}
|
||||||
|
const existingIds = new Set(prev.map((p) => p.id));
|
||||||
|
const newProducts = productsData.data.filter(
|
||||||
|
(p: Product) => !existingIds.has(p.id)
|
||||||
|
);
|
||||||
|
return [...prev, ...newProducts];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [productsData, currentPage]);
|
||||||
|
|
||||||
|
const hasMore = useMemo(() => {
|
||||||
|
return !!productsData?.pagination?.next_page_url;
|
||||||
|
}, [productsData]);
|
||||||
|
|
||||||
|
const loadMoreData = useCallback(() => {
|
||||||
|
if (!hasMore || isFetching) return;
|
||||||
|
setCurrentPage((prev) => prev + 1);
|
||||||
|
}, [hasMore, isFetching]);
|
||||||
|
|
||||||
|
const sortedProducts = useMemo(() => {
|
||||||
|
const products = [...allProducts];
|
||||||
|
if (priceSort === "lowToHigh") {
|
||||||
|
return products.sort(
|
||||||
|
(a, b) =>
|
||||||
|
parseFloat(a.price_amount || "0") - parseFloat(b.price_amount || "0")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (priceSort === "highToLow") {
|
||||||
|
return products.sort(
|
||||||
|
(a, b) =>
|
||||||
|
parseFloat(b.price_amount || "0") - parseFloat(a.price_amount || "0")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return products;
|
||||||
|
}, [allProducts, priceSort]);
|
||||||
|
|
||||||
|
// Filter handlers
|
||||||
|
const handleBrandToggle = useCallback((brandId: number) => {
|
||||||
|
setSelectedBrands((prev) => {
|
||||||
|
const newSet = new Set(prev);
|
||||||
|
newSet.has(brandId) ? newSet.delete(brandId) : newSet.add(brandId);
|
||||||
|
return newSet;
|
||||||
|
});
|
||||||
|
setCurrentPage(1);
|
||||||
|
setAllProducts([]);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleCategoryToggle = useCallback((categoryId: number) => {
|
||||||
|
setSelectedCategories((prev) => {
|
||||||
|
const newSet = new Set(prev);
|
||||||
|
newSet.has(categoryId) ? newSet.delete(categoryId) : newSet.add(categoryId);
|
||||||
|
return newSet;
|
||||||
|
});
|
||||||
|
setCurrentPage(1);
|
||||||
|
setAllProducts([]);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handlePriceChange = useCallback((values: number[]) => {
|
||||||
|
setPriceRange([values[0], values[1]]);
|
||||||
|
setCurrentPage(1);
|
||||||
|
setAllProducts([]);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handlePriceSortChange = useCallback(
|
||||||
|
(sortType: "none" | "lowToHigh" | "highToLow") => {
|
||||||
|
setPriceSort(sortType);
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const resetFilters = useCallback(() => {
|
||||||
|
setSelectedBrands(new Set());
|
||||||
|
setSelectedCategories(new Set());
|
||||||
|
setPriceRange([0, 10000]);
|
||||||
|
setPriceSort("none");
|
||||||
|
setCurrentPage(1);
|
||||||
|
setAllProducts([]);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const filterTranslations = useMemo(
|
||||||
|
() => ({
|
||||||
|
category: t("category"),
|
||||||
|
brands: t("brands"),
|
||||||
|
sort: t("sort"),
|
||||||
|
default: t("default"),
|
||||||
|
price_low_to_high: t("price_low_to_high"),
|
||||||
|
price_high_to_low: t("price_high_to_low"),
|
||||||
|
price: t("price"),
|
||||||
|
price_from: t("price_from"),
|
||||||
|
price_to: t("price_to"),
|
||||||
|
reset: t("reset"),
|
||||||
|
}),
|
||||||
|
[t]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (collectionsLoading) return <div>{t("common.loading")}</div>;
|
||||||
|
if (!selectedCollection)
|
||||||
|
return <div className="text-center py-8">{t("collection_not_found")}</div>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col mx-auto max-w-[1504px] px-2 md:px-4 lg:px-6 pb-12">
|
||||||
|
<h2 className="p-4 text-3xl font-bold pb-6 rounded-t-lg mb-0 bg-white">
|
||||||
|
{selectedCollection.name}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div className="flex gap-4 bg-white rounded-b-lg">
|
||||||
|
{/* Desktop Filters Sidebar */}
|
||||||
|
<div className="hidden sm:block w-[280px] shrink-0 border-r px-4">
|
||||||
|
<ScrollArea className="h-auto">
|
||||||
|
<CollectionFilters
|
||||||
|
filtersData={filtersData}
|
||||||
|
selectedBrands={selectedBrands}
|
||||||
|
selectedCategories={selectedCategories}
|
||||||
|
priceSort={priceSort}
|
||||||
|
priceRange={priceRange}
|
||||||
|
onBrandToggle={handleBrandToggle}
|
||||||
|
onCategoryToggle={handleCategoryToggle}
|
||||||
|
onPriceSortChange={handlePriceSortChange}
|
||||||
|
onPriceChange={handlePriceChange}
|
||||||
|
onReset={resetFilters}
|
||||||
|
translations={filterTranslations}
|
||||||
|
/>
|
||||||
|
</ScrollArea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Products Grid */}
|
||||||
|
<div className="flex-1 bg-white rounded-lg mb-6">
|
||||||
|
<CollectionProductsGrid
|
||||||
|
products={sortedProducts}
|
||||||
|
hasMore={hasMore}
|
||||||
|
onLoadMore={loadMoreData}
|
||||||
|
translations={{
|
||||||
|
loading: t("common.loading"),
|
||||||
|
no_results: t("no_results"),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Mobile Filters Sheet */}
|
||||||
|
<CollectionFiltersSheet
|
||||||
|
isOpen={isSheetOpen}
|
||||||
|
onOpenChange={setIsSheetOpen}
|
||||||
|
filterLabel={t("filter")}
|
||||||
|
closeLabel={t("close")}
|
||||||
|
>
|
||||||
|
<CollectionFilters
|
||||||
|
filtersData={filtersData}
|
||||||
|
selectedBrands={selectedBrands}
|
||||||
|
selectedCategories={selectedCategories}
|
||||||
|
priceSort={priceSort}
|
||||||
|
priceRange={priceRange}
|
||||||
|
onBrandToggle={handleBrandToggle}
|
||||||
|
onCategoryToggle={handleCategoryToggle}
|
||||||
|
onPriceSortChange={handlePriceSortChange}
|
||||||
|
onPriceChange={handlePriceChange}
|
||||||
|
onReset={resetFilters}
|
||||||
|
translations={filterTranslations}
|
||||||
|
/>
|
||||||
|
</CollectionFiltersSheet>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
60
features/collections/components/CollectionProductsGrid.tsx
Normal file
60
features/collections/components/CollectionProductsGrid.tsx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import InfiniteScroll from "react-infinite-scroll-component";
|
||||||
|
import ProductCard from "@/features/home/components/ProductCard";
|
||||||
|
import type { Product } from "@/lib/types/api";
|
||||||
|
|
||||||
|
interface CollectionProductsGridProps {
|
||||||
|
products: Product[];
|
||||||
|
hasMore: boolean;
|
||||||
|
onLoadMore: () => void;
|
||||||
|
translations: {
|
||||||
|
loading: string;
|
||||||
|
no_results: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CollectionProductsGrid({
|
||||||
|
products,
|
||||||
|
hasMore,
|
||||||
|
onLoadMore,
|
||||||
|
translations,
|
||||||
|
}: CollectionProductsGridProps) {
|
||||||
|
if (products.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="text-center py-8 text-gray-500">
|
||||||
|
{translations.no_results}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<InfiniteScroll
|
||||||
|
dataLength={products.length}
|
||||||
|
next={onLoadMore}
|
||||||
|
hasMore={hasMore}
|
||||||
|
scrollThreshold={0.8}
|
||||||
|
style={{ overflow: "visible" }}
|
||||||
|
loader={
|
||||||
|
<div className="flex justify-center py-4">
|
||||||
|
<div>{translations.loading}</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="bg-white rounded-lg grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3">
|
||||||
|
{products.map((product) => (
|
||||||
|
<ProductCard
|
||||||
|
key={product.id}
|
||||||
|
id={product.id}
|
||||||
|
name={product.name}
|
||||||
|
price={
|
||||||
|
product.price_amount ? parseFloat(product.price_amount) : null
|
||||||
|
}
|
||||||
|
struct_price_text={`${product.price_amount} TMT`}
|
||||||
|
images={[product.media?.[0]?.images_400x400]}
|
||||||
|
stock={product.stock}
|
||||||
|
button={true}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</InfiniteScroll>
|
||||||
|
);
|
||||||
|
}
|
||||||
161
features/collections/hooks/useCollections.ts
Normal file
161
features/collections/hooks/useCollections.ts
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { apiClient } from "@/lib/api";
|
||||||
|
import type {
|
||||||
|
Collection,
|
||||||
|
Product,
|
||||||
|
PaginatedResponse,
|
||||||
|
FiltersResponse,
|
||||||
|
ProductFilters,
|
||||||
|
} from "@/lib/types/api";
|
||||||
|
|
||||||
|
// Get all collections
|
||||||
|
export function useCollections(options?: { enabled?: boolean }) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["collections"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const response = await apiClient.get<PaginatedResponse<Collection>>(
|
||||||
|
"/collections"
|
||||||
|
);
|
||||||
|
return response.data.data || response.data;
|
||||||
|
},
|
||||||
|
enabled: options?.enabled !== false,
|
||||||
|
staleTime: 1000 * 60 * 30, // 30 minutes
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get single collection by ID
|
||||||
|
export function useCollection(
|
||||||
|
id: number | string,
|
||||||
|
options?: { enabled?: boolean }
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["collection", id],
|
||||||
|
queryFn: async () => {
|
||||||
|
const response = await apiClient.get<Collection>(`/collections/${id}`);
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
enabled: options?.enabled !== false && !!id,
|
||||||
|
staleTime: 1000 * 60 * 15,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get products for a collection with pagination
|
||||||
|
export function useCollectionProducts(
|
||||||
|
collectionId: number | string,
|
||||||
|
options?: {
|
||||||
|
enabled?: boolean;
|
||||||
|
page?: number;
|
||||||
|
limit?: number;
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: [
|
||||||
|
"collection",
|
||||||
|
collectionId,
|
||||||
|
"products",
|
||||||
|
options?.page,
|
||||||
|
options?.limit,
|
||||||
|
],
|
||||||
|
queryFn: async () => {
|
||||||
|
const response = await apiClient.get<PaginatedResponse<Product>>(
|
||||||
|
`/collections/${collectionId}/products`,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
page: options?.page || 1,
|
||||||
|
per_page: options?.limit,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
data: response.data.data || [],
|
||||||
|
pagination: response.data.pagination || {},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
enabled: options?.enabled !== false && !!collectionId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get filters for collection products
|
||||||
|
export function useCollectionFilters(
|
||||||
|
collectionId: number | string | undefined,
|
||||||
|
options?: { enabled?: boolean }
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["collection-filters", collectionId],
|
||||||
|
queryFn: async () => {
|
||||||
|
const response = await apiClient.get<FiltersResponse>("/filters", {
|
||||||
|
params: { collection_id: collectionId },
|
||||||
|
});
|
||||||
|
return response.data.data;
|
||||||
|
},
|
||||||
|
enabled: options?.enabled !== false && !!collectionId,
|
||||||
|
staleTime: 1000 * 60 * 15,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get filtered collection products
|
||||||
|
export function useFilteredCollectionProducts(
|
||||||
|
collectionId: number | string,
|
||||||
|
filters: ProductFilters,
|
||||||
|
options?: { enabled?: boolean }
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["collection", collectionId, "filtered-products", filters],
|
||||||
|
queryFn: async () => {
|
||||||
|
const params: Record<string, any> = {
|
||||||
|
page: filters.page || 1,
|
||||||
|
per_page: filters.limit || 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (filters.brands && filters.brands.length > 0) {
|
||||||
|
params.brands = filters.brands.join(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters.categories && filters.categories.length > 0) {
|
||||||
|
params.categories = filters.categories.join(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters.min_price !== undefined) {
|
||||||
|
params.min_price = filters.min_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters.max_price !== undefined) {
|
||||||
|
params.max_price = filters.max_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await apiClient.get<PaginatedResponse<Product>>(
|
||||||
|
`/collections/${collectionId}/products`,
|
||||||
|
{ params }
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: response.data.data || [],
|
||||||
|
pagination: response.data.pagination || {},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
enabled: options?.enabled !== false && !!collectionId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if collection has products
|
||||||
|
export function useCheckCollectionHasProducts(
|
||||||
|
collectionId: number | string,
|
||||||
|
options?: { enabled?: boolean }
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["collection", collectionId, "has-products"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const response = await apiClient.get<PaginatedResponse<Product>>(
|
||||||
|
`/collections/${collectionId}/products`,
|
||||||
|
{
|
||||||
|
params: { limit: 1 },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
hasProducts: response.data.data && response.data.data.length > 0,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
enabled: options?.enabled !== false && !!collectionId,
|
||||||
|
staleTime: 1000 * 60 * 5,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ export default function CollectionSection({ collection, locale }: Props) {
|
|||||||
} = useCollectionProducts(collection.id);
|
} = useCollectionProducts(collection.id);
|
||||||
|
|
||||||
const handleTitleClick = () => {
|
const handleTitleClick = () => {
|
||||||
router.push(`/${locale}/collections/${collection.id}`);
|
router.push(`/collections/${collection.slug}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hide section if no products
|
// Hide section if no products
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ export default function OrdersPageClient({ locale }: OrdersPageClientProps) {
|
|||||||
<h1 className="text-xl md:text-2xl lg:text-3xl font-bold mb-6">{t("my_orders")}</h1>
|
<h1 className="text-xl md:text-2xl lg:text-3xl font-bold mb-6">{t("my_orders")}</h1>
|
||||||
|
|
||||||
<Tabs defaultValue="active" className="w-full">
|
<Tabs defaultValue="active" className="w-full">
|
||||||
<TabsList className="mb-6">
|
<TabsList className="mb-4 md:mb-6 w-full md:w-fit gap-2 p-0">
|
||||||
<TabsTrigger value="active">
|
<TabsTrigger value="active" >
|
||||||
{t("active_orders")} ({activeOrders.length})
|
{t("active_orders")} ({activeOrders.length})
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
<TabsTrigger value="completed">
|
<TabsTrigger value="completed">
|
||||||
|
|||||||
90
features/products/components/ProductImageGallery.tsx
Normal file
90
features/products/components/ProductImageGallery.tsx
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import { useState, useEffect, useRef, useCallback } from "react";
|
||||||
|
import Image from "next/image";
|
||||||
|
|
||||||
|
interface ProductImageGalleryProps {
|
||||||
|
images: string[];
|
||||||
|
productName: string;
|
||||||
|
noImageText: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ProductImageGallery({
|
||||||
|
images,
|
||||||
|
productName,
|
||||||
|
noImageText,
|
||||||
|
}: ProductImageGalleryProps) {
|
||||||
|
const [selectedImage, setSelectedImage] = useState(0);
|
||||||
|
const autoplayTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (images.length <= 1) return;
|
||||||
|
|
||||||
|
const startAutoplay = () => {
|
||||||
|
autoplayTimerRef.current = setInterval(() => {
|
||||||
|
setSelectedImage((prev) => (prev + 1) % images.length);
|
||||||
|
}, 3000);
|
||||||
|
};
|
||||||
|
|
||||||
|
startAutoplay();
|
||||||
|
return () => {
|
||||||
|
if (autoplayTimerRef.current) clearInterval(autoplayTimerRef.current);
|
||||||
|
};
|
||||||
|
}, [images.length]);
|
||||||
|
|
||||||
|
const handleImageSelect = useCallback(
|
||||||
|
(index: number) => {
|
||||||
|
setSelectedImage(index);
|
||||||
|
if (autoplayTimerRef.current) clearInterval(autoplayTimerRef.current);
|
||||||
|
if (images.length > 1) {
|
||||||
|
autoplayTimerRef.current = setInterval(() => {
|
||||||
|
setSelectedImage((prev) => (prev + 1) % images.length);
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[images.length]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 max-w-2xl">
|
||||||
|
<div className="relative">
|
||||||
|
<div className="relative aspect-square w-full rounded-2xl overflow-hidden bg-white">
|
||||||
|
{images.length > 0 ? (
|
||||||
|
<Image
|
||||||
|
src={images[selectedImage]}
|
||||||
|
alt={productName}
|
||||||
|
fill
|
||||||
|
className="object-contain"
|
||||||
|
priority
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="flex items-center justify-center h-full text-gray-400">
|
||||||
|
{noImageText}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{images.length > 1 && (
|
||||||
|
<div className="mt-4 flex gap-2 overflow-x-auto pb-2">
|
||||||
|
{images.map((image, index) => (
|
||||||
|
<button
|
||||||
|
key={index}
|
||||||
|
onClick={() => handleImageSelect(index)}
|
||||||
|
className={`relative w-16 h-16 flex-shrink-0 rounded overflow-hidden border-2 transition-all ${
|
||||||
|
selectedImage === index
|
||||||
|
? "border-primary ring-2 ring-primary/20"
|
||||||
|
: "border-gray-200 hover:border-gray-300"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
src={image}
|
||||||
|
alt={`${productName} ${index + 1}`}
|
||||||
|
fill
|
||||||
|
className="object-cover"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
141
features/products/components/ProductInfoCard.tsx
Normal file
141
features/products/components/ProductInfoCard.tsx
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
import { Card } from "@/components/ui/card";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import { Star } from "lucide-react";
|
||||||
|
|
||||||
|
interface ProductProperty {
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProductInfoCardProps {
|
||||||
|
brandName?: string;
|
||||||
|
stock?: number;
|
||||||
|
barcode?: string;
|
||||||
|
colour?: string;
|
||||||
|
properties?: ProductProperty[];
|
||||||
|
description?: string;
|
||||||
|
averageRating: number;
|
||||||
|
reviewsCount: number;
|
||||||
|
t: (key: string, params?: any) => string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ProductInfoCard({
|
||||||
|
brandName,
|
||||||
|
stock,
|
||||||
|
barcode,
|
||||||
|
colour,
|
||||||
|
properties,
|
||||||
|
description,
|
||||||
|
averageRating,
|
||||||
|
reviewsCount,
|
||||||
|
t,
|
||||||
|
}: ProductInfoCardProps) {
|
||||||
|
const renderStars = (rating: number) => {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
{[1, 2, 3, 4, 5].map((star) => (
|
||||||
|
<Star
|
||||||
|
key={star}
|
||||||
|
className={`h-5 w-5 transition-all ${
|
||||||
|
star <= rating
|
||||||
|
? "fill-yellow-400 text-yellow-400"
|
||||||
|
: "text-gray-300"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-6 bg-white">
|
||||||
|
<Card className="p-4 rounded-xl border-gray-200">
|
||||||
|
<h3 className="text-xl font-semibold mb-4">{t("about_product")}</h3>
|
||||||
|
<div className="space-y-3">
|
||||||
|
{brandName && (
|
||||||
|
<>
|
||||||
|
<div className="flex justify-between items-center py-2">
|
||||||
|
<span className="text-gray-500">{t("brands")}</span>
|
||||||
|
<span className="font-medium">{brandName}</span>
|
||||||
|
</div>
|
||||||
|
<Separator />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{stock !== undefined && (
|
||||||
|
<>
|
||||||
|
<div className="flex justify-between items-center py-2">
|
||||||
|
<span className="text-gray-500">{t("stock")}</span>
|
||||||
|
<span
|
||||||
|
className={`font-medium ${
|
||||||
|
stock === 0
|
||||||
|
? "text-red-500"
|
||||||
|
: stock <= 5
|
||||||
|
? "text-orange-600"
|
||||||
|
: "text-green-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{stock === 0
|
||||||
|
? t("out_of_stock")
|
||||||
|
: stock <= 5
|
||||||
|
? `${t("only_left", { count: stock })}`
|
||||||
|
: stock}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Separator />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{barcode && (
|
||||||
|
<>
|
||||||
|
<div className="flex justify-between items-center py-2">
|
||||||
|
<span className="text-gray-500">{t("barcode")}</span>
|
||||||
|
<span className="font-mono text-sm">{barcode}</span>
|
||||||
|
</div>
|
||||||
|
<Separator />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{colour && (
|
||||||
|
<>
|
||||||
|
<div className="flex justify-between items-center py-2">
|
||||||
|
<span className="text-gray-500">{t("color")}</span>
|
||||||
|
<span className="font-medium">{colour}</span>
|
||||||
|
</div>
|
||||||
|
<Separator />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{properties && properties.length > 0 && (
|
||||||
|
<>
|
||||||
|
{properties.map(
|
||||||
|
(prop, idx) =>
|
||||||
|
prop.value && (
|
||||||
|
<div key={idx}>
|
||||||
|
<div className="flex justify-between items-center py-2">
|
||||||
|
<span className="text-gray-500">{prop.name}</span>
|
||||||
|
<span className="font-medium">{prop.value}</span>
|
||||||
|
</div>
|
||||||
|
{idx < properties.length - 1 && <Separator />}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{description && (
|
||||||
|
<Card className="p-4 rounded-xl border-gray-200">
|
||||||
|
<h3 className="text-xl font-semibold mb-3">
|
||||||
|
{t("product_description")}
|
||||||
|
</h3>
|
||||||
|
<div
|
||||||
|
className="text-gray-700 leading-relaxed prose prose-sm max-w-none"
|
||||||
|
dangerouslySetInnerHTML={{ __html: description }}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,30 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useCallback, useMemo, useRef, useEffect } from "react";
|
import { useState, useCallback, useMemo, useRef, useEffect } from "react";
|
||||||
import Image from "next/image";
|
|
||||||
import Link from "next/link";
|
|
||||||
import {
|
|
||||||
Minus,
|
|
||||||
Plus,
|
|
||||||
Heart,
|
|
||||||
ShoppingCart,
|
|
||||||
Store,
|
|
||||||
Loader2,
|
|
||||||
AlertTriangle,
|
|
||||||
} from "lucide-react";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Card } from "@/components/ui/card";
|
|
||||||
import { Separator } from "@/components/ui/separator";
|
|
||||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
useProductsBySlug,
|
||||||
DialogContent,
|
useRelatedProducts,
|
||||||
DialogDescription,
|
useSubmitReview,
|
||||||
DialogHeader,
|
} from "@/features/products/hooks/useProducts";
|
||||||
DialogTitle,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import { useProductsBySlug } from "@/features/products/hooks/useProducts";
|
|
||||||
import {
|
import {
|
||||||
useAddToCart,
|
useAddToCart,
|
||||||
useUpdateCartItemQuantity,
|
useUpdateCartItemQuantity,
|
||||||
@@ -33,6 +15,13 @@ import {
|
|||||||
} from "@/features/cart/hooks/useCart";
|
} from "@/features/cart/hooks/useCart";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { ProductImageGallery } from "./ProductImageGallery";
|
||||||
|
import { ProductInfoCard } from "./ProductInfoCard";
|
||||||
|
import { ProductPurchaseCard } from "./ProductPurchaseCard";
|
||||||
|
import { ProductReviewsSection } from "./ProductReviewsSection";
|
||||||
|
import { RelatedProductsSection } from "./RelatedProductsSection";
|
||||||
|
import { ReviewModal } from "./ReviewModal";
|
||||||
|
import { StockLimitModal } from "./StockLimitModal";
|
||||||
|
|
||||||
interface ProductDetailProps {
|
interface ProductDetailProps {
|
||||||
slug: string;
|
slug: string;
|
||||||
@@ -47,12 +36,12 @@ interface PendingUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ProductPageContent({ slug }: ProductDetailProps) {
|
export default function ProductPageContent({ slug }: ProductDetailProps) {
|
||||||
const [selectedImage, setSelectedImage] = useState(0);
|
|
||||||
const [localQuantity, setLocalQuantity] = useState(1);
|
const [localQuantity, setLocalQuantity] = useState(1);
|
||||||
const [isFavorite, setIsFavorite] = useState(false);
|
const [isFavorite, setIsFavorite] = useState(false);
|
||||||
const [isSyncing, setIsSyncing] = useState(false);
|
const [isSyncing, setIsSyncing] = useState(false);
|
||||||
const [syncError, setSyncError] = useState(false);
|
const [syncError, setSyncError] = useState(false);
|
||||||
const [showStockModal, setShowStockModal] = useState(false);
|
const [showStockModal, setShowStockModal] = useState(false);
|
||||||
|
const [showReviewModal, setShowReviewModal] = useState(false);
|
||||||
|
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
@@ -63,24 +52,30 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
const retryTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
const retryTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
||||||
const syncToServerRef = useRef<((quantity: number) => void) | null>(null);
|
const syncToServerRef = useRef<((quantity: number) => void) | null>(null);
|
||||||
const retrySyncRef = useRef<((quantity: number) => void) | null>(null);
|
const retrySyncRef = useRef<((quantity: number) => void) | null>(null);
|
||||||
const autoplayTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: product,
|
data: product,
|
||||||
isLoading: productLoading,
|
isLoading: productLoading,
|
||||||
error,
|
error,
|
||||||
|
refetch: refetchProduct,
|
||||||
} = useProductsBySlug(slug);
|
} = useProductsBySlug(slug);
|
||||||
|
|
||||||
const { data: cartData, refetch: refetchCart } = useCart();
|
const { data: cartData, refetch: refetchCart } = useCart();
|
||||||
|
|
||||||
|
const { data: relatedProducts } = useRelatedProducts(product?.id || 0, {
|
||||||
|
enabled: !!product?.id,
|
||||||
|
});
|
||||||
|
|
||||||
const addToCartMutation = useAddToCart();
|
const addToCartMutation = useAddToCart();
|
||||||
const updateCartMutation = useUpdateCartItemQuantity();
|
const updateCartMutation = useUpdateCartItemQuantity();
|
||||||
const removeFromCartMutation = useRemoveFromCart();
|
const removeFromCartMutation = useRemoveFromCart();
|
||||||
|
const submitReviewMutation = useSubmitReview();
|
||||||
|
|
||||||
const cartItem = useMemo(
|
const cartItem = useMemo(
|
||||||
() => cartData?.data?.find((item: any) => item.product?.id === product?.id),
|
() => cartData?.data?.find((item: any) => item.product?.id === product?.id),
|
||||||
[cartData, product]
|
[cartData, product]
|
||||||
);
|
);
|
||||||
const isInCart = !!cartItem;
|
const isInCart = !!cartItem;
|
||||||
|
|
||||||
const availableStock = product?.stock || 0;
|
const availableStock = product?.stock || 0;
|
||||||
|
|
||||||
const imageUrls = useMemo(
|
const imageUrls = useMemo(
|
||||||
@@ -91,42 +86,11 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
[product]
|
[product]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Auto-play carousel every 3 seconds
|
// ✅ CORRECT - Use reviews from product data
|
||||||
useEffect(() => {
|
const reviews = useMemo(() => product?.reviews_resources || [], [product]);
|
||||||
if (imageUrls.length <= 1) return;
|
const averageRating = useMemo(
|
||||||
|
() => (product?.reviews?.rating ? parseFloat(product.reviews.rating) : 0),
|
||||||
const startAutoplay = () => {
|
[product]
|
||||||
autoplayTimerRef.current = setInterval(() => {
|
|
||||||
setSelectedImage((prev) => (prev + 1) % imageUrls.length);
|
|
||||||
}, 3000);
|
|
||||||
};
|
|
||||||
|
|
||||||
startAutoplay();
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (autoplayTimerRef.current) {
|
|
||||||
clearInterval(autoplayTimerRef.current);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [imageUrls.length]);
|
|
||||||
|
|
||||||
// Reset autoplay timer when user manually selects image
|
|
||||||
const handleImageSelect = useCallback(
|
|
||||||
(index: number) => {
|
|
||||||
setSelectedImage(index);
|
|
||||||
|
|
||||||
// Reset autoplay timer
|
|
||||||
if (autoplayTimerRef.current) {
|
|
||||||
clearInterval(autoplayTimerRef.current);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (imageUrls.length > 1) {
|
|
||||||
autoplayTimerRef.current = setInterval(() => {
|
|
||||||
setSelectedImage((prev) => (prev + 1) % imageUrls.length);
|
|
||||||
}, 3000);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[imageUrls.length]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -138,19 +102,16 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
const savePendingUpdate = useCallback(
|
const savePendingUpdate = useCallback(
|
||||||
(quantity: number) => {
|
(quantity: number) => {
|
||||||
if (!product?.id) return;
|
if (!product?.id) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const stored = sessionStorage.getItem(PENDING_PRODUCT_UPDATES_KEY);
|
const stored = sessionStorage.getItem(PENDING_PRODUCT_UPDATES_KEY);
|
||||||
const pending: Record<number, PendingUpdate> = stored
|
const pending: Record<number, PendingUpdate> = stored
|
||||||
? JSON.parse(stored)
|
? JSON.parse(stored)
|
||||||
: {};
|
: {};
|
||||||
|
|
||||||
pending[product.id] = {
|
pending[product.id] = {
|
||||||
quantity,
|
quantity,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
retryCount: retryCountRef.current,
|
retryCount: retryCountRef.current,
|
||||||
};
|
};
|
||||||
|
|
||||||
sessionStorage.setItem(
|
sessionStorage.setItem(
|
||||||
PENDING_PRODUCT_UPDATES_KEY,
|
PENDING_PRODUCT_UPDATES_KEY,
|
||||||
JSON.stringify(pending)
|
JSON.stringify(pending)
|
||||||
@@ -164,13 +125,11 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
|
|
||||||
const clearPendingUpdate = useCallback(() => {
|
const clearPendingUpdate = useCallback(() => {
|
||||||
if (!product?.id) return;
|
if (!product?.id) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const stored = sessionStorage.getItem(PENDING_PRODUCT_UPDATES_KEY);
|
const stored = sessionStorage.getItem(PENDING_PRODUCT_UPDATES_KEY);
|
||||||
if (stored) {
|
if (stored) {
|
||||||
const pending: Record<number, PendingUpdate> = JSON.parse(stored);
|
const pending: Record<number, PendingUpdate> = JSON.parse(stored);
|
||||||
delete pending[product.id];
|
delete pending[product.id];
|
||||||
|
|
||||||
if (Object.keys(pending).length === 0) {
|
if (Object.keys(pending).length === 0) {
|
||||||
sessionStorage.removeItem(PENDING_PRODUCT_UPDATES_KEY);
|
sessionStorage.removeItem(PENDING_PRODUCT_UPDATES_KEY);
|
||||||
} else {
|
} else {
|
||||||
@@ -225,7 +184,6 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
setSyncError(false);
|
setSyncError(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// If quantity is 0, remove from cart
|
|
||||||
if (quantity === 0) {
|
if (quantity === 0) {
|
||||||
await removeFromCartMutation.mutateAsync(product.id);
|
await removeFromCartMutation.mutateAsync(product.id);
|
||||||
toast.success(t("removed_from_cart"));
|
toast.success(t("removed_from_cart"));
|
||||||
@@ -245,7 +203,6 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
setIsSyncing(false);
|
setIsSyncing(false);
|
||||||
retryCountRef.current = 0;
|
retryCountRef.current = 0;
|
||||||
clearPendingUpdate();
|
clearPendingUpdate();
|
||||||
|
|
||||||
await refetchCart();
|
await refetchCart();
|
||||||
|
|
||||||
if (pendingQuantityRef.current !== null) {
|
if (pendingQuantityRef.current !== null) {
|
||||||
@@ -340,7 +297,6 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
return () => {
|
return () => {
|
||||||
if (debounceTimerRef.current) clearTimeout(debounceTimerRef.current);
|
if (debounceTimerRef.current) clearTimeout(debounceTimerRef.current);
|
||||||
if (retryTimerRef.current) clearTimeout(retryTimerRef.current);
|
if (retryTimerRef.current) clearTimeout(retryTimerRef.current);
|
||||||
if (autoplayTimerRef.current) clearInterval(autoplayTimerRef.current);
|
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -356,7 +312,6 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await refetchCart();
|
await refetchCart();
|
||||||
|
|
||||||
setIsSyncing(false);
|
setIsSyncing(false);
|
||||||
|
|
||||||
toast.success(t("added_to_cart"), {
|
toast.success(t("added_to_cart"), {
|
||||||
@@ -376,14 +331,11 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
setShowStockModal(true);
|
setShowStockModal(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setLocalQuantity((prev) => prev + 1);
|
setLocalQuantity((prev) => prev + 1);
|
||||||
}, [localQuantity, availableStock]);
|
}, [localQuantity, availableStock]);
|
||||||
|
|
||||||
const handleQuantityDecrease = useCallback(() => {
|
const handleQuantityDecrease = useCallback(() => {
|
||||||
// Allow decreasing to 0 to remove from cart
|
|
||||||
if (localQuantity <= 0) return;
|
if (localQuantity <= 0) return;
|
||||||
|
|
||||||
setLocalQuantity((prev) => prev - 1);
|
setLocalQuantity((prev) => prev - 1);
|
||||||
}, [localQuantity]);
|
}, [localQuantity]);
|
||||||
|
|
||||||
@@ -391,6 +343,37 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
setIsFavorite(!isFavorite);
|
setIsFavorite(!isFavorite);
|
||||||
}, [isFavorite]);
|
}, [isFavorite]);
|
||||||
|
|
||||||
|
const handleSubmitReview = useCallback(
|
||||||
|
async (rating: number, text: string) => {
|
||||||
|
if (!product?.id || rating === 0 || !text.trim()) {
|
||||||
|
toast.error(t("error"), {
|
||||||
|
description: "Please provide rating and review text",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await submitReviewMutation.mutateAsync({
|
||||||
|
productId: product.id,
|
||||||
|
rating: rating,
|
||||||
|
title: text,
|
||||||
|
source: "site",
|
||||||
|
});
|
||||||
|
|
||||||
|
// ✅ Refetch product to get updated reviews
|
||||||
|
await refetchProduct();
|
||||||
|
|
||||||
|
toast.success("Review submitted successfully!");
|
||||||
|
setShowReviewModal(false);
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(t("error"), {
|
||||||
|
description: "Failed to submit review",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[product?.id, submitReviewMutation, refetchProduct, t]
|
||||||
|
);
|
||||||
|
|
||||||
const loadingSkeleton = useMemo(
|
const loadingSkeleton = useMemo(
|
||||||
() => (
|
() => (
|
||||||
<div className="container mx-auto px-4 py-8">
|
<div className="container mx-auto px-4 py-8">
|
||||||
@@ -413,9 +396,7 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (productLoading) {
|
if (productLoading) return loadingSkeleton;
|
||||||
return loadingSkeleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error || !product) {
|
if (error || !product) {
|
||||||
return (
|
return (
|
||||||
@@ -434,318 +415,67 @@ export default function ProductPageContent({ slug }: ProductDetailProps) {
|
|||||||
<>
|
<>
|
||||||
<div className="px-2 md:px-4 lg:px-6 rounded-lg mb-18 space-y-8 max-w-[1504px] mx-auto">
|
<div className="px-2 md:px-4 lg:px-6 rounded-lg mb-18 space-y-8 max-w-[1504px] mx-auto">
|
||||||
<div className="flex flex-col lg:flex-row gap-8 rounded-b-lg bg-white p-4">
|
<div className="flex flex-col lg:flex-row gap-8 rounded-b-lg bg-white p-4">
|
||||||
<div className="flex-1 max-w-2xl">
|
<ProductImageGallery
|
||||||
<div className="relative">
|
images={imageUrls}
|
||||||
<div className="relative aspect-square w-full rounded-2xl overflow-hidden bg-white">
|
productName={product.name}
|
||||||
{imageUrls.length > 0 ? (
|
noImageText={t("no_image")}
|
||||||
<Image
|
/>
|
||||||
src={imageUrls[selectedImage]}
|
|
||||||
alt={product.name}
|
|
||||||
fill
|
|
||||||
className="object-contain"
|
|
||||||
priority
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<div className="flex items-center justify-center h-full text-gray-400">
|
|
||||||
{t("no_image")}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{imageUrls.length > 1 && (
|
<ProductInfoCard
|
||||||
<div className="mt-4 flex gap-2 overflow-x-auto pb-2">
|
brandName={product.brand?.name}
|
||||||
{imageUrls.map((image, index) => (
|
stock={product.stock}
|
||||||
<button
|
barcode={product.barcode}
|
||||||
key={index}
|
colour={product.colour}
|
||||||
onClick={() => handleImageSelect(index)}
|
properties={product.properties}
|
||||||
className={`relative w-16 h-16 flex-shrink-0 rounded overflow-hidden border-2 transition-all ${
|
description={product.description}
|
||||||
selectedImage === index
|
averageRating={averageRating}
|
||||||
? "border-primary ring-2 ring-primary/20"
|
reviewsCount={product.reviews?.count || 0}
|
||||||
: "border-gray-200 hover:border-gray-300"
|
t={t}
|
||||||
}`}
|
/>
|
||||||
>
|
|
||||||
<Image
|
|
||||||
src={image}
|
|
||||||
alt={`${product.name} ${index + 1}`}
|
|
||||||
fill
|
|
||||||
className="object-cover"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex-1 space-y-6 bg-white">
|
<ProductPurchaseCard
|
||||||
<div>
|
price={product.price_amount}
|
||||||
<h1 className="text-3xl font-bold mb-2">{product.name}</h1>
|
oldPrice={product.old_price_amount}
|
||||||
</div>
|
isInCart={isInCart}
|
||||||
|
localQuantity={localQuantity}
|
||||||
<Card className="p-4 rounded-xl border-gray-200">
|
availableStock={availableStock}
|
||||||
<h3 className="text-xl font-semibold mb-4">
|
isSyncing={isSyncing}
|
||||||
{t("about_product")}
|
syncError={syncError}
|
||||||
</h3>
|
isFavorite={isFavorite}
|
||||||
<div className="space-y-3">
|
productStock={product.stock}
|
||||||
{product.brand?.name && (
|
channelName={product.channel?.[0]?.name}
|
||||||
<>
|
onAddToCart={handleAddToCart}
|
||||||
<div className="flex justify-between items-center py-2">
|
onQuantityIncrease={handleQuantityIncrease}
|
||||||
<span className="text-gray-500">{t("brands")}</span>
|
onQuantityDecrease={handleQuantityDecrease}
|
||||||
<span className="font-medium">{product.brand.name}</span>
|
onToggleFavorite={handleToggleFavorite}
|
||||||
</div>
|
t={t}
|
||||||
<Separator />
|
/>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{product.stock !== undefined && (
|
|
||||||
<>
|
|
||||||
<div className="flex justify-between items-center py-2">
|
|
||||||
<span className="text-gray-500">{t("stock")}</span>
|
|
||||||
<span
|
|
||||||
className={`font-medium ${
|
|
||||||
product.stock === 0
|
|
||||||
? "text-red-500"
|
|
||||||
: product.stock <= 5
|
|
||||||
? "text-orange-600"
|
|
||||||
: "text-green-600"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{product.stock === 0
|
|
||||||
? t("out_of_stock")
|
|
||||||
: product.stock <= 5
|
|
||||||
? `${t("only_left", { count: product.stock })}`
|
|
||||||
: product.stock}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<Separator />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{product.barcode && (
|
|
||||||
<>
|
|
||||||
<div className="flex justify-between items-center py-2">
|
|
||||||
<span className="text-gray-500">{t("barcode")}</span>
|
|
||||||
<span className="font-mono text-sm">
|
|
||||||
{product.barcode}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<Separator />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{product.colour && (
|
|
||||||
<>
|
|
||||||
<div className="flex justify-between items-center py-2">
|
|
||||||
<span className="text-gray-500">{t("color")}</span>
|
|
||||||
<span className="font-medium">{product.colour}</span>
|
|
||||||
</div>
|
|
||||||
<Separator />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{product.properties && product.properties.length > 0 && (
|
|
||||||
<>
|
|
||||||
{product.properties.map(
|
|
||||||
(prop, idx) =>
|
|
||||||
prop.value && (
|
|
||||||
<div key={idx}>
|
|
||||||
<div className="flex justify-between items-center py-2">
|
|
||||||
<span className="text-gray-500">{prop.name}</span>
|
|
||||||
<span className="font-medium">{prop.value}</span>
|
|
||||||
</div>
|
|
||||||
{idx < product.properties.length - 1 && (
|
|
||||||
<Separator />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{product.description && (
|
|
||||||
<Card className="p-4 rounded-xl border-gray-200">
|
|
||||||
<h3 className="text-xl font-semibold mb-3">
|
|
||||||
{t("product_description")}
|
|
||||||
</h3>
|
|
||||||
<div
|
|
||||||
className="text-gray-700 leading-relaxed prose prose-sm max-w-none"
|
|
||||||
dangerouslySetInnerHTML={{ __html: product.description }}
|
|
||||||
/>
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="lg:w-[380px] space-y-4">
|
|
||||||
<Card className="p-6 rounded-xl ">
|
|
||||||
<div className="flex justify-between items-start mb-6">
|
|
||||||
<span className="text-lg text-gray-500">{t("price")}:</span>
|
|
||||||
<div className="flex flex-col items-end">
|
|
||||||
<span className="text-3xl font-bold text-primary">
|
|
||||||
{product.price_amount} TMT
|
|
||||||
</span>
|
|
||||||
{product.old_price_amount &&
|
|
||||||
parseFloat(product.old_price_amount) > 0 && (
|
|
||||||
<span className="text-lg text-gray-400 line-through">
|
|
||||||
{product.old_price_amount} TMT
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
{isInCart ? (
|
|
||||||
<>
|
|
||||||
<Link href="/cart">
|
|
||||||
<Button
|
|
||||||
size="lg"
|
|
||||||
className="w-full rounded-lg text-lg font-bold bg-green-600 hover:bg-green-700 mb-4"
|
|
||||||
>
|
|
||||||
<ShoppingCart className="mr-2 h-5 w-5" />
|
|
||||||
{t("go_to_cart")}
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
onClick={handleQuantityDecrease}
|
|
||||||
disabled={isSyncing}
|
|
||||||
className={`rounded-lg h-12 w-12 ${
|
|
||||||
isSyncing ? "opacity-70" : ""
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<Minus className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
<div className="flex-1 text-center font-semibold text-xl border rounded-xl h-12 flex items-center justify-center relative">
|
|
||||||
{localQuantity}
|
|
||||||
|
|
||||||
{syncError && (
|
|
||||||
<span
|
|
||||||
className="absolute -top-1 -right-1 h-2 w-2 bg-red-500 rounded-full"
|
|
||||||
title="Sync error"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
onClick={handleQuantityIncrease}
|
|
||||||
disabled={localQuantity >= availableStock || isSyncing}
|
|
||||||
className={`rounded-lg h-12 w-12 ${
|
|
||||||
isSyncing ? "opacity-70" : ""
|
|
||||||
} ${
|
|
||||||
localQuantity >= availableStock
|
|
||||||
? "opacity-50 cursor-not-allowed"
|
|
||||||
: ""
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<Plus className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
onClick={handleToggleFavorite}
|
|
||||||
className={`rounded-lg h-12 w-12 transition-all border cursor-pointer ${
|
|
||||||
isFavorite
|
|
||||||
? "bg-[#F0F8FF] border-blue-300 hover:bg-blue-100"
|
|
||||||
: "hover:bg-gray-50"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<Heart
|
|
||||||
className={`h-6! w-6! transition-all ${
|
|
||||||
isFavorite
|
|
||||||
? "fill-[#005bff] text-[#005bff]"
|
|
||||||
: "text-[#005bff]"
|
|
||||||
}`}
|
|
||||||
/>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<Button
|
|
||||||
size="lg"
|
|
||||||
onClick={handleAddToCart}
|
|
||||||
disabled={isSyncing || product.stock === 0}
|
|
||||||
className="w-full rounded-lg text-lg font-bold bg-[#005bff] hover:bg-[#0041c4] cursor-pointer"
|
|
||||||
>
|
|
||||||
{isSyncing ? (
|
|
||||||
<>
|
|
||||||
<Loader2 className="mr-2 h-5 w-5 animate-spin" />
|
|
||||||
{t("adding")}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<ShoppingCart className="mr-2 h-5 w-5" />
|
|
||||||
{product.stock === 0
|
|
||||||
? t("out_of_stock")
|
|
||||||
: t("add_to_cart")}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{product.channel && product.channel.length > 0 && (
|
|
||||||
<Card className="p-6 rounded-xl">
|
|
||||||
<div className="flex items-center gap-4 mb-4">
|
|
||||||
<Avatar className="w-14 h-14 bg-primary/10">
|
|
||||||
<AvatarFallback className="bg-transparent">
|
|
||||||
<Store className="h-6 w-6 text-primary" />
|
|
||||||
</AvatarFallback>
|
|
||||||
</Avatar>
|
|
||||||
<div>
|
|
||||||
<p className="text-sm text-gray-500">{t("store")}</p>
|
|
||||||
<h4 className="text-lg font-bold">
|
|
||||||
{product.channel[0].name}
|
|
||||||
</h4>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="lg"
|
|
||||||
className="w-full rounded-lg"
|
|
||||||
>
|
|
||||||
{t("write_to_store")}
|
|
||||||
</Button>
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ProductReviewsSection
|
||||||
|
reviews={reviews}
|
||||||
|
averageRating={averageRating}
|
||||||
|
isLoading={false}
|
||||||
|
onWriteReview={() => setShowReviewModal(true)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<RelatedProductsSection products={relatedProducts || []} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Dialog open={showStockModal} onOpenChange={setShowStockModal}>
|
<StockLimitModal
|
||||||
<DialogContent className="sm:max-w-md">
|
open={showStockModal}
|
||||||
<DialogHeader>
|
onOpenChange={setShowStockModal}
|
||||||
<div className="flex items-center justify-center mb-4">
|
productName={product.name}
|
||||||
<div className="rounded-full bg-orange-100 p-3">
|
availableStock={availableStock}
|
||||||
<AlertTriangle className="h-6 w-6 text-orange-600" />
|
t={t}
|
||||||
</div>
|
/>
|
||||||
</div>
|
|
||||||
<DialogTitle className="text-center text-xl">
|
<ReviewModal
|
||||||
{t("stock_limit_title")}
|
open={showReviewModal}
|
||||||
</DialogTitle>
|
onOpenChange={setShowReviewModal}
|
||||||
<DialogDescription className="text-center text-base pt-2">
|
onSubmit={handleSubmitReview}
|
||||||
{t("stock_limit_message", {
|
isSubmitting={submitReviewMutation.isPending}
|
||||||
product: product.name,
|
/>
|
||||||
stock: availableStock,
|
|
||||||
})}
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
<div className="flex justify-center mt-4">
|
|
||||||
<Button
|
|
||||||
onClick={() => setShowStockModal(false)}
|
|
||||||
className="w-full rounded-lg"
|
|
||||||
>
|
|
||||||
{t("understood")}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
172
features/products/components/ProductPurchaseCard.tsx
Normal file
172
features/products/components/ProductPurchaseCard.tsx
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { Minus, Plus, Heart, ShoppingCart, Store, Loader2 } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Card } from "@/components/ui/card";
|
||||||
|
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
||||||
|
|
||||||
|
interface ProductPurchaseCardProps {
|
||||||
|
price: string;
|
||||||
|
oldPrice?: string;
|
||||||
|
isInCart: boolean;
|
||||||
|
localQuantity: number;
|
||||||
|
availableStock: number;
|
||||||
|
isSyncing: boolean;
|
||||||
|
syncError: boolean;
|
||||||
|
isFavorite: boolean;
|
||||||
|
productStock: number;
|
||||||
|
channelName?: string;
|
||||||
|
onAddToCart: () => void;
|
||||||
|
onQuantityIncrease: () => void;
|
||||||
|
onQuantityDecrease: () => void;
|
||||||
|
onToggleFavorite: () => void;
|
||||||
|
t: (key: string) => string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ProductPurchaseCard({
|
||||||
|
price,
|
||||||
|
oldPrice,
|
||||||
|
isInCart,
|
||||||
|
localQuantity,
|
||||||
|
availableStock,
|
||||||
|
isSyncing,
|
||||||
|
syncError,
|
||||||
|
isFavorite,
|
||||||
|
productStock,
|
||||||
|
channelName,
|
||||||
|
onAddToCart,
|
||||||
|
onQuantityIncrease,
|
||||||
|
onQuantityDecrease,
|
||||||
|
onToggleFavorite,
|
||||||
|
t,
|
||||||
|
}: ProductPurchaseCardProps) {
|
||||||
|
return (
|
||||||
|
<div className="lg:w-[380px] space-y-4">
|
||||||
|
<Card className="p-6 rounded-xl">
|
||||||
|
<div className="flex justify-between items-start mb-6">
|
||||||
|
<span className="text-lg text-gray-500">{t("price")}:</span>
|
||||||
|
<div className="flex flex-col items-end">
|
||||||
|
<span className="text-3xl font-bold text-primary">
|
||||||
|
{price} TMT
|
||||||
|
</span>
|
||||||
|
{oldPrice && parseFloat(oldPrice) > 0 && (
|
||||||
|
<span className="text-lg text-gray-400 line-through">
|
||||||
|
{oldPrice} TMT
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
{isInCart ? (
|
||||||
|
<>
|
||||||
|
<Link href="/cart">
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
className="w-full rounded-lg text-lg font-bold bg-green-600 hover:bg-green-700 mb-4"
|
||||||
|
>
|
||||||
|
<ShoppingCart className="mr-2 h-5 w-5" />
|
||||||
|
{t("go_to_cart")}
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={onQuantityDecrease}
|
||||||
|
disabled={isSyncing}
|
||||||
|
className={`rounded-lg h-12 w-12 ${
|
||||||
|
isSyncing ? "opacity-70" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Minus className="h-5 w-5" />
|
||||||
|
</Button>
|
||||||
|
<div className="flex-1 text-center font-semibold text-xl border rounded-xl h-12 flex items-center justify-center relative">
|
||||||
|
{localQuantity}
|
||||||
|
{syncError && (
|
||||||
|
<span
|
||||||
|
className="absolute -top-1 -right-1 h-2 w-2 bg-red-500 rounded-full"
|
||||||
|
title="Sync error"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={onQuantityIncrease}
|
||||||
|
disabled={localQuantity >= availableStock || isSyncing}
|
||||||
|
className={`rounded-lg h-12 w-12 ${
|
||||||
|
isSyncing ? "opacity-70" : ""
|
||||||
|
} ${
|
||||||
|
localQuantity >= availableStock
|
||||||
|
? "opacity-50 cursor-not-allowed"
|
||||||
|
: ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Plus className="h-5 w-5" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={onToggleFavorite}
|
||||||
|
className={`rounded-lg h-12 w-12 transition-all border cursor-pointer ${
|
||||||
|
isFavorite
|
||||||
|
? "bg-[#F0F8FF] border-blue-300 hover:bg-blue-100"
|
||||||
|
: "hover:bg-gray-50"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Heart
|
||||||
|
className={`h-6! w-6! transition-all ${
|
||||||
|
isFavorite
|
||||||
|
? "fill-[#005bff] text-[#005bff]"
|
||||||
|
: "text-[#005bff]"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
onClick={onAddToCart}
|
||||||
|
disabled={isSyncing || productStock === 0}
|
||||||
|
className="w-full rounded-lg text-lg font-bold bg-[#005bff] hover:bg-[#0041c4] cursor-pointer"
|
||||||
|
>
|
||||||
|
{isSyncing ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="mr-2 h-5 w-5 animate-spin" />
|
||||||
|
{t("adding")}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<ShoppingCart className="mr-2 h-5 w-5" />
|
||||||
|
{productStock === 0 ? t("out_of_stock") : t("add_to_cart")}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{channelName && (
|
||||||
|
<Card className="p-6 rounded-xl">
|
||||||
|
<div className="flex items-center gap-4 mb-4">
|
||||||
|
<Avatar className="w-14 h-14 bg-primary/10">
|
||||||
|
<AvatarFallback className="bg-transparent">
|
||||||
|
<Store className="h-6 w-6 text-primary" />
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-gray-500">{t("store")}</p>
|
||||||
|
<h4 className="text-lg font-bold">{channelName}</h4>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button variant="outline" size="lg" className="w-full rounded-lg">
|
||||||
|
{t("write_to_store")}
|
||||||
|
</Button>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
91
features/products/components/ProductReviewsSection.tsx
Normal file
91
features/products/components/ProductReviewsSection.tsx
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import { Star, Send } from "lucide-react";
|
||||||
|
import { Card } from "@/components/ui/card";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
|
||||||
|
interface Review {
|
||||||
|
id: number;
|
||||||
|
rating: number;
|
||||||
|
title: string;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProductReviewsSectionProps {
|
||||||
|
reviews: Review[];
|
||||||
|
averageRating: number;
|
||||||
|
isLoading: boolean;
|
||||||
|
onWriteReview: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ProductReviewsSection({
|
||||||
|
reviews,
|
||||||
|
averageRating,
|
||||||
|
isLoading,
|
||||||
|
onWriteReview,
|
||||||
|
}: ProductReviewsSectionProps) {
|
||||||
|
const renderStars = (rating: number) => {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
{[1, 2, 3, 4, 5].map((star) => (
|
||||||
|
<Star
|
||||||
|
key={star}
|
||||||
|
className={`h-5 w-5 transition-all ${
|
||||||
|
star <= rating
|
||||||
|
? "fill-yellow-400 text-yellow-400"
|
||||||
|
: "text-gray-300"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="p-6 rounded-xl">
|
||||||
|
<div className="flex justify-between items-center mb-6">
|
||||||
|
<div>
|
||||||
|
<h3 className="text-2xl font-bold">Customer Reviews</h3>
|
||||||
|
<div className="flex items-center gap-2 mt-2">
|
||||||
|
{renderStars(Math.round(averageRating))}
|
||||||
|
<span className="text-sm text-gray-600">
|
||||||
|
{averageRating.toFixed(1)} out of 5
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button onClick={onWriteReview} className="rounded-lg">
|
||||||
|
<Send className="mr-2 h-4 w-4" />
|
||||||
|
Write Review
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator className="my-4" />
|
||||||
|
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{[1, 2, 3].map((i) => (
|
||||||
|
<Skeleton key={i} className="h-24 w-full" />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : reviews.length > 0 ? (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{reviews.map((review) => (
|
||||||
|
<div key={review.id} className="border-b pb-4 last:border-0">
|
||||||
|
<div className="flex items-start justify-between mb-2">
|
||||||
|
<div>
|
||||||
|
{renderStars(review.rating)}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-gray-700">{review.title}</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="text-center py-8 text-gray-500">
|
||||||
|
No reviews yet. Be the first to review this product!
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
74
features/products/components/RelatedProductsSection.tsx
Normal file
74
features/products/components/RelatedProductsSection.tsx
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import ProductCard from "@/features/home/components/ProductCard";
|
||||||
|
|
||||||
|
interface RelatedProduct {
|
||||||
|
id: number;
|
||||||
|
slug: string;
|
||||||
|
name: string;
|
||||||
|
price_amount: string;
|
||||||
|
old_price_amount?: string;
|
||||||
|
struct_price_text: string;
|
||||||
|
discount?: number | null;
|
||||||
|
discount_text?: string | null;
|
||||||
|
stock?: number;
|
||||||
|
media: Array<{
|
||||||
|
images_800x800?: string;
|
||||||
|
images_720x720?: string;
|
||||||
|
images_400x400?: string;
|
||||||
|
thumbnail: string;
|
||||||
|
}>;
|
||||||
|
labels?: Array<{
|
||||||
|
text: string;
|
||||||
|
bg_color: string;
|
||||||
|
}>;
|
||||||
|
price_color?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RelatedProductsSectionProps {
|
||||||
|
products: RelatedProduct[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RelatedProductsSection({
|
||||||
|
products,
|
||||||
|
}: RelatedProductsSectionProps) {
|
||||||
|
if (!products || products.length === 0) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-white rounded-lg p-6">
|
||||||
|
<h2 className="text-2xl font-bold mb-6">Related Products</h2>
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
|
||||||
|
{products.slice(0, 4).map((product) => {
|
||||||
|
// Extract image URLs from media
|
||||||
|
const images =
|
||||||
|
product.media?.map(
|
||||||
|
(m) =>
|
||||||
|
m.images_800x800 ||
|
||||||
|
m.images_720x720 ||
|
||||||
|
m.images_400x400 ||
|
||||||
|
m.thumbnail
|
||||||
|
) || [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ProductCard
|
||||||
|
key={product.id}
|
||||||
|
id={product.id}
|
||||||
|
name={product.name}
|
||||||
|
price={parseFloat(product.price_amount) || null}
|
||||||
|
struct_price_text={
|
||||||
|
product.struct_price_text || `${product.price_amount} TMT`
|
||||||
|
}
|
||||||
|
discount={product.discount}
|
||||||
|
discount_text={product.discount_text}
|
||||||
|
images={images}
|
||||||
|
labels={product.labels || []}
|
||||||
|
price_color={product.price_color}
|
||||||
|
height={360}
|
||||||
|
width={280}
|
||||||
|
button={true}
|
||||||
|
stock={product.stock}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
121
features/products/components/ReviewModal.tsx
Normal file
121
features/products/components/ReviewModal.tsx
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { Star, Send, Loader2 } from "lucide-react";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
|
||||||
|
interface ReviewModalProps {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
onSubmit: (rating: number, text: string) => Promise<void>;
|
||||||
|
isSubmitting: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ReviewModal({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
onSubmit,
|
||||||
|
isSubmitting,
|
||||||
|
}: ReviewModalProps) {
|
||||||
|
const [rating, setRating] = useState(0);
|
||||||
|
const [text, setText] = useState("");
|
||||||
|
const [hoveredStar, setHoveredStar] = useState(0);
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
onOpenChange(false);
|
||||||
|
setRating(0);
|
||||||
|
setText("");
|
||||||
|
setHoveredStar(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
await onSubmit(rating, text);
|
||||||
|
handleClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderStars = () => {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
{[1, 2, 3, 4, 5].map((star) => (
|
||||||
|
<Star
|
||||||
|
key={star}
|
||||||
|
className={`h-5 w-5 cursor-pointer transition-all ${
|
||||||
|
star <= (hoveredStar || rating)
|
||||||
|
? "fill-yellow-400 text-yellow-400"
|
||||||
|
: "text-gray-300"
|
||||||
|
}`}
|
||||||
|
onClick={() => setRating(star)}
|
||||||
|
onMouseEnter={() => setHoveredStar(star)}
|
||||||
|
onMouseLeave={() => setHoveredStar(0)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-lg">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="text-xl">Write a Review</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Share your experience with this product
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="space-y-4 pt-4">
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-2">Rating</label>
|
||||||
|
{renderStars()}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-2">
|
||||||
|
Your Review
|
||||||
|
</label>
|
||||||
|
<Textarea
|
||||||
|
value={text}
|
||||||
|
onChange={(e) => setText(e.target.value)}
|
||||||
|
placeholder="Write your review here..."
|
||||||
|
className="min-h-[120px] resize-none"
|
||||||
|
maxLength={500}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-gray-500 mt-1">
|
||||||
|
{text.length}/500 characters
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-3 mt-6">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleClose}
|
||||||
|
className="flex-1 rounded-lg"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={rating === 0 || !text.trim() || isSubmitting}
|
||||||
|
className="flex-1 rounded-lg"
|
||||||
|
>
|
||||||
|
{isSubmitting ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||||
|
Submitting...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Send className="mr-2 h-4 w-4" />
|
||||||
|
Submit Review
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
56
features/products/components/StockLimitModal.tsx
Normal file
56
features/products/components/StockLimitModal.tsx
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import { AlertTriangle } from "lucide-react";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
|
interface StockLimitModalProps {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
productName: string;
|
||||||
|
availableStock: number;
|
||||||
|
t: (key: string, params?: any) => string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StockLimitModal({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
productName,
|
||||||
|
availableStock,
|
||||||
|
t,
|
||||||
|
}: StockLimitModalProps) {
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-md">
|
||||||
|
<DialogHeader>
|
||||||
|
<div className="flex items-center justify-center mb-4">
|
||||||
|
<div className="rounded-full bg-orange-100 p-3">
|
||||||
|
<AlertTriangle className="h-6 w-6 text-orange-600" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogTitle className="text-center text-xl">
|
||||||
|
{t("stock_limit_title")}
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription className="text-center text-base pt-2">
|
||||||
|
{t("stock_limit_message", {
|
||||||
|
product: productName,
|
||||||
|
stock: availableStock,
|
||||||
|
})}
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="flex justify-center mt-4">
|
||||||
|
<Button
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
className="w-full rounded-lg"
|
||||||
|
>
|
||||||
|
{t("understood")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,101 +2,147 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|||||||
import { apiClient } from "@/lib/api";
|
import { apiClient } from "@/lib/api";
|
||||||
import type { Review, Product, PaginatedResponse } from "@/lib/types/api";
|
import type { Review, Product, PaginatedResponse } from "@/lib/types/api";
|
||||||
|
|
||||||
// Get single review by ID
|
// Types
|
||||||
|
interface PaginationOptions {
|
||||||
|
enabled?: boolean;
|
||||||
|
page?: number;
|
||||||
|
limit?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ReviewSubmission {
|
||||||
|
productId: number | string;
|
||||||
|
rating: number;
|
||||||
|
title: string;
|
||||||
|
source?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ReviewUpdate {
|
||||||
|
reviewId: number | string;
|
||||||
|
rating?: number;
|
||||||
|
title?: string;
|
||||||
|
source?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
const DEFAULT_STALE_TIME = 1000 * 60 * 5; // 5 minutes
|
||||||
|
const EXTENDED_STALE_TIME = 1000 * 60 * 15; // 15 minutes
|
||||||
|
|
||||||
|
// Query Keys Factory
|
||||||
|
const reviewKeys = {
|
||||||
|
all: ["reviews"],
|
||||||
|
lists: () => [...reviewKeys.all, "list"],
|
||||||
|
list: (page?: number, limit?: number) => [...reviewKeys.lists(), page, limit],
|
||||||
|
details: () => [...reviewKeys.all, "detail"],
|
||||||
|
detail: (id: number | string) => [...reviewKeys.details(), id],
|
||||||
|
related: (id: number | string) => [...reviewKeys.detail(id), "related"],
|
||||||
|
byProduct: (productId: number | string, page?: number, limit?: number) => [
|
||||||
|
...reviewKeys.all,
|
||||||
|
"product",
|
||||||
|
productId,
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const productKeys = {
|
||||||
|
all: ["products"],
|
||||||
|
details: () => [...productKeys.all, "detail"],
|
||||||
|
detail: (id: number | string) => [...productKeys.details(), id],
|
||||||
|
bySlug: (slug: string) => [...productKeys.all, "slug", slug],
|
||||||
|
related: (id: number | string) => [...productKeys.detail(id), "related"],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generic fetch function
|
||||||
|
async function fetchData<T>(
|
||||||
|
url: string,
|
||||||
|
params?: Record<string, any>
|
||||||
|
): Promise<T> {
|
||||||
|
const response = await apiClient.get<T>(url, { params });
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Review Queries
|
||||||
export function useReview(
|
export function useReview(
|
||||||
reviewId: number | string,
|
reviewId: number | string,
|
||||||
options?: { enabled?: boolean }
|
options?: { enabled?: boolean }
|
||||||
) {
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["review", reviewId],
|
queryKey: reviewKeys.detail(reviewId),
|
||||||
queryFn: async () => {
|
queryFn: () => fetchData<Review>(`/reviews/${reviewId}`),
|
||||||
const response = await apiClient.get<Review>(`/reviews/${reviewId}`);
|
|
||||||
return response.data;
|
|
||||||
},
|
|
||||||
enabled: options?.enabled !== false && !!reviewId,
|
enabled: options?.enabled !== false && !!reviewId,
|
||||||
staleTime: 1000 * 60 * 10,
|
staleTime: DEFAULT_STALE_TIME * 2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all reviews with pagination
|
export function useReviews(options?: PaginationOptions) {
|
||||||
export function useReviews(options?: {
|
|
||||||
enabled?: boolean;
|
|
||||||
page?: number;
|
|
||||||
limit?: number;
|
|
||||||
}) {
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["reviews", options?.page, options?.limit],
|
queryKey: reviewKeys.list(options?.page, options?.limit),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const response = await apiClient.get<PaginatedResponse<Review>>(
|
const response = await fetchData<PaginatedResponse<Review>>("/reviews", {
|
||||||
`/reviews`,
|
page: options?.page || 1,
|
||||||
{
|
limit: options?.limit,
|
||||||
params: {
|
});
|
||||||
page: options?.page || 1,
|
|
||||||
limit: options?.limit,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
data: response.data.data || [],
|
data: response.data || [],
|
||||||
pagination: response.data.pagination || {},
|
pagination: response.pagination || {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
enabled: options?.enabled !== false,
|
enabled: options?.enabled !== false,
|
||||||
staleTime: 1000 * 60 * 5,
|
staleTime: DEFAULT_STALE_TIME,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get related reviews for a review
|
|
||||||
export function useRelatedReviews(
|
export function useRelatedReviews(
|
||||||
reviewId: number | string,
|
reviewId: number | string,
|
||||||
options?: { enabled?: boolean }
|
options?: { enabled?: boolean }
|
||||||
) {
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["review", reviewId, "related"],
|
queryKey: reviewKeys.related(reviewId),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const response = await apiClient.get<PaginatedResponse<Review>>(
|
const response = await fetchData<PaginatedResponse<Review>>(
|
||||||
`/reviews/${reviewId}/related`
|
`/reviews/${reviewId}/related`
|
||||||
);
|
);
|
||||||
return response.data.data || response.data;
|
return response.data || response;
|
||||||
},
|
},
|
||||||
enabled: options?.enabled !== false && !!reviewId,
|
enabled: options?.enabled !== false && !!reviewId,
|
||||||
staleTime: 1000 * 60 * 15,
|
staleTime: EXTENDED_STALE_TIME,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useProducts(options?: UseProductsOptions) {
|
export function useProductReviews(
|
||||||
|
productId: number | string,
|
||||||
|
options?: PaginationOptions
|
||||||
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["products", options?.page, options?.perPage],
|
queryKey: reviewKeys.byProduct(productId, options?.page, options?.limit),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const response = await apiClient.get<PaginatedResponse<Product>>(
|
const response = await fetchData<PaginatedResponse<Review>>(
|
||||||
"/products",
|
`/products/${productId}/reviews`,
|
||||||
{
|
{
|
||||||
params: {
|
page: options?.page || 1,
|
||||||
page: options?.page || 1,
|
limit: options?.limit || 10,
|
||||||
per_page: options?.perPage || 20,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return response.data.data || response.data;
|
return {
|
||||||
|
data: response.data || [],
|
||||||
|
pagination: response.pagination || {},
|
||||||
|
};
|
||||||
},
|
},
|
||||||
staleTime: options?.staleTime ?? 1000 * 60 * 5,
|
enabled: options?.enabled !== false && !!productId,
|
||||||
enabled: options?.enabled !== false,
|
staleTime: DEFAULT_STALE_TIME,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get single product by ID (for review context)
|
// Product Queries
|
||||||
export function useProduct(
|
export function useProduct(
|
||||||
productId: number | string,
|
productId: number | string,
|
||||||
options?: { enabled?: boolean }
|
options?: { enabled?: boolean }
|
||||||
) {
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["product", productId],
|
queryKey: productKeys.detail(productId),
|
||||||
queryFn: async () => {
|
queryFn: () => fetchData<Product>(`/products/${productId}`),
|
||||||
const response = await apiClient.get<Product>(`/products/${productId}`);
|
|
||||||
return response.data;
|
|
||||||
},
|
|
||||||
enabled: options?.enabled !== false && !!productId,
|
enabled: options?.enabled !== false && !!productId,
|
||||||
staleTime: 1000 * 60 * 10,
|
staleTime: DEFAULT_STALE_TIME * 2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,112 +151,86 @@ export function useProductsBySlug(
|
|||||||
options?: { enabled?: boolean }
|
options?: { enabled?: boolean }
|
||||||
) {
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["products", "slug", slug],
|
queryKey: productKeys.bySlug(slug),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const response = await apiClient.get(`/products/${slug}`);
|
const response = await fetchData<{ data: Product }>(`/products/${slug}`);
|
||||||
// API returns { message: "success", data: {...} }
|
return response.data || response;
|
||||||
return response.data.data || response.data;
|
|
||||||
},
|
},
|
||||||
enabled: options?.enabled !== false && !!slug,
|
enabled: options?.enabled !== false && !!slug,
|
||||||
staleTime: 1000 * 60 * 10,
|
staleTime: DEFAULT_STALE_TIME * 2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit review mutation
|
export function useRelatedProducts(
|
||||||
export function useSubmitReview() {
|
productId: number | string,
|
||||||
|
options?: { enabled?: boolean }
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: productKeys.related(productId),
|
||||||
|
queryFn: async () => {
|
||||||
|
const response = await fetchData<PaginatedResponse<Product>>(
|
||||||
|
`/products/${productId}/related`
|
||||||
|
);
|
||||||
|
return response.data || [];
|
||||||
|
},
|
||||||
|
enabled: options?.enabled !== false && !!productId,
|
||||||
|
staleTime: EXTENDED_STALE_TIME,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Review Mutations
|
||||||
|
function useReviewMutation<TVariables, TData = any>(
|
||||||
|
mutationFn: (variables: TVariables) => Promise<TData>,
|
||||||
|
invalidateKeys: (variables: TVariables, data?: TData) => any[]
|
||||||
|
) {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn,
|
||||||
productId,
|
onSuccess: (data, variables) => {
|
||||||
rating,
|
const keys = invalidateKeys(variables, data);
|
||||||
title,
|
keys.forEach((key) => {
|
||||||
source,
|
queryClient.invalidateQueries({ queryKey: key });
|
||||||
}: {
|
});
|
||||||
productId: number | string;
|
},
|
||||||
rating: number;
|
});
|
||||||
title: string;
|
}
|
||||||
source: string;
|
|
||||||
}) => {
|
export function useSubmitReview() {
|
||||||
const response = await apiClient.post<Review>(
|
return useReviewMutation<ReviewSubmission>(
|
||||||
`/products/${productId}/reviews`,
|
async ({ productId, rating, title, source = "site" }) => {
|
||||||
{ rating, title, source },
|
const response = await apiClient.post<{
|
||||||
{
|
message: string;
|
||||||
headers: {
|
data: Review[];
|
||||||
"Content-Type": "application/json",
|
}>(`/products/${productId}/reviews`, { rating, title, source });
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
onSuccess: (_, variables) => {
|
(variables) => [
|
||||||
queryClient.invalidateQueries({
|
reviewKeys.byProduct(variables.productId),
|
||||||
queryKey: ["reviews", "product", variables.productId],
|
productKeys.bySlug(""), // Invalidates all slug queries
|
||||||
});
|
reviewKeys.all,
|
||||||
queryClient.invalidateQueries({
|
]
|
||||||
queryKey: ["product", variables.productId],
|
);
|
||||||
});
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ["reviews"],
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update review mutation
|
|
||||||
export function useUpdateReview() {
|
export function useUpdateReview() {
|
||||||
const queryClient = useQueryClient();
|
return useReviewMutation<ReviewUpdate>(
|
||||||
|
async ({ reviewId, rating, title, source }) => {
|
||||||
return useMutation({
|
|
||||||
mutationFn: async ({
|
|
||||||
reviewId,
|
|
||||||
rating,
|
|
||||||
title,
|
|
||||||
source,
|
|
||||||
}: {
|
|
||||||
reviewId: number | string;
|
|
||||||
rating?: number;
|
|
||||||
title?: string;
|
|
||||||
source?: string;
|
|
||||||
}) => {
|
|
||||||
const response = await apiClient.put<Review>(
|
const response = await apiClient.put<Review>(
|
||||||
`/reviews/${reviewId}`,
|
`/reviews/${reviewId}`,
|
||||||
{ rating, title, source },
|
{ rating, title, source },
|
||||||
{
|
{ headers: { "Content-Type": "application/json" } }
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
onSuccess: (data, variables) => {
|
(variables) => [reviewKeys.detail(variables.reviewId), reviewKeys.all]
|
||||||
queryClient.invalidateQueries({
|
);
|
||||||
queryKey: ["review", variables.reviewId],
|
|
||||||
});
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ["reviews"],
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete review mutation
|
|
||||||
export function useDeleteReview() {
|
export function useDeleteReview() {
|
||||||
const queryClient = useQueryClient();
|
return useReviewMutation<number | string>(
|
||||||
|
(reviewId) =>
|
||||||
return useMutation({
|
apiClient.delete(`/reviews/${reviewId}`).then((res) => res.data),
|
||||||
mutationFn: async (reviewId: number | string) => {
|
(reviewId) => [reviewKeys.detail(reviewId), reviewKeys.all]
|
||||||
const response = await apiClient.delete(`/reviews/${reviewId}`);
|
);
|
||||||
return response.data;
|
|
||||||
},
|
|
||||||
onSuccess: (_, reviewId) => {
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ["review", reviewId],
|
|
||||||
});
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ["reviews"],
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useMemo, useState, useEffect } from "react";
|
import { useCallback, useMemo, useState, useEffect } from "react";
|
||||||
import { LogOut, Edit2, Save, X, User, Phone, MapPin, Mail } from "lucide-react";
|
import { LogOut, Edit2, Save, X, User, Phone, MapPin } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
@@ -29,7 +29,7 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
|
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
first_name: "",
|
name: "",
|
||||||
last_name: "",
|
last_name: "",
|
||||||
phone_number: "",
|
phone_number: "",
|
||||||
address: "",
|
address: "",
|
||||||
@@ -37,8 +37,9 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user && !isEditing) {
|
if (user && !isEditing) {
|
||||||
|
console.log("[Profile] User data loaded:", user);
|
||||||
setFormData({
|
setFormData({
|
||||||
first_name: user.first_name || "",
|
name: user.first_name || "",
|
||||||
last_name: user.last_name || "",
|
last_name: user.last_name || "",
|
||||||
phone_number: user.phone_number || "",
|
phone_number: user.phone_number || "",
|
||||||
address: user.address || "",
|
address: user.address || "",
|
||||||
@@ -46,14 +47,6 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
}
|
}
|
||||||
}, [user, isEditing]);
|
}, [user, isEditing]);
|
||||||
|
|
||||||
const prepareDataForAPI = useCallback(() => {
|
|
||||||
return {
|
|
||||||
name: `${formData.first_name} ${formData.last_name}`.trim(),
|
|
||||||
phone_number: formData.phone_number,
|
|
||||||
address: formData.address,
|
|
||||||
};
|
|
||||||
}, [formData]);
|
|
||||||
|
|
||||||
const handleLogout = useCallback(() => {
|
const handleLogout = useCallback(() => {
|
||||||
clearAuthToken();
|
clearAuthToken();
|
||||||
window.location.href = "/";
|
window.location.href = "/";
|
||||||
@@ -62,7 +55,7 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
const handleEdit = useCallback(() => {
|
const handleEdit = useCallback(() => {
|
||||||
if (user) {
|
if (user) {
|
||||||
setFormData({
|
setFormData({
|
||||||
first_name: user.first_name || "",
|
name: user.first_name || "",
|
||||||
last_name: user.last_name || "",
|
last_name: user.last_name || "",
|
||||||
phone_number: user.phone_number || "",
|
phone_number: user.phone_number || "",
|
||||||
address: user.address || "",
|
address: user.address || "",
|
||||||
@@ -75,7 +68,7 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
if (user) {
|
if (user) {
|
||||||
setFormData({
|
setFormData({
|
||||||
first_name: user.first_name || "",
|
name: user.first_name || "",
|
||||||
last_name: user.last_name || "",
|
last_name: user.last_name || "",
|
||||||
phone_number: user.phone_number || "",
|
phone_number: user.phone_number || "",
|
||||||
address: user.address || "",
|
address: user.address || "",
|
||||||
@@ -84,23 +77,35 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
const handleSave = useCallback(async () => {
|
const handleSave = useCallback(async () => {
|
||||||
const apiData = prepareDataForAPI();
|
if (!formData.name.trim()) {
|
||||||
|
|
||||||
if (!apiData.name) {
|
|
||||||
toast.error(t("name_required") || "Name is required");
|
toast.error(t("name_required") || "Name is required");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const apiData = {
|
||||||
|
name: formData.name.trim(),
|
||||||
|
last_name: formData.last_name.trim(),
|
||||||
|
phone_number: formData.phone_number.trim(),
|
||||||
|
address: formData.address.trim(),
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("[Profile] Saving data:", apiData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await updateProfile.mutateAsync(apiData);
|
await updateProfile.mutateAsync(apiData);
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
toast.success(t("profile_updated_success") || "Profile updated successfully");
|
toast.success(
|
||||||
|
t("profile_updated_success") || "Profile updated successfully"
|
||||||
|
);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const errorMessage = err?.response?.data?.message || t("profile_update_error") || "Failed to update profile";
|
const errorMessage =
|
||||||
|
err?.response?.data?.message ||
|
||||||
|
t("profile_update_error") ||
|
||||||
|
"Failed to update profile";
|
||||||
toast.error(errorMessage);
|
toast.error(errorMessage);
|
||||||
console.error("Profile update error:", err);
|
console.error("[Profile] Update error:", err);
|
||||||
}
|
}
|
||||||
}, [formData, updateProfile, t, prepareDataForAPI]);
|
}, [formData, updateProfile, t]);
|
||||||
|
|
||||||
const handleInputChange = useCallback(
|
const handleInputChange = useCallback(
|
||||||
(field: keyof typeof formData, value: string) => {
|
(field: keyof typeof formData, value: string) => {
|
||||||
@@ -165,7 +170,7 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-50 p-4 sm:p-6 lg:p-8 pt-20 sm:pt-24">
|
<div className="min-h-screen bg-gray-50 p-4 sm:p-6 lg:p-8 pb-20 sm:pb-24">
|
||||||
<div className="container mx-auto max-w-4xl">
|
<div className="container mx-auto max-w-4xl">
|
||||||
{/* Header Section */}
|
{/* Header Section */}
|
||||||
<div className="mb-6 sm:mb-8">
|
<div className="mb-6 sm:mb-8">
|
||||||
@@ -175,7 +180,9 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
{t("profile")}
|
{t("profile")}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-sm sm:text-base text-gray-600">
|
<p className="text-sm sm:text-base text-gray-600">
|
||||||
{isEditing ? t("edit_your_information") : t("view_your_information")}
|
{isEditing
|
||||||
|
? t("edit_your_information")
|
||||||
|
: t("view_your_information")}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-shrink-0 w-12 h-12 sm:w-14 sm:h-14 bg-blue-600 rounded-full flex items-center justify-center shadow-sm">
|
<div className="flex-shrink-0 w-12 h-12 sm:w-14 sm:h-14 bg-blue-600 rounded-full flex items-center justify-center shadow-sm">
|
||||||
@@ -209,7 +216,7 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="pt-5 sm:pt-6 space-y-4 sm:space-y-5">
|
<CardContent className="pt-5 sm:pt-6 space-y-4 sm:space-y-5">
|
||||||
{user && (
|
{user && (
|
||||||
<>
|
<>
|
||||||
@@ -217,17 +224,17 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-5">
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-5">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label
|
<Label
|
||||||
htmlFor="firstName"
|
htmlFor="name"
|
||||||
className="text-sm font-medium text-gray-700 flex items-center gap-1.5"
|
className="text-sm font-medium text-gray-700 flex items-center gap-1.5"
|
||||||
>
|
>
|
||||||
<User className="h-3.5 w-3.5 text-gray-400" />
|
<User className="h-3.5 w-3.5 text-gray-400" />
|
||||||
{t("first_name")}
|
{t("first_name")}
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
id="firstName"
|
id="name"
|
||||||
value={formData.first_name}
|
value={formData.name}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
handleInputChange("first_name", e.target.value)
|
handleInputChange("name", e.target.value)
|
||||||
}
|
}
|
||||||
disabled={!isEditing}
|
disabled={!isEditing}
|
||||||
className={`h-10 sm:h-11 text-sm sm:text-base ${
|
className={`h-10 sm:h-11 text-sm sm:text-base ${
|
||||||
@@ -264,6 +271,8 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-5">
|
||||||
|
|
||||||
{/* Phone Field */}
|
{/* Phone Field */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label
|
<Label
|
||||||
@@ -288,7 +297,6 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
placeholder={t("enter_phone_number")}
|
placeholder={t("enter_phone_number")}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Address Field */}
|
{/* Address Field */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label
|
<Label
|
||||||
@@ -313,6 +321,8 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
placeholder={t("enter_address")}
|
placeholder={t("enter_address")}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{/* Action Buttons - Edit Mode */}
|
{/* Action Buttons - Edit Mode */}
|
||||||
{isEditing && (
|
{isEditing && (
|
||||||
@@ -323,7 +333,9 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
className="w-full sm:flex-1 bg-blue-600 hover:bg-blue-700 h-10 sm:h-11 text-sm sm:text-base font-medium shadow-sm"
|
className="w-full sm:flex-1 bg-blue-600 hover:bg-blue-700 h-10 sm:h-11 text-sm sm:text-base font-medium shadow-sm"
|
||||||
>
|
>
|
||||||
<Save className="h-4 w-4 mr-2" />
|
<Save className="h-4 w-4 mr-2" />
|
||||||
{updateProfile.isPending ? t("saving") : t("save_changes")}
|
{updateProfile.isPending
|
||||||
|
? t("saving")
|
||||||
|
: t("save_changes")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleCancel}
|
onClick={handleCancel}
|
||||||
@@ -356,4 +368,4 @@ export default function ClientProfilePage(props: ProfilePageProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { UserProfile } from "./types";
|
import type { UserProfile } from "@/lib/types/api";
|
||||||
|
|
||||||
// In-memory store (session-based, no persistence)
|
// In-memory store (session-based, no persistence)
|
||||||
class UserStore {
|
class UserStore {
|
||||||
@@ -16,11 +16,12 @@ class UserStore {
|
|||||||
this.user = null;
|
this.user = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrderData(): { customer_name: string; customer_phone: string } | null {
|
getOrderData(): { customer_name: string; customer_phone: string, customer_last_name: string } | null {
|
||||||
if (!this.user) return null;
|
if (!this.user) return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
customer_name: `${this.user.first_name} ${this.user.last_name}`.trim(),
|
customer_name: this.user.first_name,
|
||||||
|
customer_last_name: this.user.last_name,
|
||||||
customer_phone: this.user.phone_number,
|
customer_phone: this.user.phone_number,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
"enterPhone": "Введите свой номер телефона",
|
"enterPhone": "Введите свой номер телефона",
|
||||||
"weWillSendCode": "Мы вышлем вам код",
|
"weWillSendCode": "Мы вышлем вам код",
|
||||||
"loading": "Загрузка...",
|
"loading": "Загрузка...",
|
||||||
"all_collections_loaded": "Все коллекции загружены"
|
"all_collections_loaded": "Все коллекции загружены"
|
||||||
},
|
},
|
||||||
"category": "Категория",
|
"category": "Категория",
|
||||||
"checkout": "Оформить заказ",
|
"checkout": "Оформить заказ",
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
"total_price": "Общая цена:",
|
"total_price": "Общая цена:",
|
||||||
"profile": "Профиль",
|
"profile": "Профиль",
|
||||||
"cart_orders": "Корзина заказов",
|
"cart_orders": "Корзина заказов",
|
||||||
"shipping_method": "Способ доставки",
|
"shipping_method": "Способ доставки",
|
||||||
"product_description_title": "Описание к товару",
|
"product_description_title": "Описание к товару",
|
||||||
"recommended": "Рекомендуем также",
|
"recommended": "Рекомендуем также",
|
||||||
"address_search": "Поиск адреса",
|
"address_search": "Поиск адреса",
|
||||||
@@ -147,12 +147,21 @@
|
|||||||
"sending": "Отправка...",
|
"sending": "Отправка...",
|
||||||
"verifying": "Проверка...",
|
"verifying": "Проверка...",
|
||||||
"verify": "Подтвердить",
|
"verify": "Подтвердить",
|
||||||
"only_left": "Осталось {count} шт.",
|
"only_left": "Осталось {count} шт.",
|
||||||
"stock_limit_title": "Недостаточно на складе",
|
"stock_limit_title": "Недостаточно на складе",
|
||||||
"stock_limit_message": "{product} закончился. Можно купить только {stock} шт.",
|
"stock_limit_message": "{product} закончился. Можно купить только {stock} шт.",
|
||||||
"understood": "Понятно",
|
"understood": "Понятно",
|
||||||
"loading": "Загрузка...",
|
"loading": "Загрузка...",
|
||||||
"customer_information": "Информация о клиенте",
|
"customer_information": "Информация о клиенте",
|
||||||
"name": "Имя"
|
"name": "Имя",
|
||||||
|
"edit_your_information": "Изменить информацию",
|
||||||
}
|
"view_your_information": "Просмотр информации",
|
||||||
|
"edit": "Изменить",
|
||||||
|
"enter_first_name": "Введите имя",
|
||||||
|
"enter_last_name": "Введите фамилию",
|
||||||
|
"enter_phone_number": "Введите номер телефона",
|
||||||
|
"enter_address": "Введите адрес",
|
||||||
|
"save_changes": "Сохранить изменения",
|
||||||
|
"saving": "Сохранение...",
|
||||||
|
"cancel": "Отменить"
|
||||||
|
}
|
||||||
|
|||||||
@@ -147,15 +147,22 @@
|
|||||||
"sending": "Iberilýär...",
|
"sending": "Iberilýär...",
|
||||||
"verifying": "Barlanýar...",
|
"verifying": "Barlanýar...",
|
||||||
"verify": "Tassyklamak",
|
"verify": "Tassyklamak",
|
||||||
"only_left": "Diňe {count} sany galdy",
|
"only_left": "Diňe {count} sany galdy",
|
||||||
"stock_limit_title": "Çäkli sanda",
|
"stock_limit_title": "Çäkli sanda",
|
||||||
"stock_limit_message": "{product} harytdan diňe {stock} sany bar. Mundan köp sebediňize goşup bilmersiňiz.",
|
"stock_limit_message": "{product} harytdan diňe {stock} sany bar. Mundan köp sebediňize goşup bilmersiňiz.",
|
||||||
"understood": "Düşündim",
|
"understood": "Düşündim",
|
||||||
"loading": "Ýüklenýär...",
|
"loading": "Ýüklenýär...",
|
||||||
"customer_information": "Müşteri maglumatlary",
|
"customer_information": "Müşteri maglumatlary",
|
||||||
"name": "Ady"
|
"name": "Ady",
|
||||||
|
"edit_your_information": "Maglumatlaryňyzy üýtgediň",
|
||||||
|
"view_your_information": "Maglumatlaryňyzy görüň",
|
||||||
|
"edit": "Üýtgetmek",
|
||||||
|
"enter_first_name": "Adyňyzy ýazyň",
|
||||||
|
"enter_last_name": "Familiýaňyzy ýazyň",
|
||||||
|
"enter_phone_number": "Telefon belgisini giriziň",
|
||||||
|
"enter_address": "Adres giriziň",
|
||||||
|
"save_changes": "Ýatda sakla",
|
||||||
|
"saving": "Ýatda saklýar...",
|
||||||
|
"cancel": "Goýbolsun"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -97,10 +97,11 @@ export interface Category {
|
|||||||
export interface Collection {
|
export interface Collection {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
slug?: string;
|
slug: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
image?: string;
|
image?: string;
|
||||||
created_at?: string;
|
created_at?: string;
|
||||||
|
media?: ProductMedia[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cart Types
|
// Cart Types
|
||||||
@@ -495,7 +496,7 @@ export interface FiltersResponse {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Existing types'a ekleme
|
|
||||||
export interface ProductFilters {
|
export interface ProductFilters {
|
||||||
brands?: number[];
|
brands?: number[];
|
||||||
categories?: number[];
|
categories?: number[];
|
||||||
@@ -503,4 +504,5 @@ export interface ProductFilters {
|
|||||||
max_price?: number;
|
max_price?: number;
|
||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}
|
collection_id?: number;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user