diff --git a/app/[locale]/cart/page.tsx b/app/[locale]/cart/page.tsx index 759ada1..103cf34 100644 --- a/app/[locale]/cart/page.tsx +++ b/app/[locale]/cart/page.tsx @@ -160,7 +160,7 @@ export default function CartPage() { } return ( -
+

{t("cart")}

diff --git a/features/products/components/ProductInfoCard.tsx b/features/products/components/ProductInfoCard.tsx index 8b4421f..deae423 100644 --- a/features/products/components/ProductInfoCard.tsx +++ b/features/products/components/ProductInfoCard.tsx @@ -8,6 +8,7 @@ interface ProductProperty { } interface ProductInfoCardProps { + name: string; brandName?: string; stock?: number; barcode?: string; @@ -20,6 +21,7 @@ interface ProductInfoCardProps { } export function ProductInfoCard({ + name, brandName, stock, barcode, @@ -30,12 +32,10 @@ export function ProductInfoCard({ reviewsCount, t, }: ProductInfoCardProps) { - - return (
-

{t("about_product")}

+

{name}

{brandName && ( <> @@ -123,4 +123,4 @@ export function ProductInfoCard({ )}
); -} \ No newline at end of file +} diff --git a/features/products/components/ProductPageContent.tsx b/features/products/components/ProductPageContent.tsx index a91c23f..4b6f9b5 100644 --- a/features/products/components/ProductPageContent.tsx +++ b/features/products/components/ProductPageContent.tsx @@ -23,7 +23,10 @@ import { ProductReviewsSection } from "./ProductReviewsSection"; import { RelatedProductsSection } from "./RelatedProductsSection"; import { ReviewModal } from "./ReviewModal"; import { StockLimitModal } from "./StockLimitModal"; - +import { + useIsFavorite, + useToggleFavorite, +} from "@/features/favorites/hooks/useFavorites"; interface ProductDetailProps { slug: string; } @@ -43,7 +46,7 @@ interface PendingUpdate { export default function ProductPageContent({ slug }: ProductDetailProps) { const [localQuantity, setLocalQuantity] = useState(1); - const [isFavorite, setIsFavorite] = useState(false); + const [isSyncing, setIsSyncing] = useState(false); const [syncError, setSyncError] = useState(false); const [showStockModal, setShowStockModal] = useState(false); @@ -68,7 +71,9 @@ export default function ProductPageContent({ slug }: ProductDetailProps) { error, refetch: refetchProduct, } = useProductsBySlug(slug); - + const { isFavorite, isLoading: isFavLoading } = useIsFavorite( + product?.id || 0 + ); const cartOptions = useMemo( () => ({ refetchOnMount: true, @@ -77,7 +82,7 @@ export default function ProductPageContent({ slug }: ProductDetailProps) { }), [] ); - + const { mutate: toggleFavoriteMutation } = useToggleFavorite(); const { data: cartData, refetch: refetchCart, @@ -374,9 +379,41 @@ export default function ProductPageContent({ slug }: ProductDetailProps) { }); }, [localQuantity]); - const handleToggleFavorite = useCallback(() => { - setIsFavorite(!isFavorite); - }, [isFavorite]); + const handleToggleFavorite = useCallback( + (e?: React.MouseEvent) => { + e?.preventDefault(); + e?.stopPropagation(); + + if (!product?.id) { + toast.error(t("error"), { + description: "Product ID not found", + }); + return; + } + + toggleFavoriteMutation( + { + productId: product.id, + isFavorite, + }, + { + onSuccess: (data) => { + toast.success( + data?.wasAdded + ? t("added_to_favorites") + : t("removed_from_favorites") + ); + }, + onError: () => { + toast.error(t("error"), { + description: "Try again later", + }); + }, + } + ); + }, + [product?.id, isFavorite, toggleFavoriteMutation, t] + ); const handleSubmitReview = useCallback( async (rating: number, text: string) => { @@ -456,6 +493,7 @@ export default function ProductPageContent({ slug }: ProductDetailProps) { />