import { MetaFunction } from "@remix-run/node"; import { Link } from "@remix-run/react"; import { Layers, Trash2, Loader2, ChevronLeft, ShoppingBag } from "lucide-react"; import { useState } from "react"; import { Button } from "~/components/ui/button"; import { Skeleton } from "~/components/ui/skeleton"; import { Dialog, DialogContent, DialogOverlay } from "~/components/ui/dialog"; import { useUserCollections, useDeleteCollection, } from "../requestHandler/use-user-collection-hooks"; import { UserCollection, ProductDetail } from "../../src/api/types"; import ProfilePagesHeader from "~/components/ProfilePagesHeader"; import { useQuery } from "@tanstack/react-query"; export default function ProfileSets() { const { data: collections, isLoading, refetch } = useUserCollections(); const [deleteModalOpen, setDeleteModalOpen] = useState(false); const [selectedCollection, setSelectedCollection] = useState(null); const handleDeleteClick = ( e: React.MouseEvent, collection: UserCollection ) => { e.preventDefault(); e.stopPropagation(); setSelectedCollection(collection); setDeleteModalOpen(true); }; return (
{/* Header */}

ست‌های من

{/* Content */}
{isLoading ? (
{[1, 2, 3].map((i) => ( ))}
) : collections && collections.length > 0 ? (
{collections.map((collection) => ( handleDeleteClick(e, collection)} /> ))}
) : (

هنوز ستی ندارید

با رفتن به صفحه محصولات و زدن دکمه افزودن به ست، اولین ست خود را بسازید

)}
{/* Delete confirmation modal */} { refetch(); setDeleteModalOpen(false); setSelectedCollection(null); }} />
); } // Set Card Component const SetCard = ({ collection, onDelete, }: { collection: UserCollection; onDelete: (e: React.MouseEvent) => void; }) => { const productIds = collection.products?.slice(0, 4) || []; return ( {/* Product Images Row */}
{productIds.length > 0 ? ( <> {productIds.slice(0, 4).map((productId, index) => ( 4} extraCount={(collection.products?.length || 0) - 4} /> ))} {/* Fill empty slots if less than 4 products */} {productIds.length < 4 && Array.from({ length: 4 - productIds.length }).map((_, i) => (
))} ) : (
)}
{/* Info Section */}

{collection.title}

{collection.products?.length || 0} محصول

); }; // Product Image Cell for the grid const ProductImageCell = ({ productId, isLast, extraCount, }: { productId: string; isLast: boolean; extraCount: number; }) => { const { data: product, isLoading } = useQuery({ queryKey: ["product-thumb-cell", productId], queryFn: async (): Promise => { const response = await fetch( `${ typeof window !== "undefined" ? import.meta.env.VITE_API_BASE_URL || "https://api.prod.vitrown.com" : process.env.VITE_API_BASE_URL || "https://api.prod.vitrown.com" }/api/product/v1/products/${productId}/` ); if (!response.ok) throw new Error("Failed to fetch product"); return response.json(); }, enabled: !!productId, staleTime: 10 * 60 * 1000, }); if (isLoading) { return (
); } return (
{product?.imageUrls?.[0] ? ( ) : (
)} {isLast && extraCount > 0 && (
+{extraCount}
)}
); }; const DeleteSetModal = ({ open, onOpenChange, collection, onSuccess, }: { open: boolean; onOpenChange: (open: boolean) => void; collection: UserCollection | null; onSuccess: () => void; }) => { const { mutate: deleteCollection, isPending } = useDeleteCollection(); const handleDelete = () => { if (!collection?.id) return; deleteCollection(collection.id, { onSuccess: () => { onSuccess(); }, }); }; return (

حذف ست

آیا از حذف ست "{collection?.title}" مطمئن هستید؟

); }; export const meta: MetaFunction = () => { return [ { title: "ست‌های من | ویترون" }, { name: "description", content: "مدیریت ست‌های محصولات شما" }, { name: "robots", content: "noindex, follow" }, ]; };